Commit 596d1245 authored by Your Name's avatar Your Name

Add diffusers fallback when GGUF image model fails to load

If llama.cpp fails to load a GGUF image model (e.g., unsupported architecture like lumina2), try loading via diffusers instead.
parent fe8268fd
......@@ -4594,7 +4594,40 @@ def main():
print(f"GGUF image model loaded successfully: {original_model_name}")
except Exception as llama_error:
print(f"llama.cpp load error: {llama_error}")
print(f"Will try loading image model on first request instead")
print(f"GGUF loading failed, trying diffusers fallback...")
try:
import torch
from diffusers import StableDiffusionXLPipeline, DiffusionPipeline
print(f"Loading diffusers pipeline: {model_name}")
try:
pipeline = StableDiffusionXLPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
use_safetensors=True,
)
except Exception as e:
print(f"SDXL failed, trying generic pipeline: {e}")
pipeline = DiffusionPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
use_safetensors=True,
)
if torch.cuda.is_available():
pipeline = pipeline.to("cuda")
pipeline.enable_attention_slicing()
else:
pipeline = pipeline.to("cpu")
multi_model_manager.add_model(model_key, pipeline)
print(f"Image model loaded successfully via diffusers: {model_name}")
except ImportError as diffusers_err:
print(f"Warning: diffusers not installed: {diffusers_err}")
print(f"Image model will load on first request")
except Exception as diffusers_err:
print(f"Warning: diffusers fallback also failed: {diffusers_err}")
print(f"Image model will load on first request")
else:
print(f"Could not load GGUF image model: no valid model path")
......@@ -4992,7 +5025,40 @@ def main():
print(f"GGUF image model loaded successfully: {original_model_name}")
except Exception as llama_error:
print(f"llama.cpp load error: {llama_error}")
print(f"Will try loading image model on first request instead")
print(f"GGUF loading failed, trying diffusers fallback...")
try:
import torch
from diffusers import StableDiffusionXLPipeline, DiffusionPipeline
print(f"Loading diffusers pipeline: {model_name}")
try:
pipeline = StableDiffusionXLPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
use_safetensors=True,
)
except Exception as e:
print(f"SDXL failed, trying generic pipeline: {e}")
pipeline = DiffusionPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
use_safetensors=True,
)
if torch.cuda.is_available():
pipeline = pipeline.to("cuda")
pipeline.enable_attention_slicing()
else:
pipeline = pipeline.to("cpu")
multi_model_manager.add_model(model_key, pipeline)
print(f"Image model loaded successfully via diffusers: {model_name}")
except ImportError as diffusers_err:
print(f"Warning: diffusers not installed: {diffusers_err}")
print(f"Image model will load on first request")
except Exception as diffusers_err:
print(f"Warning: diffusers fallback also failed: {diffusers_err}")
print(f"Image model will load on first request")
else:
print(f"Could not load GGUF image model: no valid model path")
......
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