krisha06 commited on
Commit
ca66e20
·
verified ·
1 Parent(s): 5d1b435

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -10,11 +10,17 @@ tokenizer = AutoTokenizer.from_pretrained(base_model)
10
  # Load base model in CPU-only mode
11
  model = AutoModelForCausalLM.from_pretrained(
12
  base_model,
13
- device_map="cpu"
 
 
14
  )
15
 
16
- # Load the LoRA adapter
17
- model = PeftModel.from_pretrained(model, "lora_adapter")
 
 
 
 
18
  model.eval()
19
 
20
  def format_prompt(instruction):
 
10
  # Load base model in CPU-only mode
11
  model = AutoModelForCausalLM.from_pretrained(
12
  base_model,
13
+ device_map="auto", # Use 'auto' or manually move later
14
+ torch_dtype=torch.float32,
15
+ low_cpu_mem_usage=True # Ensures meta device usage
16
  )
17
 
18
+ # Move the model to CPU safely
19
+ model = model.to_empty(device=torch.device("cpu"))
20
+
21
+ # Now load the LoRA adapter
22
+ from peft import PeftModel
23
+ model = PeftModel.from_pretrained(model, "lora_adapter", device_map="cpu")
24
  model.eval()
25
 
26
  def format_prompt(instruction):