From fd707a2a056799431fdb845273e42cac1f3fd655 Mon Sep 17 00:00:00 2001 From: sophosympatheia Date: Mon, 3 Aug 2026 21:15:08 -0700 Subject: [PATCH 1/2] Fix local model discovery to recurse into subfolders get_local_models() used a non-recursive glob.glob(models_dir/*.gguf), so .gguf files placed in subfolders of a configured models directory (e.g. ~/models/Gemma-4-31B-it/gemma-4-31B-it-qat-UD-Q4_K_XL.gguf) were never listed as available models. Walk the directory tree with os.walk instead and return each match as a path relative to its models_dir. This matches the relative-path convention ComfyUI's own folder_paths.recursive_search uses, so is_model_local() and get_model_path() (which already join models_dir with the returned name) work unchanged for subfolder entries. --- py/model_manager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/py/model_manager.py b/py/model_manager.py index e9733ce..8aacf6f 100644 --- a/py/model_manager.py +++ b/py/model_manager.py @@ -2,7 +2,6 @@ Utility functions for managing llama.cpp models """ import os -import glob import re import folder_paths import server @@ -131,12 +130,13 @@ def get_local_models(): all_models = set() # Use set to avoid duplicates for models_dir in all_dirs: if os.path.exists(models_dir): - gguf_files = glob.glob(os.path.join(models_dir, "*.gguf")) - for f in gguf_files: - basename = os.path.basename(f) - # Filter out mmproj files - if 'mmproj' not in basename.lower(): - all_models.add(basename) + for dirpath, _subdirs, filenames in os.walk(models_dir, followlinks=True): + for filename in filenames: + if not filename.lower().endswith(".gguf") or 'mmproj' in filename.lower(): + continue + full_path = os.path.join(dirpath, filename) + rel_path = os.path.relpath(full_path, models_dir) + all_models.add(rel_path) # Return sorted list of unique filenames return sorted(list(all_models)) From 4459c270c2c08249a90d645c089cc002f30ad1e8 Mon Sep 17 00:00:00 2001 From: sophosympatheia Date: Mon, 3 Aug 2026 21:21:43 -0700 Subject: [PATCH 2/2] Fix mmproj discovery to recurse into subfolders and match same-folder files get_mmproj_path()'s heuristic search used os.listdir(models_dir), so mmproj files placed in a model's own subfolder were never found. It also required >= 4 shared non-quant keywords between model and mmproj filenames, which fails for generically-named files like 'mmproj-BF16.gguf' that carry no identifying keywords at all. Add a same-folder fallback: if the model's directory contains exactly one mmproj file, use it without requiring any naming convention. Keep the keyword heuristic as a fallback for mmproj files that live elsewhere, and make that search recurse into subfolders too. --- py/model_manager.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/py/model_manager.py b/py/model_manager.py index 8aacf6f..c65a5ec 100644 --- a/py/model_manager.py +++ b/py/model_manager.py @@ -238,7 +238,8 @@ def get_mmproj_path(model_name): """Get the path to the mmproj file for a model, if it exists. 1. Check the explicit QWEN_MODELS mapping first. - 2. Fall back to heuristic matching by model identity (strips quant parts). + 2. If the model's own folder contains exactly one mmproj file, use it. + 3. Fall back to heuristic matching by model identity (strips quant parts). """ # --- 1. Explicit mapping --- mmproj_name = get_mmproj_for_model(model_name) @@ -251,7 +252,19 @@ def get_mmproj_path(model_name): # Mapped but file not found on disk return None - # --- 2. Heuristic: keyword-based matching --- + # --- 2. Same-folder single-candidate fallback --- + # If the model lives in its own subfolder alongside exactly one mmproj + # file, assume that's the one to use — no naming convention required. + model_dir = os.path.dirname(get_model_path(model_name)) + if os.path.isdir(model_dir): + sibling_mmprojs = [ + f for f in os.listdir(model_dir) + if f.lower().endswith('.gguf') and 'mmproj' in f.lower() + ] + if len(sibling_mmprojs) == 1: + return os.path.join(model_dir, sibling_mmprojs[0]) + + # --- 3. Heuristic: keyword-based matching --- # Split the model name into normalised keywords (no quant tags, no 'mmproj') # and find the mmproj file that shares the most keywords (minimum 4). model_keywords = _get_model_keywords(model_name) @@ -266,14 +279,15 @@ def get_mmproj_path(model_name): for models_dir in all_dirs: if not os.path.exists(models_dir): continue - for f in os.listdir(models_dir): - if 'mmproj' not in f.lower() or not f.endswith('.gguf'): - continue - mmproj_keywords = _get_model_keywords(f) - common = model_keywords & mmproj_keywords - if len(common) >= MIN_KEYWORD_MATCH and len(common) > best_match_count: - best_match = os.path.join(models_dir, f) - best_match_count = len(common) + for dirpath, _subdirs, filenames in os.walk(models_dir, followlinks=True): + for f in filenames: + if 'mmproj' not in f.lower() or not f.lower().endswith('.gguf'): + continue + mmproj_keywords = _get_model_keywords(f) + common = model_keywords & mmproj_keywords + if len(common) >= MIN_KEYWORD_MATCH and len(common) > best_match_count: + best_match = os.path.join(dirpath, f) + best_match_count = len(common) return best_match