Spaces:
Paused
Paused
Update app/main.py
Browse files27 unmodified lines2829303132333414 unmodified lines495051525354555657585960616227 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"generator = Nonecurrent_model = None14 unmodified linestop_p: float = 0.9# ---------------------------# Model loader with HF token support# ---------------------------def load_model(model_key: str):global generator, current_modelmodel_name = SUPPORTED_MODELS.get(model_key, SUPPORTED_MODELS[DEFAULT_MODEL_KEY])if current_model == model_name and generator is not None:returndevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")torch_dtype = torch.float16 if device.type == "cuda" else torch.float3227 unmodified lines2829303132333414 unmodified lines4950515253545556575859606162636465666768697071727327 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 = "llama2-7b-chat"generator = Nonecurrent_model = None14 unmodified linestop_p: float = 0.9# ---------------------------# Model loader/unloader with HF token support# ---------------------------def unload_model():global generator, current_modelif generator is not None:# Delete pipeline and force garbage collectiondel generatortorch.cuda.empty_cache()current_model = Nonedef load_model(model_key: str):global generator, current_modelmodel_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 modelsunload_model()device = torch.device("cuda" if torch.cuda.is_available() else "cpu")torch_dtype = torch.float16 if device.type == "cuda" else torch.float32
app/main.py+13-2