ritabratamaiti commited on
Commit
b4f00ea
·
1 Parent(s): c04d8ce

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +84 -0
README.md CHANGED
@@ -4,6 +4,90 @@ datasets:
4
  - Xilabs/instructmix
5
  pipeline_tag: text-generation
6
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  ## Training procedure
8
 
9
 
 
4
  - Xilabs/instructmix
5
  pipeline_tag: text-generation
6
  ---
7
+ ## Model Card for "InstructMix Llama 3B"
8
+
9
+ **Model Name:** InstructMix Llama 3B
10
+
11
+ **Description:**
12
+
13
+ InstructMix Llama 3B is a language model fine-tuned on the InstructMix dataset using parameter-efficient fine-tuning (PEFT), using the base model "openlm-research/open_llama_3b_v2," which can be found at [https://huggingface.co/openlm-research/open_llama_3b_v2](https://huggingface.co/openlm-research/open_llama_3b_v2).
14
+
15
+
16
+ **Usage:**
17
+ ```py
18
+ import torch
19
+ from transformers import LlamaForCausalLM, LlamaTokenizer
20
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
21
+ from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
22
+ from peft import PeftModel, PeftConfig
23
+
24
+ # Hugging Face model_path
25
+ model_path = 'openlm-research/open_llama_3b_v2'
26
+ peft_model_id = 'Xilabs/instructmix-llama-3b'
27
+ tokenizer = LlamaTokenizer.from_pretrained(model_path)
28
+ model = LlamaForCausalLM.from_pretrained(
29
+ model_path, device_map="auto"
30
+ )
31
+ model = PeftModel.from_pretrained(model, peft_model_id)
32
+ def generate_prompt(instruction, input=None):
33
+ if input:
34
+ return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
35
+
36
+ ### Instruction:
37
+ {instruction}
38
+
39
+ ### Input:
40
+ {input}
41
+
42
+ ### Response:"""
43
+ else:
44
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
45
+
46
+ ### Instruction:
47
+ {instruction}
48
+
49
+ ### Response:"""
50
+ def evaluate(
51
+ instruction,
52
+ input=None,
53
+ temperature=0.5,
54
+ top_p=0.75,
55
+ top_k=40,
56
+ num_beams=5,
57
+ max_new_tokens=128,
58
+ **kwargs,
59
+ ):
60
+ prompt = generate_prompt(instruction, input)
61
+ inputs = tokenizer(prompt, return_tensors="pt")
62
+ input_ids = inputs["input_ids"].to("cuda")
63
+ generation_config = GenerationConfig(
64
+ temperature=temperature,
65
+ top_p=top_p,
66
+ top_k=top_k,
67
+ num_beams=num_beams,
68
+ early_stopping=True,
69
+ repetition_penalty=1.1,
70
+ **kwargs,
71
+ )
72
+ with torch.no_grad():
73
+ generation_output = model.generate(
74
+ input_ids=input_ids,
75
+ generation_config=generation_config,
76
+ return_dict_in_generate=True,
77
+ output_scores=True,
78
+ max_new_tokens=max_new_tokens,
79
+ )
80
+ s = generation_output.sequences[0]
81
+ output = tokenizer.decode(s, skip_special_tokens = True)
82
+ #print(output)
83
+ return output.split("### Response:")[1]
84
+
85
+ # Sample Test Instruction Used by Youtuber Sam Witteveen https://www.youtube.com/@samwitteveenai
86
+ instruction = "What is the meaning of life?"
87
+ print(evaluate(instruction, num_beams=3, temperature=0.1, max_new_tokens=256))
88
+ ```
89
+
90
+
91
  ## Training procedure
92
 
93