Commit ce75ec47 authored by Your Name's avatar Your Name

Fix: Improve HuggingFace model ID resolution for sd.cpp

- Enhanced the HF model resolution logic in images.py sd.cpp fallback path
- Now checks for ANY cached file from the repo first (not just GGUF files)
- Falls back to checking for cached GGUF files specifically
- Last resort: downloads the first file in the repo as fallback
- Better error handling and logging throughout the resolution process
- This should resolve models that are already cached even if the exact GGUF filename isn't known
parent 7bb4eec1
......@@ -676,9 +676,25 @@ async def create_image_generation(request: ImageGenerationRequest, http_request:
if len(parts) >= 2:
repo_id = f"{parts[0]}/{parts[1]}"
# First check if there's a cached GGUF file for this model
# Try common GGUF file patterns
# First check if there's ANY cached file for this model (more flexible)
try:
files = list_repo_files(repo_id)
# Check for any cached file from this repo
for file in files:
# Construct potential URL and check cache
potential_url = f"https://huggingface.co/{repo_id}/resolve/main/{file}"
cached = multi_model_manager.get_cached_model_path(potential_url)
if cached:
model_path = cached
print(f"Using cached model from HF repo: {model_path}")
break
except Exception as list_error:
print(f"Could not list repo files: {list_error}")
files = []
# If no cached file found, try to find a cached GGUF file specifically
if not model_path:
# Try common GGUF file patterns
gguf_files = [f for f in files if f.endswith('.gguf')]
if gguf_files:
......@@ -697,6 +713,12 @@ async def create_image_generation(request: ImageGenerationRequest, http_request:
print(f"Downloading GGUF model from HF: {gguf_files[0]}")
model_path = hf_hub_download(repo_id=repo_id, filename=gguf_files[0])
print(f"Downloaded to: {model_path}")
else:
# No GGUF files found, try to download the first file as fallback
if files:
print(f"No GGUF files found, trying to download first file: {files[0]}")
model_path = hf_hub_download(repo_id=repo_id, filename=files[0])
print(f"Downloaded to: {model_path}")
except Exception as e:
print(f"Could not resolve as HuggingFace model: {e}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment