cahlen commited on
Commit
23dc7a3
·
verified ·
1 Parent(s): e9bd214

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +228 -195
README.md CHANGED
@@ -1,202 +1,235 @@
1
  ---
2
- base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
 
 
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.15.1
 
1
  ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
  library_name: peft
6
+ base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
7
+ tags:
8
+ - tinyllama
9
+ - llama
10
+ - qlora
11
+ - fine-tuning
12
+ - motorcycle-repair
13
+ - question-answering
14
+ - generated:text-generation-code:pipeline_example
15
+ pipeline_tag: text-generation
16
+ datasets:
17
+ - cahlen/cdg-motorcycle-repair-qa-data-85x10
18
+ model_index:
19
+ - name: cahlen/tinyllama-motorcycle-repair-qa-adapter
20
+ results: []
21
  ---
22
 
23
+ # LoRA Adapter for TinyLlama-1.1B-Chat specialized on Motorcycle Repair QA
24
+
25
+ This repository contains LoRA adapter weights fine-tuned from the base model `TinyLlama/TinyLlama-1.1B-Chat-v1.0`. The goal was to enhance the model's knowledge and question-answering capabilities specifically within the domain of motorcycle repair and maintenance, while leveraging the efficiency of the compact TinyLlama architecture.
26
+
27
+ This adapter was trained using QLoRA for memory efficiency.
28
+
29
+ ## Model Description
30
+
31
+ * **Base Model:** [TinyLlama/TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0)
32
+ * **Adapter Task:** Question Answering / Instruction Following on Motorcycle Repair topics.
33
+ * **Fine-tuning Method:** QLoRA (4-bit quantization) via `trl`'s `SFTTrainer`.
34
+ * **Dataset:** [cahlen/cdg-motorcycle-repair-qa-data-85x10](https://huggingface.co/datasets/cahlen/cdg-motorcycle-repair-qa-data-85x10) (880 synthetically generated QA pairs).
35
+
36
+ ## Key Features
37
+
38
+ * **Domain Specialization:** Improved performance on questions related to motorcycle repair compared to the base model.
39
+ * **Efficiency:** Builds upon the small and efficient TinyLlama (1.1B parameters). The adapter itself is only ~580MB.
40
+ * **QLoRA Trained:** Enables loading the base model in 4-bit precision for reduced memory footprint during inference.
41
+
42
+ ## How to Use
43
+
44
+ You need to load the base model (`TinyLlama/TinyLlama-1.1B-Chat-v1.0`) and then apply this LoRA adapter on top. Ensure you have `transformers`, `peft`, `accelerate`, and `bitsandbytes` installed.
45
+
46
+ ```python
47
+ import torch
48
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, pipeline
49
+ from peft import PeftModel
50
+ import os
51
+
52
+ # --- Configuration ---
53
+ base_model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
54
+ adapter_id = "cahlen/tinyllama-motorcycle-repair-qa-adapter" # This is the adapter you are using
55
+ device_map = "auto"
56
+
57
+ # --- Load Tokenizer ---
58
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
59
+ if tokenizer.pad_token is None:
60
+ tokenizer.pad_token = tokenizer.eos_token
61
+ tokenizer.padding_side = "left"
62
+
63
+ # --- Configure Quantization ---
64
+ use_4bit = True # Set to False if not using 4-bit
65
+ compute_dtype = getattr(torch, "float16") # Default compute dtype
66
+ quantization_config = None
67
+
68
+ if use_4bit and torch.cuda.is_available():
69
+ print("Using 4-bit quantization")
70
+ bnb_config = BitsAndBytesConfig(
71
+ load_in_4bit=True,
72
+ bnb_4bit_quant_type="nf4",
73
+ bnb_4bit_compute_dtype=compute_dtype,
74
+ bnb_4bit_use_double_quant=False,
75
+ )
76
+ quantization_config = bnb_config
77
+ else:
78
+ print("Not using 4-bit quantization or CUDA not available")
79
+ compute_dtype = torch.float32 # Use default float32 on CPU
80
+
81
+ # --- Load Base Model ---
82
+ print(f"Loading base model: {base_model_id}")
83
+ base_model = AutoModelForCausalLM.from_pretrained(
84
+ base_model_id,
85
+ quantization_config=quantization_config,
86
+ device_map=device_map,
87
+ trust_remote_code=True,
88
+ torch_dtype=compute_dtype # Set appropriate dtype
89
+ )
90
+ base_model.config.use_cache = True
91
+
92
+ # --- Load LoRA Adapter ---
93
+ print(f"Loading LoRA adapter: {adapter_id}")
94
+ model = PeftModel.from_pretrained(base_model, adapter_id)
95
+ model.eval()
96
+ print("Adapter loaded successfully.")
97
+
98
+ # --- Prepare Prompt ---
99
+ # Example prompt
100
+ topic = "Brake System"
101
+ question = "What are the signs of worn brake pads?"
102
+ system_prompt = "You are a helpful assistant knowledgeable about motorcycle repair."
103
+
104
+ user_query = f"Topic: {topic}\nQuestion: {question}"
105
+ messages = [
106
+ {"role": "system", "content": system_prompt},
107
+ {"role": "user", "content": user_query},
108
+ ]
109
+ formatted_prompt = tokenizer.apply_chat_template(
110
+ messages,
111
+ tokenize=False,
112
+ add_generation_prompt=True
113
+ )
114
+ print(f"--- Prompt ---\n{formatted_prompt}")
115
+
116
+ # --- Generate Response ---
117
+ print("Generating...")
118
+ pipe = pipeline(
119
+ task="text-generation",
120
+ model=model,
121
+ tokenizer=tokenizer,
122
+ max_new_tokens=100,
123
+ do_sample=True,
124
+ temperature=0.7,
125
+ top_p=0.9,
126
+ pad_token_id=tokenizer.eos_token_id,
127
+ eos_token_id=tokenizer.eos_token_id
128
+ )
129
+ result = pipe(formatted_prompt)
130
+
131
+ # --- Print Response ---
132
+ print("\n--- Output ---")
133
+ print(result[0]['generated_text'])
134
+
135
+ # Extract only the assistant's response
136
+ assistant_response = result[0]['generated_text'][len(formatted_prompt):].strip()
137
+ print("\n--- Assistant Only ---")
138
+ print(assistant_response)
139
+
140
+ ```
141
 
142
  ## Training Details
143
 
144
+ * **Base Model:** `TinyLlama/TinyLlama-1.1B-Chat-v1.0`
145
+ * **Dataset:** `cahlen/cdg-motorcycle-repair-qa-data-85x10` (880 examples)
146
+ * **Training Method:** QLoRA using `trl.SFTTrainer`.
147
+ * **QLoRA Config:** 4-bit NF4 quantization, `float16` compute dtype.
148
+ * **LoRA Config:** `r=64`, `lora_alpha=16`, `lora_dropout=0.1`, target modules: `["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]`.
149
+ * **Training Arguments:**
150
+ * Epochs: 1
151
+ * Batch Size (per device): 4
152
+ * Gradient Accumulation: 2 (Effective Batch Size: 8)
153
+ * Optimizer: PagedAdamW (32-bit)
154
+ * Learning Rate: 2e-4
155
+ * LR Scheduler: Cosine
156
+ * Sequence Length: 512
157
+ * Precision: Mixed (FP16)
158
+
159
+ ## Example Usage & Responses
160
+
161
+ Here are some examples of prompts and the responses generated by this fine-tuned adapter:
162
+
163
+ **Example 1: Tire Pressure**
164
+ ```
165
+ <|system|>
166
+ You are a helpful assistant knowledgeable about motorcycle repair.</s>
167
+ <|user|>
168
+ Topic: Tire Maintenance
169
+ Question: What is the first step in checking tire pressure?</s>
170
+ <|assistant|>
171
+ The first step is to check the tire pressure, then check the tire pressure gauge, and finally check the tire tread depth.
172
+ ```
173
+
174
+ **Example 2: Oil Change Frequency**
175
+ ```
176
+ <|system|>
177
+ You are a helpful assistant knowledgeable about motorcycle repair.</s>
178
+ <|user|>
179
+ Topic: Oil Maintenance
180
+ Question: How often should I change my motorcycle oil?</s>
181
+ <|assistant|>
182
+ It is recommended to change your motorcycle oil every 5,000 to 10,000 miles, or as recommended by the manufacturer.
183
+ ```
184
+
185
+ **Example 3: Worn Brake Pads**
186
+ ```
187
+ <|system|>
188
+ You are a helpful assistant knowledgeable about motorcycle repair.</s>
189
+ <|user|>
190
+ Topic: Brake System
191
+ Question: What are the signs of worn brake pads?</s>
192
+ <|assistant|>
193
+ Worn brake pads can be felt in the brake pedal, resulting in a rough or jerky braking action, or a noticeable decrease in braking performance.
194
+ ```
195
+
196
+ **Example 4: General Knowledge Retention**
197
+ ```
198
+ <|system|>
199
+ You are a helpful assistant knowledgeable about motorcycle repair.</s>
200
+ <|user|>
201
+ Topic: Geography
202
+ Question: What is the capital of France?</s>
203
+ <|assistant|>
204
+ The capital of France is Paris.
205
+ ```
206
+
207
+ ## Limitations and Bias
208
+
209
+ * This model inherits limitations and potential biases from the base `TinyLlama` model and the synthetically generated dataset.
210
+ * The motorcycle repair knowledge, while enhanced, is based on AI-generated data and has **not** been verified by human experts. **Do not rely solely on this model for critical repair decisions.** Always consult official service manuals and qualified mechanics.
211
+ * Performance on topics outside of motorcycle repair may be degraded compared to the base model.
212
+
213
+ ## Citation
214
+
215
+ If you use this adapter, please cite the base model and consider citing this repository:
216
+
217
+ ```bibtex
218
+ @misc{cahlen_tinyllama_motorcycle_repair_qa_adapter,
219
+ author = {Cahlen},
220
+ title = {LoRA Adapter for TinyLlama-1.1B-Chat specialized on Motorcycle Repair QA},
221
+ year = {2024},
222
+ publisher = {Hugging Face},
223
+ journal = {Hugging Face Hub},
224
+ howpublished = {\url{https://huggingface.co/cahlen/tinyllama-motorcycle-repair-qa-adapter}}
225
+ }
226
+
227
+ @misc{zhang2024tinyllama,
228
+ title={TinyLlama: An Open-Source Small Language Model},
229
+ author={Peiyuan Zhang and Guangxuan Xiao and Ning Tuan Anh Tran and Xin (Notus) Li and Hao Tan and Yaowen Zhang and Philipp F. Hoefer and Hong Mo Kuan and Benn Tan and Ponnuchamy Muthu Ilakkuvan and Associated Professor Nan Yang and Dr. Si-Qing Qin and Dr. Bin Lin and Dr. Zhengin Li and Dr. Ramesha Karunasena and Dr. Ajay Kumar Jha and Mohamed Ahmed Hassan and ARIES AI},
230
+ year={2024},
231
+ eprint={2401.02385},
232
+ archivePrefix={arXiv},
233
+ primaryClass={cs.CL}
234
+ }
235
+ ```