mmendoza commited on
Commit
f8a5bad
·
1 Parent(s): 640bc91

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -0
README.md CHANGED
@@ -19,6 +19,37 @@ Input: What are your thoughts on the proposed merger and its potential effects o
19
 
20
  Output: I'm sorry, but I don't have any thoughts on the proposed merger and its potential effects on our industry.
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ---
24
  library_name: peft
 
19
 
20
  Output: I'm sorry, but I don't have any thoughts on the proposed merger and its potential effects on our industry.
21
 
22
+ ## Quick tutorial
23
+
24
+ import torch
25
+ from peft import PeftModel, PeftConfig
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
+
28
+ peft_model_id = "mmendoza/gpt-j-6B-lora-polite-enh"
29
+ config = PeftConfig.from_pretrained(peft_model_id)
30
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
31
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
32
+
33
+ # Load the Lora model
34
+ model = PeftModel.from_pretrained(model, peft_model_id)
35
+
36
+ # Prompting
37
+ batch = tokenizer("You have an input text. Write a polite version of the text preserving the meaning of the input.
38
+ Input: No card counting allowed in blackjack at the casino. Output: ", return_tensors='pt')
39
+
40
+ with torch.cuda.amp.autocast():
41
+ output_tokens = model.generate(**batch, max_new_tokens=50, pad_token_id=tokenizer.eos_token_id)
42
+
43
+ line = tokenizer.decode(output_tokens[0], skip_special_tokens=True)
44
+
45
+ start = 'Output: '
46
+ end = '.'
47
+
48
+ line = line.replace("\n"," ")
49
+ line = (line.split(start))[1].split(end)[0]
50
+
51
+ "Please refrain from counting cards in blackjack at the casino."
52
+
53
 
54
  ---
55
  library_name: peft