philipp-zettl commited on
Commit
0c3a5b0
·
verified ·
1 Parent(s): ac2d242

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
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
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
- model = AutoModelForCausalLM.from_pretrained(
12
- MODEL_ID,
13
- torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
14
- device_map="auto",
15
- trust_remote_code=True
16
- )
17
- model.eval()
 
 
 
 
 
 
 
 
 
 
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