Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,15 @@ import os
|
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
from peft import PeftModel, PeftConfig
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# β
Ensure offload directory exists
|
10 |
os.makedirs("offload", exist_ok=True)
|
11 |
|
@@ -26,7 +35,8 @@ def load_model(model_path):
|
|
26 |
base_model_name,
|
27 |
torch_dtype=torch.float16, # Use FP16 to reduce memory usage
|
28 |
device_map="auto", # Automatically distribute across CPU/GPU
|
29 |
-
offload_folder="offload" # β
Prevents memory crashes
|
|
|
30 |
)
|
31 |
|
32 |
# β
Load LoRA adapter with `is_trainable=False`
|
|
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
from peft import PeftModel, PeftConfig
|
8 |
|
9 |
+
# β
Retrieve Hugging Face token from environment variable (Secret)
|
10 |
+
HF_TOKEN = os.getenv("HF_TOKEN") # β
Now using stored secret, not hardcoded!
|
11 |
+
|
12 |
+
if HF_TOKEN is None:
|
13 |
+
raise ValueError("β ERROR: Hugging Face token is missing! Please set HF_TOKEN in Hugging Face Secrets.")
|
14 |
+
|
15 |
+
# β
Authenticate with Hugging Face
|
16 |
+
login(token=HF_TOKEN)
|
17 |
+
|
18 |
# β
Ensure offload directory exists
|
19 |
os.makedirs("offload", exist_ok=True)
|
20 |
|
|
|
35 |
base_model_name,
|
36 |
torch_dtype=torch.float16, # Use FP16 to reduce memory usage
|
37 |
device_map="auto", # Automatically distribute across CPU/GPU
|
38 |
+
offload_folder="offload", # β
Prevents memory crashes
|
39 |
+
use_auth_token=HF_TOKEN # β
Authenticate model loading
|
40 |
)
|
41 |
|
42 |
# β
Load LoRA adapter with `is_trainable=False`
|