Spaces:
Paused
Paused
Update app/main.py
Browse files27 unmodified lines282930313132333414 unmodified lines495051525253545556575859606162636465666768697071727327 unmodified lines "llama2-7b-chat": "meta-llama/Llama-2-7b-chat-hf", # gated "llama2-7b-base": "meta-llama/Llama-2-7b-hf", # gated}DEFAULT_MODEL_KEY = "smollm3"DEFAULT_MODEL_KEY = "llama2-7b-chat"
generator = Nonecurrent_model = None14 unmodified lines top_p: float = 0.9
# ---------------------------# Model loader with HF token support# Model loader/unloader with HF token support# ---------------------------def unload_model(): global generator, current_model if generator is not None: # Delete pipeline and force garbage collection del generator torch.cuda.empty_cache() current_model = None
def load_model(model_key: str): global generator, current_model model_name = SUPPORTED_MODELS.get(model_key, SUPPORTED_MODELS[DEFAULT_MODEL_KEY])
if current_model == model_name and generator is not None: return # Free GPU memory if switching models unload_model()
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") torch_dtype = torch.float16 if device.type == "cuda" else torch.float32app/main.py+13-2