From 9424ba17c8e5b8dcd5d89b5cd1735e5d210bea4e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:56:42 -0700 Subject: [PATCH] UI: show only part 00001 of multipart GGUF models in the model menu --- modules/utils.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/modules/utils.py b/modules/utils.py index f6be7541..269561aa 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -76,44 +76,54 @@ def get_available_models(): # Get all GGUF files gguf_files = get_available_ggufs() + # Filter out non-first parts of multipart GGUF files + filtered_gguf_files = [] + for gguf_path in gguf_files: + filename = os.path.basename(gguf_path) + + match = re.search(r'-(\d+)-of-\d+\.gguf$', filename) + + if match: + part_number = match.group(1) + # Keep only if it's part 1 + if part_number.lstrip("0") == "1": + filtered_gguf_files.append(gguf_path) + else: + # Not a multi-part file + filtered_gguf_files.append(gguf_path) + model_dir = Path(shared.args.model_dir) # Find top-level directories containing GGUF files dirs_with_gguf = set() for gguf_path in gguf_files: path = Path(gguf_path) - if path.parts: # If in a subdirectory - dirs_with_gguf.add(path.parts[0]) # Add top-level directory + if path.parts: + dirs_with_gguf.add(path.parts[0]) - # Find directories with safetensors files directly under them + # Find directories with safetensors files dirs_with_safetensors = set() for item in os.listdir(model_dir): item_path = model_dir / item if item_path.is_dir(): - # Check if there are safetensors files directly under this directory if any(file.lower().endswith(('.safetensors', '.pt')) for file in os.listdir(item_path) if (item_path / file).is_file()): dirs_with_safetensors.add(item) # Find valid model directories model_dirs = [] - for item in os.listdir(model_dir): item_path = model_dir / item - - # Skip if not a directory if not item_path.is_dir(): continue - # Include directory if it either: - # 1. Doesn't contain GGUF files, OR - # 2. Contains both GGUF and safetensors files + # Include directory if it either doesn't contain GGUF files + # or contains both GGUF and safetensors files if item not in dirs_with_gguf or item in dirs_with_safetensors: model_dirs.append(item) model_dirs = sorted(model_dirs, key=natural_keys) - # Combine all models - return ['None'] + gguf_files + model_dirs + return ['None'] + filtered_gguf_files + model_dirs def get_available_ggufs():