Commit c535ca5f authored by Your Name's avatar Your Name

Fix image generation to properly handle diffusers vs GGUF models

- Added check in sd.cpp fallback to skip HF model IDs that are likely diffusers models
- Prevents sd.cpp from trying to download non-GGUF files like .gitattributes for diffusers models
- Tongyi-MAI/Z-Image-Turbo and similar diffusers models now handled correctly by diffusers library
- GGUF models still work with sd.cpp as before
parent 5e641ba2
...@@ -671,61 +671,71 @@ async def create_image_generation(request: ImageGenerationRequest, http_request: ...@@ -671,61 +671,71 @@ async def create_image_generation(request: ImageGenerationRequest, http_request:
elif os.path.isfile(model_to_use): elif os.path.isfile(model_to_use):
model_path = model_to_use model_path = model_to_use
else: else:
# Try to resolve as HuggingFace model ID # Check if this is a likely diffusers model (not GGUF)
print(f"Trying to resolve as HuggingFace model ID: {model_to_use}") # If it doesn't contain 'gguf' and we're in image generation context,
try: # it's probably a diffusers model that should be handled by the diffusers library
from huggingface_hub import hf_hub_download, list_repo_files is_likely_diffusers = ('gguf' not in model_to_use.lower() and
not model_to_use.endswith('.gguf'))
# Parse model name (format: "org/model" or "org/model/filename.gguf")
parts = model_to_use.split('/') if is_likely_diffusers:
if len(parts) >= 2: print(f"Model '{model_to_use}' appears to be a diffusers model (not GGUF), skipping sd.cpp resolution")
repo_id = f"{parts[0]}/{parts[1]}" print("This model should be handled by the diffusers library above")
model_path = None
# First check if there's ANY cached file for this model (more flexible) else:
try: # Try to resolve as HuggingFace GGUF model ID
files = list_repo_files(repo_id) print(f"Trying to resolve as HuggingFace GGUF model ID: {model_to_use}")
# Check for any cached file from this repo try:
for file in files: from huggingface_hub import hf_hub_download, list_repo_files
# Construct potential URL and check cache
potential_url = f"https://huggingface.co/{repo_id}/resolve/main/{file}" # Parse model name (format: "org/model" or "org/model/filename.gguf")
cached = get_cached_model_path(potential_url) parts = model_to_use.split('/')
if cached: if len(parts) >= 2:
model_path = cached repo_id = f"{parts[0]}/{parts[1]}"
print(f"Using cached model from HF repo: {model_path}")
break # First check if there's ANY cached file for this model (more flexible)
except Exception as list_error: try:
print(f"Could not list repo files: {list_error}") files = list_repo_files(repo_id)
files = [] # Check for any cached file from this repo
for file in 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:
# Try to find a cached version first
for gguf_file in gguf_files:
# Construct potential URL and check cache # Construct potential URL and check cache
potential_url = f"https://huggingface.co/{repo_id}/resolve/main/{gguf_file}" potential_url = f"https://huggingface.co/{repo_id}/resolve/main/{file}"
cached = get_cached_model_path(potential_url) cached = get_cached_model_path(potential_url)
if cached: if cached:
model_path = cached model_path = cached
print(f"Using cached GGUF model: {model_path}") print(f"Using cached model from HF repo: {model_path}")
break break
except Exception as list_error:
# If not cached, download the first GGUF file print(f"Could not list repo files: {list_error}")
if not model_path: files = []
print(f"Downloading GGUF model from HF: {gguf_files[0]}")
model_path = hf_hub_download(repo_id=repo_id, filename=gguf_files[0]) # If no cached file found, try to find a cached GGUF file specifically
print(f"Downloaded to: {model_path}") if not model_path:
else: # Try common GGUF file patterns
# No GGUF files found, try to download the first file as fallback gguf_files = [f for f in files if f.endswith('.gguf')]
if files:
print(f"No GGUF files found, trying to download first file: {files[0]}") if gguf_files:
model_path = hf_hub_download(repo_id=repo_id, filename=files[0]) # Try to find a cached version first
print(f"Downloaded to: {model_path}") for gguf_file in gguf_files:
except Exception as e: # Construct potential URL and check cache
print(f"Could not resolve as HuggingFace model: {e}") potential_url = f"https://huggingface.co/{repo_id}/resolve/main/{gguf_file}"
cached = get_cached_model_path(potential_url)
if cached:
model_path = cached
print(f"Using cached GGUF model: {model_path}")
break
# If not cached, download the first GGUF file
if not model_path:
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 - this is not a GGUF model
print(f"No GGUF files found in {repo_id} - this is not a GGUF model")
model_path = None
except Exception as e:
print(f"Could not resolve as HuggingFace GGUF model: {e}")
model_path = None
if model_path is None: if model_path is None:
print("Warning: Could not resolve sd.cpp model path via HuggingFace GGUF resolution") print("Warning: Could not resolve sd.cpp model path via HuggingFace GGUF resolution")
......
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