deepakdethliya commited on
Commit
938dd28
·
verified ·
1 Parent(s): 4fae600

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -12,18 +12,18 @@ ADAPTER_MODEL_ID = "vsple/LegalBuddy-Qwen-1.5B"
12
  # Load tokenizer
13
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID, trust_remote_code=True)
14
 
15
- # Load base model
16
- print("Loading base model...")
 
17
  base_model = AutoModelForCausalLM.from_pretrained(
18
  BASE_MODEL_ID,
19
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
20
- device_map="auto",
21
  trust_remote_code=True
22
  )
23
 
24
- # Load adapter
25
- print("Loading adapter...")
26
  model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL_ID)
 
27
  model = model.eval()
28
 
29
  def predict(message, history, system_prompt, max_tokens, temperature, top_p):
 
12
  # Load tokenizer
13
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID, trust_remote_code=True)
14
 
15
+ # Load model and adapter
16
+ print("Loading model and adapter...")
17
+ device = "cuda" if torch.cuda.is_available() else "cpu"
18
  base_model = AutoModelForCausalLM.from_pretrained(
19
  BASE_MODEL_ID,
20
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
21
+ low_cpu_mem_usage=True,
22
  trust_remote_code=True
23
  )
24
 
 
 
25
  model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL_ID)
26
+ model = model.to(device)
27
  model = model.eval()
28
 
29
  def predict(message, history, system_prompt, max_tokens, temperature, top_p):