Commit c517c947 authored by Your Name's avatar Your Name

Fix: Reload default text model when switching from image to text

- When 'default' model is requested but not loaded (was unloaded for image model),
  the code now tries to reload the default model
- Cleanup image models first to free VRAM, then reload the text model
parent c8f7c8d9
...@@ -2444,6 +2444,37 @@ class MultiModelManager: ...@@ -2444,6 +2444,37 @@ class MultiModelManager:
if self.default_model and self.default_model in self.models: if self.default_model and self.default_model in self.models:
self.current_model_key = self.default_model self.current_model_key = self.default_model
return self.models[self.default_model] return self.models[self.default_model]
# Model not loaded - check if it's in config (registered but unloaded)
if self.default_model and self.default_model in self.config:
# Need to reload the default model - cleanup image models first
for key in list(self.models.keys()):
if key.startswith("image:"):
model_to_cleanup = self.models.get(key)
if model_to_cleanup is not None:
print(f"Unloading image model '{key}' from VRAM to reload text model")
try:
if hasattr(model_to_cleanup, 'cleanup') and callable(getattr(model_to_cleanup, 'cleanup')):
model_to_cleanup.cleanup()
elif hasattr(model_to_cleanup, 'model') and model_to_cleanup.model is not None:
if hasattr(model_to_cleanup.model, 'cleanup'):
model_to_cleanup.model.cleanup()
except Exception as e:
print(f"Warning during cleanup of '{key}': {e}")
del self.models[key]
# Now try to reload the default model
try:
from llama_cpp import Llama
backend = self.config[self.default_model].get('backend_type', 'auto')
model_path = self.default_model
load_kwargs = self.config[self.default_model].copy()
load_kwargs.pop('backend_type', None)
print(f"Reloading default model: {model_path}")
llm = Llama(model_path=model_path, **load_kwargs)
self.models[self.default_model] = ModelManager(llm, backend=backend)
self.current_model_key = self.default_model
return self.models[self.default_model]
except Exception as e:
print(f"Error reloading default model: {e}")
return None return None
# Handle "audio" alias - use first/default audio model # Handle "audio" alias - use first/default audio model
......
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