Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,36 @@ import torch
|
|
7 |
# Load model and tokenizer
|
8 |
model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
model = AutoModelForCausalLM.from_pretrained(
|
11 |
model_id,
|
12 |
torch_dtype=torch.bfloat16,
|
|
|
7 |
# Load model and tokenizer
|
8 |
model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
10 |
+
|
11 |
+
# Add this workaround for the RoPE scaling issue
|
12 |
+
from transformers.utils import WEIGHTS_NAME, CONFIG_NAME
|
13 |
+
import os
|
14 |
+
import json
|
15 |
+
|
16 |
+
# Fix the rope_scaling configuration before loading the model
|
17 |
+
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.json")
|
18 |
+
if not os.path.exists(config_path):
|
19 |
+
# Download the config file if it doesn't exist
|
20 |
+
from huggingface_hub import hf_hub_download
|
21 |
+
config_path = hf_hub_download(repo_id=model_id, filename=CONFIG_NAME)
|
22 |
+
|
23 |
+
# Load and modify the config
|
24 |
+
with open(config_path, 'r') as f:
|
25 |
+
config = json.load(f)
|
26 |
+
|
27 |
+
# Fix the rope_scaling format
|
28 |
+
if 'rope_scaling' in config and not (isinstance(config['rope_scaling'], dict) and 'type' in config['rope_scaling'] and 'factor' in config['rope_scaling']):
|
29 |
+
# Convert to the expected format
|
30 |
+
old_scaling = config['rope_scaling']
|
31 |
+
config['rope_scaling'] = {
|
32 |
+
'type': 'dynamic',
|
33 |
+
'factor': old_scaling.get('factor', 8.0)
|
34 |
+
}
|
35 |
+
# Save the modified config
|
36 |
+
with open(config_path, 'w') as f:
|
37 |
+
json.dump(config, f)
|
38 |
+
|
39 |
+
# Now load the model with the fixed config
|
40 |
model = AutoModelForCausalLM.from_pretrained(
|
41 |
model_id,
|
42 |
torch_dtype=torch.bfloat16,
|