Eterna2 commited on
Commit
da1b4b3
1 Parent(s): c557140

Initial run with default params

Browse files
Files changed (3) hide show
  1. README.md +80 -0
  2. adapter_config.json +18 -0
  3. adapter_model.bin +3 -0
README.md CHANGED
@@ -1,3 +1,83 @@
1
  ---
 
 
 
 
 
 
 
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ library_name: peft
5
+ tags:
6
+ - llama
7
+ - lora
8
+ - peft
9
  license: apache-2.0
10
  ---
11
+
12
+ [Low-Rank-Adaption (LoRA)](https://paperswithcode.com/paper/lora-low-rank-adaptation-of-large-language) of [LLAMA 6B model](https://paperswithcode.com/paper/llama-open-and-efficient-foundation-language-1) that is fine-tuned with [Stanford Alpaca instruction dataset](https://github.com/tatsu-lab/stanford_alpaca) using [PEFT](https://github.com/huggingface/peft).
13
+
14
+ This model is trained based on the script provided in https://github.com/tloen/alpaca-lora.
15
+
16
+ > You might need to install the latest transformers from github for Llama support.
17
+
18
+ ```python
19
+ from peft import PeftModel
20
+ from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
21
+
22
+ tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
23
+
24
+ model = LlamaForCausalLM.from_pretrained(
25
+ "decapoda-research/llama-7b-hf",
26
+ load_in_8bit=True,
27
+ torch_dtype=torch.float16,
28
+ device_map="auto",
29
+ )
30
+ model = PeftModel.from_pretrained(
31
+ model, "tloen/alpaca-lora-7b",
32
+ torch_dtype=torch.float16
33
+ )
34
+
35
+ def generate_prompt(instruction, input=None):
36
+ if input:
37
+ 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.
38
+ ### Instruction:
39
+ {instruction}
40
+ ### Input:
41
+ {input}
42
+ ### Response:"""
43
+ else:
44
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
45
+ ### Instruction:
46
+ {instruction}
47
+ ### Response:"""
48
+
49
+
50
+ model.eval()
51
+
52
+
53
+ def evaluate(
54
+ instruction,
55
+ input=None,
56
+ temperature=0.1,
57
+ top_p=0.75,
58
+ top_k=40,
59
+ num_beams=4,
60
+ **kwargs,
61
+ ):
62
+ prompt = generate_prompt(instruction, input)
63
+ inputs = tokenizer(prompt, return_tensors="pt")
64
+ input_ids = inputs["input_ids"].to(device)
65
+ generation_config = GenerationConfig(
66
+ temperature=temperature,
67
+ top_p=top_p,
68
+ top_k=top_k,
69
+ num_beams=num_beams,
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=2048,
79
+ )
80
+ s = generation_output.sequences[0]
81
+ output = tokenizer.decode(s)
82
+ return output.split("### Response:")[1].strip()
83
+ ```
adapter_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "base_model_name_or_path": "decapoda-research/llama-7b-hf",
3
+ "bias": "none",
4
+ "enable_lora": null,
5
+ "fan_in_fan_out": false,
6
+ "inference_mode": true,
7
+ "lora_alpha": 16,
8
+ "lora_dropout": 0.05,
9
+ "merge_weights": false,
10
+ "modules_to_save": null,
11
+ "peft_type": "LORA",
12
+ "r": 8,
13
+ "target_modules": [
14
+ "q_proj",
15
+ "v_proj"
16
+ ],
17
+ "task_type": "CAUSAL_LM"
18
+ }
adapter_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a734191cc72b69cced6f1a99a27954e90f384646d9dfc5844423d24518d1da98
3
+ size 16822989