ashwinram472 commited on
Commit
56b9fcb
1 Parent(s): d9bb9c2

Adding model tags

Browse files
.ipynb_checkpoints/README-checkpoint.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ datasets:
6
+ - yahma/alpaca-cleaned
7
+ pipeline_tag: text2text-generation
8
+ tags:
9
+ - alpaca
10
+ - llama
11
+ - chat
12
+ - gpt4
13
+ - lora
14
+ ---
15
+ This repo contains a low-rank adapter for Llama-7b finetuned on the Cleaned Alpaca version of the Dataset.
16
+
17
+ This version was finetuned using:
18
+ ```shell
19
+ python finetune.py \
20
+ --base_model '../models/llama_7b_hf' \
21
+ --data_path 'yahma/alpaca-cleaned' \
22
+ --output_dir './lora-alpaca-cleaned' \
23
+ --batch_size 128 \
24
+ --micro_batch_size 4 \
25
+ --num_epochs 10 \
26
+ --learning_rate 1e-4 \
27
+ --cutoff_len 512 \
28
+ --val_set_size 2000 \
29
+ --lora_r 16 \
30
+ --lora_alpha 16 \
31
+ --lora_dropout 0.05 \
32
+ --lora_target_modules '[q_proj,k_proj,v_proj,o_proj]' \
33
+ --train_on_inputs \
34
+ --group_by_length \
35
+ --wandb_project 'alpaca-lora-cleaned'
36
+ --wandb_run_name 'alpaca-lora-10epoch'
37
+ ```
38
+
39
+ For Training logs visit W&B report: [here](https://wandb.ai/ashwinram472/alpaca-lora-cleaned?workspace=user-ashwinram472).
40
+
41
+
42
+ ```python
43
+ model = LlamaForCausalLM.from_pretrained(
44
+ '/llama_7b_hf',
45
+ load_in_8bit=True,
46
+ torch_dtype=torch.float16,
47
+ device_map='auto',
48
+ )
49
+
50
+ lora_weights = 'ashwinram472/alpaca-cleaned-lora-7b'
51
+
52
+ model = PeftModel.from_pretrained(
53
+ model,
54
+ lora_weights,
55
+ torch_dtype=torch.float16,
56
+ )
57
+
58
+ tokenizer = LlamaTokenizer.from_pretrained("../models/llama_7b_hf")
59
+
60
+ def generate_prompt(instruction: str, input_ctxt: str = None) -> str:
61
+ if input_ctxt:
62
+ 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.
63
+
64
+ ### Instruction:
65
+ {instruction}
66
+
67
+ ### Input:
68
+ {input_ctxt}
69
+
70
+ ### Response:"""
71
+ else:
72
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
73
+
74
+ ### Instruction:
75
+ {instruction}
76
+
77
+ ### Response:"""
78
+
79
+ generation_config = GenerationConfig(
80
+ temperature=0.1,
81
+ top_p=0.75,
82
+ top_k=40,
83
+ num_beams=4,
84
+ max_new_tokens=128,
85
+ )
86
+
87
+ model.eval()
88
+
89
+
90
+ instruction = "Count up from 1 to 500."
91
+
92
+ input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.
93
+
94
+ prompt = generate_prompt(instruction, input_ctxt)
95
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
96
+ input_ids = input_ids.to(model.device)
97
+
98
+ with torch.no_grad():
99
+ outputs = model.generate(
100
+ input_ids=input_ids,
101
+ generation_config=generation_config,
102
+ return_dict_in_generate=True,
103
+ output_scores=True,
104
+ )
105
+
106
+ response = tokenizer.decode(outputs.sequences[0], skip_special_tokens=True)
107
+
108
+ print(response.split("### Response:")[1].strip().split("### Instruction")[0])
109
+ ```
README.md CHANGED
@@ -6,11 +6,11 @@ datasets:
6
  - yahma/alpaca-cleaned
7
  pipeline_tag: text2text-generation
8
  tags:
9
- -alpaca
10
- -llama
11
- -chat
12
- -gpt4
13
- -lora
14
  ---
15
  This repo contains a low-rank adapter for Llama-7b finetuned on the Cleaned Alpaca version of the Dataset.
16
 
 
6
  - yahma/alpaca-cleaned
7
  pipeline_tag: text2text-generation
8
  tags:
9
+ - alpaca
10
+ - llama
11
+ - chat
12
+ - gpt4
13
+ - lora
14
  ---
15
  This repo contains a low-rank adapter for Llama-7b finetuned on the Cleaned Alpaca version of the Dataset.
16