Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,13 +16,26 @@ def load_model():
|
|
| 16 |
print("This may take several minutes on first load...")
|
| 17 |
|
| 18 |
# Load model with correct parameters based on official documentation
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Load processor (not tokenizer)
|
| 28 |
processor = AutoProcessor.from_pretrained(
|
|
|
|
| 16 |
print("This may take several minutes on first load...")
|
| 17 |
|
| 18 |
# Load model with correct parameters based on official documentation
|
| 19 |
+
# Try with flash attention first, fall back to standard attention
|
| 20 |
+
try:
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
+
model_name,
|
| 23 |
+
trust_remote_code=True,
|
| 24 |
+
device_map="auto",
|
| 25 |
+
torch_dtype=torch.bfloat16, # Changed from float16 to bfloat16
|
| 26 |
+
attn_implementation="flash_attention_2", # Added for better performance
|
| 27 |
+
)
|
| 28 |
+
print("Loaded with flash attention")
|
| 29 |
+
except Exception as flash_error:
|
| 30 |
+
print(f"Flash attention failed: {flash_error}")
|
| 31 |
+
print("Falling back to standard attention...")
|
| 32 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 33 |
+
model_name,
|
| 34 |
+
trust_remote_code=True,
|
| 35 |
+
device_map="auto",
|
| 36 |
+
torch_dtype=torch.bfloat16,
|
| 37 |
+
)
|
| 38 |
+
print("Loaded with standard attention")
|
| 39 |
|
| 40 |
# Load processor (not tokenizer)
|
| 41 |
processor = AutoProcessor.from_pretrained(
|