Jayveersinh-Raj commited on
Commit
f351391
1 Parent(s): 69ffa00

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -1
README.md CHANGED
@@ -3,4 +3,31 @@ library_name: peft
3
  base_model: bigscience/bloom-3b
4
  ---
5
 
6
- Low Rank Adapter for Bloom decoder for question answering
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  base_model: bigscience/bloom-3b
4
  ---
5
 
6
+ Low Rank Adapter for Bloom decoder for question answering
7
+
8
+ # Example usage:
9
+ import torch
10
+ from peft import PeftModel, PeftConfig
11
+ from transformers import AutoModelForCausalLM, AutoTokenizer
12
+ from IPython.display import display, Markdown
13
+
14
+ peft_model_id = "Jayveersinh-Raj/bloom-que-ans"
15
+ config = PeftConfig.from_pretrained(peft_model_id)
16
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False, device_map='auto')
17
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
18
+
19
+ # Load the Lora model
20
+ qa_model = PeftModel.from_pretrained(model, peft_model_id)
21
+
22
+ def make_inference(context, question):
23
+ batch = tokenizer(f"### CONTEXT\n{context}\n\n### QUESTION\n{question}\n\n### ANSWER\n", return_tensors='pt').to("cuda")
24
+
25
+ with torch.cuda.amp.autocast():
26
+ output_tokens = qa_model.generate(**batch, max_new_tokens=200)
27
+
28
+ display(Markdown((tokenizer.decode(output_tokens[0], skip_special_tokens=True))))
29
+
30
+ context = ""
31
+ question = "What is the best food?"
32
+
33
+ make_inference(context, question)