lgfunderburk commited on
Commit
7b2117c
·
1 Parent(s): 9b882bb

share usage instructions

Browse files
Files changed (1) hide show
  1. README.md +64 -0
README.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Load adapters from the Hub
2
+ You can also directly load adapters from the Hub using the commands below:
3
+
4
+ ```
5
+ import torch
6
+ from peft import PeftModel, PeftConfig
7
+ from transformers import AutoModelForCausalLM, AutoTokenizer
8
+
9
+ peft_model_id = f"{HUGGING_FACE_USER_NAME}/{model_name}"
10
+ config = PeftConfig.from_pretrained(peft_model_id)
11
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False, device_map='auto')
12
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
13
+
14
+ # Load the Lora model
15
+ model = PeftModel.from_pretrained(model, peft_model_id)
16
+ ```
17
+
18
+ # Inference
19
+ You can then directly use the trained model or the model that you have loaded from the 🤗 Hub for inference as you would do it usually in transformers.
20
+
21
+ ```
22
+ from IPython.display import display, Markdown
23
+
24
+ def make_inference(product, description):
25
+ batch = tokenizer(f"### INSTRUCTION\nBelow is a product and description,\
26
+ please write a marketing email for this product.\
27
+ \n\n### Product:\n{product}\n### Description:\n{description}\n\n### Marketing Email:\n",
28
+ return_tensors='pt')
29
+
30
+ with torch.cuda.amp.autocast():
31
+ output_tokens = model.generate(**batch, max_new_tokens=200)
32
+
33
+ display(Markdown((tokenizer.decode(output_tokens[0], skip_special_tokens=True))))
34
+
35
+ # Example
36
+ your_product_name_here = "Campfortable chair"
37
+ your_product_description_here = "A lightweight camping chair known for its comfort"
38
+
39
+ make_inference(your_product_name_here, your_product_description_here)
40
+ ```
41
+
42
+ Executing the code above then yields the following
43
+
44
+ INSTRUCTION
45
+ Below is a product and description, please write a marketing email for this product.
46
+
47
+ Product:
48
+ Campfortable chair
49
+
50
+ Description:
51
+ A lightweight camping chair known for its comfort
52
+
53
+ Marketing Email:
54
+ Subject: 🏖️🌞 Get Relaxed incampfortable! ✨
55
+
56
+ Hey there, Thirsty Traveler! 😎
57
+
58
+ Imagine being able to lounge in your camping chair all day long, wave goodbye to friends, and return to camp with a refreshed, energy-filled mind and body? 🌴
59
+
60
+ That's what you’ll get with our revolutionary Campfortable Chair! 🚀
61
+
62
+ 🌱 Say Goodbye to Fears of Inflatable Chairs Our revolutionary design eliminates the worries of bulky, heavy chairs. With just a few simple touches, you’ll feel like you are cradling the world in your arms! 💫
63
+
64
+ 🌺 Flip through Days with Campfortable Chair When you bring Campfortable Chair with you, you’ll have the power to adjust its comfort level based on the demands of your day. Say goodbye to sore backs and headaches, and welcome to relaxed, full-body fun