Brian Tang commited on
Commit
f65013c
1 Parent(s): 06b21c3

Adds axolotl config, lora usage notebook

Browse files
Files changed (2) hide show
  1. README.md +144 -191
  2. example_lora_usage.ipynb +285 -0
README.md CHANGED
@@ -1,202 +1,155 @@
1
  ---
2
  base_model: openlm-research/open_llama_3b_v2
3
  library_name: peft
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
 
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
-
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
200
  ### Framework versions
201
 
202
- - PEFT 0.11.1
 
 
 
 
 
1
  ---
2
  base_model: openlm-research/open_llama_3b_v2
3
  library_name: peft
4
+ license: apache-2.0
5
+ tags:
6
+ - generated_from_trainer
7
+ model-index:
8
+ - name: outputs/lora-out
9
+ results: []
10
  ---
11
 
12
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
13
+ should probably proofread and complete it, then remove this comment. -->
14
 
15
+ [<img src="https://raw.githubusercontent.com/axolotl-ai-cloud/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/axolotl-ai-cloud/axolotl)
16
+ <details><summary>See axolotl config</summary>
17
 
18
+ axolotl version: `0.4.1`
19
+ ```yaml
20
+ base_model: openlm-research/open_llama_3b_v2
21
+ model_type: LlamaForCausalLM
22
+ tokenizer_type: LlamaTokenizer
23
+ load_in_8bit: true
24
+ load_in_4bit: false
25
+ strict: false
26
+ push_dataset_to_hub:
27
+ datasets:
28
+ - path: teknium/GPT4-LLM-Cleaned
29
+ type: alpaca
30
+ dataset_prepared_path: ./last_run_prepared
31
+ val_set_size: 0.02
32
+ adapter: lora
33
+ lora_model_dir:
34
+ sequence_len: 1024
35
+ sample_packing: true
36
+ lora_r: 8
37
+ lora_alpha: 16
38
+ lora_dropout: 0.0
39
+ lora_target_modules:
40
+ - gate_proj
41
+ - down_proj
42
+ - up_proj
43
+ - q_proj
44
+ - v_proj
45
+ - k_proj
46
+ - o_proj
47
+ lora_fan_in_fan_out:
48
+ wandb_project: openllama-axolotl
49
+ wandb_entity: ashrielbrian
50
+ wandb_watch:
51
+ wandb_name:
52
+ wandb_log_model:
53
+ output_dir: ./outputs/lora-out
54
+ gradient_accumulation_steps: 1
55
+ micro_batch_size: 2
56
+ num_epochs: 4
57
+ optimizer: adamw_bnb_8bit
58
+ torchdistx_path:
59
+ lr_scheduler: cosine
60
+ learning_rate: 0.0002
61
+ train_on_inputs: false
62
+ group_by_length: false
63
+ bf16: false
64
+ fp16: true
65
+ tf32: false
66
+ gradient_checkpointing: true
67
+ early_stopping_patience:
68
+ resume_from_checkpoint: ./outputs/lora-out/checkpoint-10762
69
+ local_rank:
70
+ logging_steps: 1
71
+ xformers_attention:
72
+ flash_attention: true
73
+ gptq_groupsize:
74
+ s2_attention:
75
+ gptq_model_v1:
76
+ warmup_steps: 20
77
+ evals_per_epoch: 4
78
+ saves_per_epoch: 1
79
+ debug:
80
+ deepspeed:
81
+ weight_decay: 0.1
82
+ fsdp:
83
+ fsdp_config:
84
+ special_tokens:
85
+ bos_token: "<s>"
86
+ eos_token: "</s>"
87
+ unk_token: "<unk>"
88
+
89
+ ```
90
+
91
+ </details><br>
92
+
93
+ [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="200" height="32"/>](https://wandb.ai/ashrielbrian/openllama-axolotl/runs/y4gkw5cu)
94
+ # outputs/lora-out
95
+
96
+ This model is a fine-tuned version of [openlm-research/open_llama_3b_v2](https://huggingface.co/openlm-research/open_llama_3b_v2) on the None dataset.
97
+ It achieves the following results on the evaluation set:
98
+ - Loss: 1.0423
99
+
100
+ ## Model description
101
+
102
+ More information needed
103
+
104
+ ## Intended uses & limitations
105
+
106
+ More information needed
107
+
108
+ ## Training and evaluation data
109
+
110
+ More information needed
111
+
112
+ ## Training procedure
113
+
114
+ ### Training hyperparameters
115
+
116
+ The following hyperparameters were used during training:
117
+ - learning_rate: 0.0002
118
+ - train_batch_size: 2
119
+ - eval_batch_size: 2
120
+ - seed: 42
121
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
122
+ - lr_scheduler_type: cosine
123
+ - lr_scheduler_warmup_steps: 20
124
+ - num_epochs: 4
125
+ - mixed_precision_training: Native AMP
126
+
127
+ ### Training results
128
+
129
+ | Training Loss | Epoch | Step | Validation Loss |
130
+ |:-------------:|:------:|:-----:|:---------------:|
131
+ | 1.4066 | 0.0002 | 1 | 1.6832 |
132
+ | 0.9583 | 0.2501 | 1346 | 1.1052 |
133
+ | 1.0801 | 0.5003 | 2692 | 1.0731 |
134
+ | 0.8311 | 0.7504 | 4038 | 1.0377 |
135
+ | 0.9795 | 1.0006 | 5384 | 1.0241 |
136
+ | 0.9849 | 1.2334 | 6730 | 1.0143 |
137
+ | 1.1134 | 1.4836 | 8076 | 1.0098 |
138
+ | 0.916 | 1.7337 | 9422 | 1.0073 |
139
+ | 0.8791 | 2.0011 | 10768 | 1.0076 |
140
+ | 1.1143 | 2.2513 | 12114 | 1.0257 |
141
+ | 1.1426 | 2.5014 | 13460 | 1.0169 |
142
+ | 1.0163 | 2.7515 | 14806 | 1.0169 |
143
+ | 0.8814 | 3.0017 | 16152 | 1.0085 |
144
+ | 0.8806 | 3.2338 | 17498 | 1.0438 |
145
+ | 0.9132 | 3.4839 | 18844 | 1.0442 |
146
+ | 0.7981 | 3.7341 | 20190 | 1.0423 |
147
 
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  ### Framework versions
150
 
151
+ - PEFT 0.11.1
152
+ - Transformers 4.42.4
153
+ - Pytorch 2.3.1+cu121
154
+ - Datasets 2.19.1
155
+ - Tokenizers 0.19.1
example_lora_usage.ipynb ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 24,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from peft import PeftModel"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 16,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
19
+ "import torch"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "markdown",
24
+ "metadata": {},
25
+ "source": [
26
+ "### Load the base model"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": 17,
32
+ "metadata": {},
33
+ "outputs": [],
34
+ "source": [
35
+ "model = AutoModelForCausalLM.from_pretrained(\"openlm-research/open_llama_3b_v2\", torch_dtype=torch.float16, device_map=\"auto\")"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 8,
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "tokenizer = AutoTokenizer.from_pretrained(\"ashrielbrian/openllama_3b_v2-teknium-GPT4-LLM-Cleaned\")"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 18,
50
+ "metadata": {},
51
+ "outputs": [],
52
+ "source": [
53
+ "inp = tokenizer(\"write a function that takes in two integers, and returns its modulo.\", return_tensors=\"pt\")\n"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "execution_count": 19,
59
+ "metadata": {},
60
+ "outputs": [
61
+ {
62
+ "data": {
63
+ "text/plain": [
64
+ "{'input_ids': tensor([[ 1, 2786, 260, 1155, 347, 2976, 293, 846, 1146, 6014,\n",
65
+ " 29522, 295, 5729, 737, 966, 19795, 29520]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}"
66
+ ]
67
+ },
68
+ "execution_count": 19,
69
+ "metadata": {},
70
+ "output_type": "execute_result"
71
+ }
72
+ ],
73
+ "source": [
74
+ "inp"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": 21,
80
+ "metadata": {},
81
+ "outputs": [
82
+ {
83
+ "data": {
84
+ "text/plain": [
85
+ "{'input_ids': tensor([[ 1, 2786, 260, 1155, 347, 2976, 293, 846, 1146, 6014,\n",
86
+ " 29522, 295, 5729, 737, 966, 19795, 29520]], device='cuda:0'),\n",
87
+ " 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], device='cuda:0')}"
88
+ ]
89
+ },
90
+ "execution_count": 21,
91
+ "metadata": {},
92
+ "output_type": "execute_result"
93
+ }
94
+ ],
95
+ "source": [
96
+ "inputs = {k: v.to(\"cuda\") for k, v in inp.items()}\n",
97
+ "inputs"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": 22,
103
+ "metadata": {},
104
+ "outputs": [],
105
+ "source": [
106
+ "with torch.no_grad():\n",
107
+ " generate_ids = model.generate(**inputs, max_length=1000)"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 23,
113
+ "metadata": {},
114
+ "outputs": [
115
+ {
116
+ "data": {
117
+ "text/plain": [
118
+ "'write a function that takes in two integers, and returns its modulo.\\nFor example, if you have the integers 10 and 2, then the modulo of 10 and 2 is 2.\\nThe modulo of 10 and 3 is 3.\\nThe modulo of 10 and 4 is 4.\\nThe modulo of 10 and 5 is 5.\\nThe modulo of 10 and 6 is 6.\\nThe modulo of 10 and 7 is 7.\\nThe modulo of 10 and 8 is 8.\\nThe modulo of 10 and 9 is 9.\\nThe modulo of 10 and 10 is 10.\\nThe modulo of 10 and 11 is 11.\\nThe modulo of 10 and 12 is 12.\\nThe modulo of 10 and 13 is 13.\\nThe modulo of 10 and 14 is 14.\\nThe modulo of 10 and 15 is 15.\\nThe modulo of 10 and 16 is 16.\\nThe modulo of 10 and 17 is 17.\\nThe modulo of 10 and 18 is 18.\\nThe modulo of 10 and 19 is 19.\\nThe modulo of 10 and 20 is 20.\\nThe modulo of 10 and 21 is 21.\\nThe modulo of 10 and 22 is 22.\\nThe modulo of 10 and 23 is 23.\\nThe modulo of 10 and 24 is 24.\\nThe modulo of 10 and 25 is 25.\\nThe modulo of 10 and 26 is 26.\\nThe modulo of 10 and 27 is 27.\\nThe modulo of 10 and 28 is 28.\\nThe modulo of 10 and 29 is 29.\\nThe modulo of 10 and 30 is 30.\\nThe modulo of 10 and 31 is 31.\\nThe modulo of 10 and 32 is 32.\\nThe modulo of 10 and 33 is 33.\\nThe modulo of 10 and 34 is 34.\\nThe modulo of 10 and 35 is 35.\\nThe modulo of 10 and 36 is 36.\\nThe modulo of 10 and 37 is 37.\\nThe modulo of 10 and 38 is 38.\\nThe modulo of 10 and 39 is 39.\\nThe modulo of 10 and 40 is 40.\\nThe modulo of 10 and 41 is 41.\\nThe modulo of 10 and 42 is 42.\\nThe modulo of 10 and 43 is 43.\\nThe modulo of 10 and 44 is 44.\\nThe modulo of 10 and 45 is 45.\\nThe modulo of 10 and 46 is 46.\\nThe modulo of 10 and 47 is 47.\\nThe modulo of 10 and 48 is 48.\\nThe modulo of 10 and 49 is 49.\\nThe modulo of 10 and 50 is 50.\\nThe modulo of 10 and 51 is 51.\\nThe modulo of 10 and 52 is 52.\\nThe modulo of 10 and 53 is 53.\\nThe modulo of 10 and 54 is 54.\\nThe modulo of 10 and 55 is 55.\\nThe modulo of 10 and 56 is 56.\\nThe modulo of 10 and 57 is 57.\\nThe modulo of 10 and 58 is 58.\\nThe modulo of 10 and 59 is'"
119
+ ]
120
+ },
121
+ "execution_count": 23,
122
+ "metadata": {},
123
+ "output_type": "execute_result"
124
+ }
125
+ ],
126
+ "source": [
127
+ "# the output is practically gibberish because it was trained as a completion model, and is NOT instruction-tuned.\n",
128
+ "outputs = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]\n",
129
+ "outputs\n"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "markdown",
134
+ "metadata": {},
135
+ "source": [
136
+ "### Load adapters without merging"
137
+ ]
138
+ },
139
+ {
140
+ "cell_type": "code",
141
+ "execution_count": 32,
142
+ "metadata": {},
143
+ "outputs": [],
144
+ "source": [
145
+ "peft_model_id = \"ashrielbrian/openllama_3b_v2-teknium-GPT4-LLM-Cleaned\"\n",
146
+ "model = PeftModel.from_pretrained(model, peft_model_id)"
147
+ ]
148
+ },
149
+ {
150
+ "cell_type": "code",
151
+ "execution_count": 35,
152
+ "metadata": {},
153
+ "outputs": [
154
+ {
155
+ "data": {
156
+ "text/plain": [
157
+ "'write a function that takes in two integers, and returns its modulo.\\n\\nHere is one way to write the function in Python:\\n\\n```python\\ndef modulo(a, b):\\n return a % b\\n```\\n\\nThis function takes in two arguments, `a` and `b`, and returns the remainder of `a` when divided by `b`. The remainder is the value that remains after the division.'"
158
+ ]
159
+ },
160
+ "execution_count": 35,
161
+ "metadata": {},
162
+ "output_type": "execute_result"
163
+ }
164
+ ],
165
+ "source": [
166
+ "with torch.no_grad():\n",
167
+ " generate_ids = model.generate(**inputs, max_length=1000)\n",
168
+ "\n",
169
+ "outputs = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]\n",
170
+ "outputs"
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "markdown",
175
+ "metadata": {},
176
+ "source": [
177
+ "### Merge the adapter into the base model\n",
178
+ "Helpful resource on [Huggingface](https://huggingface.co/docs/peft/main/en/developer_guides/lora)."
179
+ ]
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "execution_count": 36,
184
+ "metadata": {},
185
+ "outputs": [
186
+ {
187
+ "data": {
188
+ "text/plain": [
189
+ "PeftModelForCausalLM(\n",
190
+ " (base_model): LoraModel(\n",
191
+ " (model): LlamaForCausalLM(\n",
192
+ " (model): LlamaModel(\n",
193
+ " (embed_tokens): Embedding(32000, 3200, padding_idx=0)\n",
194
+ " (layers): ModuleList(\n",
195
+ " (0-25): 26 x LlamaDecoderLayer(\n",
196
+ " (self_attn): LlamaSdpaAttention(\n",
197
+ " (q_proj): Linear(in_features=3200, out_features=3200, bias=False)\n",
198
+ " (k_proj): Linear(in_features=3200, out_features=3200, bias=False)\n",
199
+ " (v_proj): Linear(in_features=3200, out_features=3200, bias=False)\n",
200
+ " (o_proj): Linear(in_features=3200, out_features=3200, bias=False)\n",
201
+ " (rotary_emb): LlamaRotaryEmbedding()\n",
202
+ " )\n",
203
+ " (mlp): LlamaMLP(\n",
204
+ " (gate_proj): Linear(in_features=3200, out_features=8640, bias=False)\n",
205
+ " (up_proj): Linear(in_features=3200, out_features=8640, bias=False)\n",
206
+ " (down_proj): Linear(in_features=8640, out_features=3200, bias=False)\n",
207
+ " (act_fn): SiLU()\n",
208
+ " )\n",
209
+ " (input_layernorm): LlamaRMSNorm()\n",
210
+ " (post_attention_layernorm): LlamaRMSNorm()\n",
211
+ " )\n",
212
+ " )\n",
213
+ " (norm): LlamaRMSNorm()\n",
214
+ " )\n",
215
+ " (lm_head): Linear(in_features=3200, out_features=32000, bias=False)\n",
216
+ " )\n",
217
+ " )\n",
218
+ ")"
219
+ ]
220
+ },
221
+ "execution_count": 36,
222
+ "metadata": {},
223
+ "output_type": "execute_result"
224
+ }
225
+ ],
226
+ "source": [
227
+ "model.merge_and_unload()"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "code",
232
+ "execution_count": 37,
233
+ "metadata": {},
234
+ "outputs": [
235
+ {
236
+ "data": {
237
+ "text/plain": [
238
+ "'write a function that takes in two integers, and returns its modulo.\\n\\nHere is one way to write the function in Python:\\n\\n```python\\ndef modulo(a, b):\\n return a % b\\n```\\n\\nThis function takes in two arguments, `a` and `b`, and returns the remainder of `a` when divided by `b`. The remainder is the value that remains after the division.'"
239
+ ]
240
+ },
241
+ "execution_count": 37,
242
+ "metadata": {},
243
+ "output_type": "execute_result"
244
+ }
245
+ ],
246
+ "source": [
247
+ "with torch.no_grad():\n",
248
+ " generate_ids = model.generate(**inputs, max_length=1000)\n",
249
+ "\n",
250
+ "# inference latency here is lower than if we kept the adapter separate as in the previous step\n",
251
+ "# comparing walltime between the unmerged adapter model, with the merged LORA weights, are 1.3s and 0.9s respectively.\n",
252
+ "outputs = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]\n",
253
+ "outputs"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "execution_count": null,
259
+ "metadata": {},
260
+ "outputs": [],
261
+ "source": []
262
+ }
263
+ ],
264
+ "metadata": {
265
+ "kernelspec": {
266
+ "display_name": "axolotl",
267
+ "language": "python",
268
+ "name": "python3"
269
+ },
270
+ "language_info": {
271
+ "codemirror_mode": {
272
+ "name": "ipython",
273
+ "version": 3
274
+ },
275
+ "file_extension": ".py",
276
+ "mimetype": "text/x-python",
277
+ "name": "python",
278
+ "nbconvert_exporter": "python",
279
+ "pygments_lexer": "ipython3",
280
+ "version": "3.10.14"
281
+ }
282
+ },
283
+ "nbformat": 4,
284
+ "nbformat_minor": 2
285
+ }