Update app.py
Browse files
app.py
CHANGED
|
@@ -22,16 +22,18 @@ def load_llama_model(model_name):
|
|
| 22 |
print(f"🔄 Loading Model: {model_name}")
|
| 23 |
|
| 24 |
tokenizer = LlamaTokenizer.from_pretrained(model_name, token=HUGGINGFACE_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
model_url = f"https://huggingface.co/{model_name}/resolve/main/consolidated.00.pth"
|
| 28 |
-
state_dict = torch.hub.load_state_dict_from_url(model_url, map_location="cpu")
|
| 29 |
-
|
| 30 |
-
print("✅ Model state dictionary loaded successfully!")
|
| 31 |
-
|
| 32 |
-
# Initialize model and load state_dict
|
| 33 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, state_dict=state_dict)
|
| 34 |
-
|
| 35 |
return tokenizer, model
|
| 36 |
|
| 37 |
# Load the quantized Llama model
|
|
|
|
| 22 |
print(f"🔄 Loading Model: {model_name}")
|
| 23 |
|
| 24 |
tokenizer = LlamaTokenizer.from_pretrained(model_name, token=HUGGINGFACE_TOKEN)
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 28 |
+
model_name,
|
| 29 |
+
token=HUGGINGFACE_TOKEN,
|
| 30 |
+
trust_remote_code=True # Allows loading non-standard model formats
|
| 31 |
+
)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"❌ Error loading model: {e}")
|
| 34 |
+
raise ValueError(f"❌ Model {model_name} may not have valid weight files. Check the Hugging Face repository.")
|
| 35 |
|
| 36 |
+
print("✅ Model loaded successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return tokenizer, model
|
| 38 |
|
| 39 |
# Load the quantized Llama model
|