ZEECO1 commited on
Commit
33b9789
·
verified ·
1 Parent(s): bdc0f32

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -0
README.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
+
4
+ base_model_id = "mistralai/Mistral-7B-v0.1"
5
+ bnb_config = BitsAndBytesConfig(
6
+ load_in_4bit=True,
7
+ bnb_4bit_use_double_quant=True,
8
+ bnb_4bit_quant_type="nf4",
9
+ bnb_4bit_compute_dtype=torch.bfloat16
10
+ )
11
+
12
+ base_model = AutoModelForCausalLM.from_pretrained(
13
+ base_model_id, # Mistral, same as before
14
+ quantization_config=bnb_config, # Same quantization config as before
15
+ device_map="auto",
16
+ trust_remote_code=True,
17
+ )
18
+
19
+ eval_tokenizer = AutoTokenizer.from_pretrained(base_model_id, add_bos_token=True, trust_remote_code=True)
20
+
21
+ from peft import PeftModel
22
+
23
+ ft_model = PeftModel.from_pretrained(base_model, "ZEECO1/CancerLLM-Mistral7b/checkpoint-500")
24
+
25
+
26
+
27
+ eval_prompt = " what are the drugs against lung cancer: # "
28
+ model_input = eval_tokenizer(eval_prompt, return_tensors="pt").to("cuda")
29
+
30
+ ft_model.eval()
31
+ with torch.no_grad():
32
+ print(eval_tokenizer.decode(ft_model.generate(**model_input, max_new_tokens=100, repetition_penalty=1.15)[0], skip_special_tokens=True))