File size: 4,541 Bytes
9d84a85
 
5b2bd19
9d84a85
5b2bd19
9d84a85
 
 
 
 
 
 
ed9115a
 
 
 
 
 
 
 
 
 
 
 
 
 
5b2bd19
9d84a85
 
 
ed9115a
 
 
9d84a85
 
 
ed9115a
 
 
 
 
 
 
 
 
9d84a85
ed9115a
9d84a85
ed9115a
9d84a85
ed9115a
9d84a85
ed9115a
 
 
 
 
9d84a85
ed9115a
 
 
 
 
 
 
 
9d84a85
ed9115a
9d84a85
ed9115a
9d84a85
ed9115a
9d84a85
ed9115a
 
 
 
 
 
 
 
 
 
 
 
 
 
9d84a85
 
 
ed9115a
9d84a85
ed9115a
 
 
9d84a85
ed9115a
9d84a85
ed9115a
9d84a85
ed9115a
9d84a85
ed9115a
 
 
 
 
9d84a85
f96b1dc
ed9115a
 
 
 
 
 
 
 
 
 
9d84a85
ed9115a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d84a85
 
ed9115a
 
 
9d84a85
ed9115a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158


---
language: en
license: apache-2.0
tags:
- text-generation
- conversational
- gpt
- from-scratch
- lora
- pytorch
---

 ---
language: en
license: mit
library_name: pytorch
tags:
  - text-generation
  - conversational
  - transformer
  - lora
  - from-scratch
  - pytorch
pipeline_tag: text-generation
---

# TinyTalk-124M

**TinyTalk-124M** is a 124M-parameter conversational language model, built by fine-tuning a from-scratch pretrained transformer backbone (**ScratchLM-95M**) using LoRA (Low-Rank Adaptation). The entire pipeline — architecture, pretraining, and fine-tuning — was implemented independently in PyTorch, with no pretrained weights sourced from any external model at any stage.

---

## Model Details

| | |
|---|---|
| **Developed by** | Debarun Das |
| **Model type** | Decoder-only transformer, LoRA fine-tuned |
| **Language** | English |
| **License** | MIT |
| **Base model** | ScratchLM-95M (trained from scratch) |
| **Parameters** | ~124.2M |
| **Framework** | PyTorch |

---

## Architecture

TinyTalk-124M inherits its backbone from **ScratchLM-95M**, a 12-layer decoder-only transformer using:

- **RoPE (Rotary Positional Embeddings)** for relative position encoding
- **SwiGLU activation** in the feed-forward layers (as used in LLaMA, Mistral, and Gemma)
- **Causal self-attention** with Flash Attention (SDPA fallback)
- **Pre-Norm** transformer blocks with residual connections
- **GPT-2 BPE tokenizer** (50,257 vocabulary)

| Parameter | Value |
|---|---|
| Layers | 12 |
| Embedding Dimension | 512 |
| Attention Heads | 8 (head_dim = 64) |
| FFN Intermediate Dim | 2,730 |
| Context Length | 512 tokens |
| Base Perplexity (WikiText-103) | 24.40 |

---

## Fine-Tuning Approach

TinyTalk-124M was produced using a parameter-efficient LoRA adaptation strategy:

- The base model backbone remains **frozen** throughout fine-tuning
- Trainable low-rank matrices (**rank = 64, alpha = 128**) are injected into attention (`qkv_proj`, `out_proj`) and feed-forward (`w1`, `w2`, `w3`) projections
- Adapter weights are merged directly into the base after training: `W' = W₀ + B·A · (α/r)`, producing a standalone, dependency-free checkpoint
- Fine-tuned on **69,220 instruction/response conversational pairs** (ChatAlpaca-style format)
- Trained with AdamW, cosine learning rate decay, and mixed precision (AMP)

| Metric | Value |
|---|---|
| Adaptation Method | LoRA (r=64, α=128) |
| Fine-Tuning Data | 69,220 instruction/response pairs |
| Training Epochs | 5 |
| Validation Perplexity | ~25.8 |

---

## Intended Use

TinyTalk-124M is designed for:

- Instruction-following and conversational text generation
- Research and educational demonstrations of from-scratch LLM pretraining and LoRA fine-tuning
- Lightweight experimentation on consumer-grade hardware

As a 124M-parameter model, it is best suited to general conversational and instructional prompts rather than tasks requiring extensive world knowledge or long-context reasoning — its scale reflects a deliberate choice to make the full architecture-to-deployment pipeline reproducible on a single consumer GPU.

---

## How to Use

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("Debarun12/tinytalk-124m")
model = AutoModelForCausalLM.from_pretrained("Debarun12/tinytalk-124m")

prompt = "How can I improve my relationship with my family?"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
    **inputs,
    max_new_tokens=80,
    repetition_penalty=3.0,
    do_sample=True,
    temperature=0.7
)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

---

## Training Data

The fine-tuning dataset consists of 69,220 cleaned instruction/response conversational pairs in an Alpaca-style format, curated and deduplicated to maintain consistent formatting and answer quality.

---

## Training Infrastructure

- **Hardware:** Single consumer GPU
- **Framework:** PyTorch (no external training libraries)
- **Precision:** Mixed precision (AMP)
- **Optimizer:** AdamW with cosine learning rate decay

---

## Citation

If you use this model, please cite:

```bibtex
@misc{tinytalk124m2026,
  author = {Debarun Das},
  title = {TinyTalk-124M: A Conversational Language Model Built From Scratch},
  year = {2026},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/Debarun12}}
}
```

---

## Author

**Debarun Das**
[GitHub](https://github.com/debarun23) · [Hugging Face](https://huggingface.co/Debarun12)