Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,24 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStream
|
|
| 7 |
MODEL_ID = "HuggingFaceTB/nanowhale-100m"
|
| 8 |
|
| 9 |
print(f"Loading model {MODEL_ID} ...")
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
)
|
| 17 |
-
model.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
print("Model loaded.")
|
| 19 |
|
| 20 |
DEVICE = next(model.parameters()).device
|
|
|
|
| 7 |
MODEL_ID = "HuggingFaceTB/nanowhale-100m"
|
| 8 |
|
| 9 |
print(f"Loading model {MODEL_ID} ...")
|
| 10 |
+
import torch
|
| 11 |
+
from safetensors.torch import load_file
|
| 12 |
+
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
| 13 |
+
from huggingface_hub import hf_hub_download
|
| 14 |
+
|
| 15 |
+
# Load model (recommended: manual load for reliability)
|
| 16 |
+
config = AutoConfig.from_pretrained("HuggingFaceTB/nanowhale-100m", trust_remote_code=True)
|
| 17 |
+
model = AutoModelForCausalLM.from_config(config, trust_remote_code=True).float()
|
| 18 |
+
|
| 19 |
+
# Download and load weights
|
| 20 |
+
weights_path = hf_hub_download("HuggingFaceTB/nanowhale-100m", "model.safetensors")
|
| 21 |
+
state_dict = load_file(weights_path)
|
| 22 |
+
model.load_state_dict(state_dict, strict=True)
|
| 23 |
+
model = model.cuda().eval()
|
| 24 |
+
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/nanowhale-100m")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
print("Model loaded.")
|
| 29 |
|
| 30 |
DEVICE = next(model.parameters()).device
|