Havoc999 commited on
Commit
7e1c7bc
Β·
verified Β·
1 Parent(s): ef8705e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +232 -60
README.md CHANGED
@@ -1,25 +1,29 @@
1
  ---
2
  language:
3
  - en
4
- license:
5
- - apache-2.0
6
- base_model:
7
- - TinyLlama/TinyLlama-1.1B-Chat-v1.0
8
  datasets:
9
  - tatsu-lab/alpaca
10
  tags:
11
  - instruction-tuning
12
  - lora
13
- - chatbot
14
- - trl
15
  - peft
 
 
 
 
16
  ---
17
 
18
  # πŸ€– Tiny Chatbot β€” LoRA Fine-Tuned on Alpaca
19
 
20
- Fine-tuned **tiny-chatbot** on the
21
- [tatsu-lab/alpaca](https://huggingface.co/datasets/tatsu-lab/alpaca) dataset
22
- using LoRA (rank {CFG.lora_r}) via TRL's SFTTrainer on Kaggle Dual T4 GPU.
 
 
 
 
23
 
24
  ## πŸš€ Quick Start
25
 
@@ -28,66 +32,234 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
28
  import torch
29
 
30
  model = AutoModelForCausalLM.from_pretrained(
31
- "{CFG.hub_model_id}", torch_dtype=torch.float16
32
- ).cuda()
33
- tok = AutoTokenizer.from_pretrained("{CFG.hub_model_id}")
 
 
34
 
35
  prompt = (
36
- "Below is an instruction that describes a task.\\n"
37
- "Write a response that appropriately completes the request.\\n\\n"
38
- "### Instruction:\\nExplain gravity simply.\\n\\n### Response:\\n"
 
 
 
 
 
 
 
 
 
 
 
 
39
  )
40
- ids = tok(prompt, return_tensors="pt").input_ids.cuda()
41
- out = model.generate(ids, max_new_tokens=200, temperature=0.7, do_sample=True)
42
- print(tok.decode(out[0, ids.shape[1]:], skip_special_tokens=True))
43
  ```
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  ## πŸ“‹ Training Details
46
 
47
  | Setting | Value |
48
- |---------|-------|
49
- | Base model | `{CFG.model_name}` |
50
- | Dataset | tatsu-lab/alpaca ({CFG.train_size:,} train + {CFG.eval_size:,} eval) |
51
- | LoRA rank | {CFG.lora_r} |
52
- | LoRA alpha | {CFG.lora_alpha} |
53
- | Epochs | {CFG.num_epochs} |
54
- | Peak LR | {CFG.learning_rate} |
55
- | Effective batch | {CFG.batch_size * 2 * CFG.grad_accum} ({CFG.batch_size}/GPU Γ— 2 GPUs Γ— {CFG.grad_accum} accum) |
56
- | Precision | float16 |
57
- | Hardware | Kaggle Dual T4 (2 Γ— 16 GiB) |
58
-
59
- ### "The model achieved an average ROUGE-L F1-score of 0.3209 over 50 evaluation examples using Porter stemming, indicating a moderate to strong capability in instruction-following structure, though limited by occasional stylistic variations and specific factual deviations from the ground truth."
60
- ### Model : Havoc999/tiny-chatbot
61
- ### Dataset : MMLU Elementary Mathematics
62
- ### Samples Evaluated : 50
63
- ### Correct : 15
64
- ### Invalid Outputs : 4
65
- ### Accuracy : 30.00%
66
- ### Random Baseline : 25.00%
67
- ============================================================
68
- BENCHMARK RESULTS
69
- ============================================================
70
-
71
- hellaswag
72
- sample_len 200.0000
73
- acc,none 0.4550
74
- acc_norm,none 0.5600
75
-
76
- piqa
77
- sample_len 200.0000
78
- acc,none 0.7450
79
- acc_norm,none 0.7400
80
-
81
- arc_challenge
82
- sample_len 200.0000
83
- acc,none 0.3050
84
- acc_norm,none 0.3500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  ## ⚠️ Limitations
88
 
89
- - English-only
90
- - May hallucinate facts β€” verify important claims
91
- - 1.1 B parameter model: complex multi-step reasoning can fail
92
- - Not RLHF-aligned for safety beyond TinyLlama's base alignment
93
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  language:
3
  - en
4
+ license: apache-2.0
5
+ base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
 
 
6
  datasets:
7
  - tatsu-lab/alpaca
8
  tags:
9
  - instruction-tuning
10
  - lora
 
 
11
  - peft
12
+ - trl
13
+ - chatbot
14
+ - causal-lm
15
+ pipeline_tag: text-generation
16
  ---
17
 
18
  # πŸ€– Tiny Chatbot β€” LoRA Fine-Tuned on Alpaca
19
 
20
+ A conversational assistant produced by fine-tuning
21
+ **[TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0)**
22
+ on the **[tatsu-lab/alpaca](https://huggingface.co/datasets/tatsu-lab/alpaca)**
23
+ instruction dataset (52 K English instruction–response pairs) using
24
+ LoRA (rank 16) via TRL's SFTTrainer on a Kaggle Dual T4 GPU environment.
25
+
26
+ ---
27
 
28
  ## πŸš€ Quick Start
29
 
 
32
  import torch
33
 
34
  model = AutoModelForCausalLM.from_pretrained(
35
+ "YOUR_HF_USERNAME/tiny-chatbot",
36
+ torch_dtype=torch.float16,
37
+ device_map="auto",
38
+ )
39
+ tokenizer = AutoTokenizer.from_pretrained("YOUR_HF_USERNAME/tiny-chatbot")
40
 
41
  prompt = (
42
+ "Below is an instruction that describes a task. "
43
+ "Write a response that appropriately completes the request.\n\n"
44
+ "### Instruction:\n"
45
+ "Explain the water cycle in simple terms.\n\n"
46
+ "### Response:\n"
47
+ )
48
+
49
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
50
+ output = model.generate(
51
+ **inputs,
52
+ max_new_tokens=256,
53
+ temperature=0.7,
54
+ top_p=0.9,
55
+ do_sample=True,
56
+ repetition_penalty=1.15,
57
  )
58
+ response = tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True)
59
+ print(response)
 
60
  ```
61
 
62
+ ### Multi-turn (Chat Template)
63
+
64
+ ```python
65
+ from transformers import pipeline
66
+
67
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
68
+
69
+ messages = [
70
+ {"role": "user", "content": "What is photosynthesis?"},
71
+ ]
72
+
73
+ # TinyLlama-Chat supports the built-in chat template
74
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
75
+ print(pipe(prompt, max_new_tokens=200)[0]["generated_text"])
76
+ ```
77
+
78
+ ---
79
+
80
+ ## πŸ“Š Benchmark Results
81
+
82
+ All benchmarks were evaluated after fine-tuning, using greedy decoding unless otherwise noted.
83
+
84
+ ### MMLU β€” Elementary Mathematics
85
+
86
+ | Metric | Value |
87
+ |---|---|
88
+ | Samples evaluated | 50 |
89
+ | Correct | 15 |
90
+ | Invalid outputs | 4 |
91
+ | **Accuracy** | **30.00%** |
92
+ | Random baseline (4-way) | 25.00% |
93
+
94
+ > **+5 pp above random.** The model demonstrates marginal elementary math ability consistent with the small 1.1 B parameter count and an English instruction dataset that contains limited mathematical content.
95
+
96
+ ---
97
+
98
+ ### HellaSwag *(commonsense NLI)*
99
+
100
+ | Metric | Score | Samples |
101
+ |---|---|---|
102
+ | Accuracy | 0.4550 | 200 |
103
+ | Accuracy (normalised) | **0.5600** | 200 |
104
+
105
+ > Normalised accuracy above 0.50 indicates better-than-random commonsense sentence completion. HellaSwag is a strong proxy for general language understanding.
106
+
107
+ ---
108
+
109
+ ### PIQA *(physical intuition QA)*
110
+
111
+ | Metric | Score | Samples |
112
+ |---|---|---|
113
+ | Accuracy | 0.7450 | 200 |
114
+ | Accuracy (normalised) | **0.7400** | 200 |
115
+
116
+ > PIQA tests physical intuition and everyday procedural knowledge. 0.74 is a solid result for a 1.1 B model, suggesting the base pre-training retains good world knowledge even after instruction fine-tuning.
117
+
118
+ ---
119
+
120
+ ### ARC Challenge *(grade-school science)*
121
+
122
+ | Metric | Score | Samples |
123
+ |---|---|---|
124
+ | Accuracy | 0.3050 | 200 |
125
+ | Accuracy (normalised) | **0.3500** | 200 |
126
+
127
+ > ARC-Challenge targets questions that require reasoning beyond simple retrieval. 0.35 normalised reflects the model's limitations on multi-step reasoning at this scale.
128
+
129
+ ---
130
+
131
+ ### Summary
132
+
133
+ | Benchmark | Metric | Score |
134
+ |---|---|---|
135
+ | MMLU Elem. Math | Accuracy | 30.00% |
136
+ | HellaSwag | Acc (norm) | 56.00% |
137
+ | PIQA | Acc (norm) | 74.00% |
138
+ | ARC Challenge | Acc (norm) | 35.00% |
139
+
140
+ ---
141
+
142
  ## πŸ“‹ Training Details
143
 
144
  | Setting | Value |
145
+ |---|---|
146
+ | Base model | TinyLlama/TinyLlama-1.1B-Chat-v1.0 |
147
+ | Dataset | tatsu-lab/alpaca |
148
+ | Train split | 45,000 examples |
149
+ | Eval split | 2,000 examples |
150
+ | Fine-tuning method | LoRA (PEFT) |
151
+ | LoRA rank | 16 |
152
+ | LoRA alpha | 32 |
153
+ | LoRA dropout | 0.05 |
154
+ | Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
155
+ | Trainable parameters | ~17 M / 1.1 B (~1.55%) |
156
+ | Precision | float16 (AMP) |
157
+ | Epochs | 3 |
158
+ | Per-GPU batch size | 4 |
159
+ | Gradient accumulation | 4 steps |
160
+ | Effective global batch | 32 (4 Γ— 2 GPUs Γ— 4 accum) |
161
+ | Peak learning rate | 2e-4 |
162
+ | LR scheduler | Cosine annealing |
163
+ | Warmup ratio | 3% |
164
+ | Gradient checkpointing | Enabled |
165
+ | NEFTune noise alpha | 5 |
166
+ | Hardware | Kaggle Dual T4 (2 Γ— 16 GiB VRAM) |
167
+ | Loss masking | Completion-only (response tokens only) |
168
+ | Early stopping patience | 3 evaluations |
169
+
170
+ ---
171
+
172
+ ## βš™οΈ Reproduce
173
+
174
+ ```python
175
+ # Install dependencies
176
+ # pip install transformers datasets peft trl accelerate bitsandbytes huggingface_hub
177
+
178
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
179
+ from peft import LoraConfig, get_peft_model, TaskType
180
+ from trl import SFTTrainer, DataCollatorForCompletionOnlyLM
181
+ from datasets import load_dataset
182
+
183
+ # 1. Load dataset
184
+ dataset = load_dataset("tatsu-lab/alpaca", split="train")
185
+
186
+ # 2. Format examples
187
+ def format_alpaca(ex):
188
+ input_section = f"### Input:\n{ex['input']}\n\n" if ex["input"].strip() else ""
189
+ return {
190
+ "text": (
191
+ "Below is an instruction that describes a task. "
192
+ "Write a response that appropriately completes the request.\n\n"
193
+ f"### Instruction:\n{ex['instruction']}\n\n"
194
+ f"{input_section}"
195
+ f"### Response:\n{ex['output']}"
196
+ )
197
+ }
198
+
199
+ dataset = dataset.map(format_alpaca, batched=False)
200
 
201
+ # 3. Load model + LoRA
202
+ tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
203
+ tokenizer.pad_token = tokenizer.eos_token
204
+
205
+ model = AutoModelForCausalLM.from_pretrained(
206
+ "TinyLlama/TinyLlama-1.1B-Chat-v1.0",
207
+ torch_dtype="auto",
208
+ device_map={"": 0},
209
+ )
210
+ model.config.use_cache = False
211
+ model.enable_input_require_grads()
212
+
213
+ lora_config = LoraConfig(
214
+ r=16, lora_alpha=32, lora_dropout=0.05,
215
+ bias="none", task_type=TaskType.CAUSAL_LM,
216
+ target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"],
217
+ )
218
+ model = get_peft_model(model, lora_config)
219
+
220
+ # 4. Train
221
+ trainer = SFTTrainer(
222
+ model=model, tokenizer=tokenizer,
223
+ train_dataset=dataset,
224
+ dataset_text_field="text",
225
+ max_seq_length=512,
226
+ data_collator=DataCollatorForCompletionOnlyLM("### Response:\n", tokenizer=tokenizer),
227
+ args=TrainingArguments(
228
+ output_dir="./chatbot-lora",
229
+ num_train_epochs=3,
230
+ per_device_train_batch_size=4,
231
+ gradient_accumulation_steps=4,
232
+ learning_rate=2e-4,
233
+ fp16=True,
234
+ gradient_checkpointing=True,
235
+ save_strategy="steps", save_steps=200, save_total_limit=3,
236
+ eval_strategy="no",
237
+ ),
238
+ )
239
+ trainer.train()
240
+ ```
241
+
242
+ ---
243
 
244
  ## ⚠️ Limitations
245
 
246
+ - **English only** β€” the base model and Alpaca dataset are English-focused; other languages may produce incoherent outputs.
247
+ - **Hallucination** β€” like all generative models, this one can confidently state incorrect facts. Always verify important claims.
248
+ - **Limited reasoning** β€” at 1.1 B parameters, multi-step logical and mathematical reasoning is unreliable (see ARC / MMLU results above).
249
+ - **No RLHF safety alignment** β€” this model has not undergone reinforcement learning from human feedback. It inherits TinyLlama's base alignment only and may produce inappropriate responses to adversarial prompts.
250
+ - **Short context** β€” trained with a maximum sequence length of 512 tokens; very long conversations will be truncated.
251
+ - **Not production-ready** β€” intended as a learning artefact and research baseline, not a deployed consumer product.
252
+
253
+ ---
254
+
255
+ ## πŸ“œ License
256
+
257
+ This model is released under the **Apache 2.0** license, consistent with the
258
+ [TinyLlama base model](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0)
259
+ and the
260
+ [Alpaca dataset](https://huggingface.co/datasets/tatsu-lab/alpaca).
261
+ See [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) for full terms.
262
+
263
+ ---
264
+
265
+ *Fine-tuned on Kaggle Dual T4 GPU Β· TRL SFTTrainer Β· LoRA via PEFT*