Tufan1 commited on
Commit
58a2772
·
verified ·
1 Parent(s): a5515f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -14,9 +14,32 @@ BASE_MODEL = "stanford-crfm/BioMedLM" # or the path you used originally
14
  ADAPTER_PATH = "Tufan1/BioMedLM-Cardio-Fold10-CPU"
15
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Force CPU-safe model loading
18
- base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype=torch.float32)
19
- model = PeftModel.from_pretrained(base_model, ADAPTER_PATH, device_map=None).to("cpu")
20
 
21
 
22
  # Dictionaries to decode user inputs
 
14
  ADAPTER_PATH = "Tufan1/BioMedLM-Cardio-Fold10-CPU"
15
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
16
 
17
+ # Load base model with safe settings
18
+ base_model = AutoModelForCausalLM.from_pretrained(
19
+ BASE_MODEL,
20
+ torch_dtype=torch.float32,
21
+ low_cpu_mem_usage=True, # Reduces memory spikes
22
+ device_map="cpu" # Force CPU loading
23
+ )
24
+
25
+ # Load PEFT adapter with proper weight mapping
26
+ model = PeftModel.from_pretrained(
27
+ base_model,
28
+ ADAPTER_PATH,
29
+ device_map="cpu",
30
+ is_trainable=False
31
+ )
32
+
33
+ # Explicitly load adapter weights to CPU
34
+ adapter_weights = torch.load(
35
+ f"{ADAPTER_PATH}/adapter_model.bin",
36
+ map_location=torch.device('cpu')
37
+ )
38
+ model.load_state_dict(adapter_weights, strict=False)
39
+
40
  # Force CPU-safe model loading
41
+ #base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype=torch.float32)
42
+ #model = PeftModel.from_pretrained(base_model, ADAPTER_PATH, device_map=None).to("cpu")
43
 
44
 
45
  # Dictionaries to decode user inputs