Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -8,6 +8,7 @@ tags:
|
|
| 8 |
- tiny-stories
|
| 9 |
- adafactor
|
| 10 |
- bitlinear
|
|
|
|
| 11 |
license_name: mit
|
| 12 |
license_link: https://opensource.org/licenses/MIT
|
| 13 |
---
|
|
@@ -18,7 +19,7 @@ license_link: https://opensource.org/licenses/MIT
|
|
| 18 |
|
| 19 |
**Experimental implementation of ternary (1.58-bit) quantization for training small language models on extremely limited hardware.**
|
| 20 |
|
| 21 |
-
**Status: EXPERIMENTAL -
|
| 22 |
|
| 23 |
---
|
| 24 |
|
|
@@ -50,67 +51,183 @@ This project explores whether **ternary quantization** (weights constrained to -
|
|
| 50 |
|
| 51 |
---
|
| 52 |
|
| 53 |
-
##
|
| 54 |
|
| 55 |
-
### 1
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
| Steps | 5,000 |
|
| 60 |
-
|
|
| 61 |
-
|
|
| 62 |
-
|
|
| 63 |
-
|
|
| 64 |
-
| Duration | ~4 hours |
|
| 65 |
|
| 66 |
-
**
|
| 67 |
|
| 68 |
---
|
| 69 |
|
| 70 |
-
### 2.
|
| 71 |
|
| 72 |
-
|
|
| 73 |
-
|--------
|
| 74 |
-
|
|
| 75 |
-
|
|
| 76 |
-
|
|
| 77 |
-
|
|
| 78 |
-
|
|
| 79 |
-
|
|
| 80 |
-
|
|
| 81 |
-
| Root Cause | Missing momentum (beta1=None) |
|
| 82 |
|
| 83 |
-
**
|
| 84 |
|
| 85 |
---
|
| 86 |
|
| 87 |
-
###
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
| 92 |
-
|
|
| 93 |
-
|
|
| 94 |
-
|
|
| 95 |
-
|
|
| 96 |
-
|
|
| 97 |
-
|
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
---
|
| 103 |
|
| 104 |
## Training Configuration
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
| Setting | Value |
|
| 107 |
|---------|-------|
|
| 108 |
-
| Dataset | TinyStories
|
| 109 |
| Samples | 50,000 |
|
| 110 |
| Batch size | 4 |
|
| 111 |
| Gradient accumulation | 8 |
|
| 112 |
| Effective batch size | 32 |
|
| 113 |
-
| Optimizer | Adafactor |
|
| 114 |
| Max Learning Rate | 0.0003 |
|
| 115 |
| Min Learning Rate | 0.00003 |
|
| 116 |
| Warmup steps | 1,000 |
|
|
@@ -119,64 +236,78 @@ This project explores whether **ternary quantization** (weights constrained to -
|
|
| 119 |
|
| 120 |
---
|
| 121 |
|
| 122 |
-
##
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|-------------|---------------|-----------|--------|
|
| 128 |
-
| None (0.0) | FAST | UNSTABLE | COLLAPSED at 50k |
|
| 129 |
-
| 0.9 | SLOW | STABLE | HEALTHY but not useful |
|
| 130 |
-
| 0.5 - 0.7 | UNKNOWN | UNKNOWN | Need to test |
|
| 131 |
|
| 132 |
-
|
| 133 |
|
| 134 |
-
|
| 135 |
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|----------|-----------|---------|-----------|--------|
|
| 140 |
-
| Attempt 2 (beta1=None) | 3.16 | 8.2% | 94% "time" | COLLAPSED |
|
| 141 |
-
| Attempt 4 (beta1=0.9) | 7.56 | 96.2% | 0.56% "the" | HEALTHY (gibberish) |
|
| 142 |
|
| 143 |
-
**
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
---
|
| 146 |
|
| 147 |
-
##
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|---------|----------|---------|
|
| 151 |
-
| 1 (5k test) | 4 hours | SUCCESS (pipeline verified) |
|
| 152 |
-
| 2 (50k collapsed) | 79 hours | FAILED (beta1=None) |
|
| 153 |
-
| 3 (stopped) | 1 hour | STOPPED (wrong accumulation) |
|
| 154 |
-
| 4 (50k gibberish) | 83 hours | COMPLETED (not useful) |
|
| 155 |
-
| **Total** | **167 hours** | |
|
| 156 |
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
5. **Need optimal beta1** - Testing 0.5 and 0.7 as candidates
|
| 166 |
-
6. **Ternary quantization is challenging** - Requires careful optimizer tuning
|
| 167 |
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
-
#
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
|
| 174 |
```python
|
| 175 |
import torch
|
| 176 |
from src.model.bitlinear import BitLinearGPT
|
| 177 |
from src.tokenizer.bpe_tokenizer import BPETokenizer
|
| 178 |
|
| 179 |
-
# Load model architecture
|
| 180 |
model = BitLinearGPT(
|
| 181 |
vocab_size=4000,
|
| 182 |
d_model=256,
|
|
@@ -186,9 +317,9 @@ model = BitLinearGPT(
|
|
| 186 |
max_seq_len=256
|
| 187 |
)
|
| 188 |
|
| 189 |
-
# Load checkpoint
|
| 190 |
-
checkpoint = torch.load('checkpoint-
|
| 191 |
-
model.load_state_dict(checkpoint)
|
| 192 |
model.eval()
|
| 193 |
|
| 194 |
# Load tokenizer
|
|
@@ -199,22 +330,14 @@ input_ids = torch.tensor([tokenizer.encode("Once upon a time")])
|
|
| 199 |
# ... generation code ...
|
| 200 |
```
|
| 201 |
|
| 202 |
-
### Not For Production
|
| 203 |
-
|
| 204 |
-
These checkpoints are experimental. They will NOT produce coherent text. Use them to:
|
| 205 |
-
- Learn about ternary quantization challenges
|
| 206 |
-
- Understand model collapse patterns
|
| 207 |
-
- Compare optimizer settings
|
| 208 |
-
- Train your own models with different configs
|
| 209 |
-
|
| 210 |
---
|
| 211 |
|
| 212 |
## Tokenizers
|
| 213 |
|
| 214 |
| File | Description |
|
| 215 |
|------|-------------|
|
| 216 |
-
| tokenizer.json |
|
| 217 |
-
| tokenizer-
|
| 218 |
|
| 219 |
---
|
| 220 |
|
|
@@ -226,30 +349,39 @@ Full source code available at GitHub:
|
|
| 226 |
|
| 227 |
Includes:
|
| 228 |
- Complete training scripts
|
| 229 |
-
- Model architecture
|
|
|
|
| 230 |
- Training history documentation
|
| 231 |
- Monitoring tools
|
|
|
|
| 232 |
|
| 233 |
---
|
| 234 |
|
| 235 |
-
##
|
|
|
|
|
|
|
| 236 |
|
| 237 |
-
|
| 238 |
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
---
|
| 242 |
|
| 243 |
## Next Steps
|
| 244 |
|
| 245 |
-
| Phase | Plan |
|
| 246 |
-
|-------|------|
|
| 247 |
-
| 1 |
|
| 248 |
-
| 2 |
|
| 249 |
-
| 3 |
|
| 250 |
-
| 4 |
|
| 251 |
-
| 5 |
|
| 252 |
-
| 6 |
|
|
|
|
| 253 |
|
| 254 |
---
|
| 255 |
|
|
@@ -263,7 +395,7 @@ If you use this work for learning or research:
|
|
| 263 |
title = {ARTN: Adaptive Ternary Recurrent Network - 1.58-bit Quantization Experiments},
|
| 264 |
year = {2026},
|
| 265 |
publisher = {HuggingFace},
|
| 266 |
-
url = {https://huggingface.co/kishxrx/
|
| 267 |
}
|
| 268 |
```
|
| 269 |
|
|
@@ -279,9 +411,9 @@ MIT License
|
|
| 279 |
|
| 280 |
**THIS IS EXPERIMENTAL SOFTWARE.**
|
| 281 |
|
| 282 |
-
-
|
| 283 |
-
-
|
| 284 |
-
- Not suitable for
|
| 285 |
- No guarantees of any kind
|
| 286 |
|
| 287 |
---
|
|
@@ -293,6 +425,6 @@ MIT License
|
|
| 293 |
|
| 294 |
---
|
| 295 |
|
| 296 |
-
**Last Updated:**
|
| 297 |
|
| 298 |
-
**Version:** v0.
|
|
|
|
| 8 |
- tiny-stories
|
| 9 |
- adafactor
|
| 10 |
- bitlinear
|
| 11 |
+
- adamw
|
| 12 |
license_name: mit
|
| 13 |
license_link: https://opensource.org/licenses/MIT
|
| 14 |
---
|
|
|
|
| 19 |
|
| 20 |
**Experimental implementation of ternary (1.58-bit) quantization for training small language models on extremely limited hardware.**
|
| 21 |
|
| 22 |
+
**Status: EXPERIMENTAL - Research in Progress**
|
| 23 |
|
| 24 |
---
|
| 25 |
|
|
|
|
| 51 |
|
| 52 |
---
|
| 53 |
|
| 54 |
+
## Research Timeline
|
| 55 |
|
| 56 |
+
### Phase 1: Initial Experiments (August 2026)
|
| 57 |
|
| 58 |
+
Early experiments with Adafactor optimizer:
|
| 59 |
+
|
| 60 |
+
| Attempt | Config | Result | Issue |
|
| 61 |
+
|---------|--------|--------|-------|
|
| 62 |
+
| 5k steps | Beta1=None | COLLAPSED | Model fell into repetitive patterns |
|
| 63 |
+
| 50k steps | Beta1=None | COLLAPSED | Entropy dropped to 8.2% |
|
| 64 |
+
| 50k steps | Beta1=0.9 | HEALTHY | Learning too slow, val loss 7.56 |
|
| 65 |
+
|
| 66 |
+
**Key Finding:** Beta1=None caused collapse. Beta1=0.9 too conservative.
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
### Phase 2: Root Cause Investigation (September 2026)
|
| 71 |
+
|
| 72 |
+
**September 26, 2026:** Critical discovery - Adafactor implementation bug identified.
|
| 73 |
+
|
| 74 |
+
| Issue | Details |
|
| 75 |
+
|-------|---------|
|
| 76 |
+
| Bug location | Original Adafactor implementation |
|
| 77 |
+
| Bug type | Variance computed but not applied to updates |
|
| 78 |
+
| Impact | Optimizer behaved like SGD with momentum |
|
| 79 |
+
| Evidence | Lines 152, 170 in `src/training/adafactor.py` |
|
| 80 |
+
|
| 81 |
+
**Verification:** Original optimizer state matched broken implementation, not canonical Adafactor.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
### Phase 3: Working Models (September 2026)
|
| 86 |
+
|
| 87 |
+
**After identifying the bug, switched to AdamW optimizer:**
|
| 88 |
+
|
| 89 |
+
#### 1. FP32 + AdamW Baseline (August 19, 2026)
|
| 90 |
+
|
| 91 |
+
| Metric | Value |
|
| 92 |
+
|--------|-------|
|
| 93 |
+
| Optimizer | AdamW |
|
| 94 |
| Steps | 5,000 |
|
| 95 |
+
| Val Loss | **1.69** |
|
| 96 |
+
| Perplexity | **5.44** |
|
| 97 |
+
| Generation | β
Coherent stories |
|
| 98 |
+
| Status | **SUCCESS - Baseline established** |
|
|
|
|
| 99 |
|
| 100 |
+
**File:** `checkpoint-fp32-adamw-working.pt`
|
| 101 |
|
| 102 |
---
|
| 103 |
|
| 104 |
+
#### 2. BitLinear + AdamW (September 10-11, 2026)
|
| 105 |
|
| 106 |
+
| Metric | Value |
|
| 107 |
+
|--------|-------|
|
| 108 |
+
| Optimizer | AdamW |
|
| 109 |
+
| Steps | 9,500 |
|
| 110 |
+
| Val Loss | **1.92** |
|
| 111 |
+
| Perplexity | **6.81** |
|
| 112 |
+
| Generation | β
Coherent stories |
|
| 113 |
+
| Quantization | Ternary (1.58-bit) |
|
| 114 |
+
| Status | **SUCCESS - Ternary quantization works** |
|
|
|
|
| 115 |
|
| 116 |
+
**File:** `checkpoint-bitlinear-adamw-working.pt`
|
| 117 |
|
| 118 |
---
|
| 119 |
|
| 120 |
+
### Phase 4: Canonical Adafactor Investigation (October 15, 2026)
|
| 121 |
|
| 122 |
+
Implemented and tested canonical Adafactor (matching PyTorch reference):
|
| 123 |
+
|
| 124 |
+
| Metric | Value |
|
| 125 |
+
|--------|-------|
|
| 126 |
+
| Implementation | Verified against PyTorch (0.025% accuracy) |
|
| 127 |
+
| Val Loss | 4.82 |
|
| 128 |
+
| Perplexity | 124.10 |
|
| 129 |
+
| Optimizer State Memory | 0.16 MB (316x less than AdamW) |
|
| 130 |
+
| Observed Performance | 2.0x gap vs AdamW on tested configurations |
|
| 131 |
+
|
| 132 |
+
**Note:** Performance gap observed, but configurations differed (weight decay, momentum). Investigation ongoing.
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
|
| 136 |
+
## Key Findings
|
| 137 |
+
|
| 138 |
+
### 1. Ternary Quantization is VIABLE
|
| 139 |
+
|
| 140 |
+
| Evidence | Result |
|
| 141 |
+
|----------|--------|
|
| 142 |
+
| BitLinear + AdamW | Val loss 1.92 (vs FP32 1.69) |
|
| 143 |
+
| Performance gap | 13% (acceptable for 85% memory reduction) |
|
| 144 |
+
| Generation quality | β
Coherent stories |
|
| 145 |
+
|
| 146 |
+
**Conclusion:** Ternary quantization works with proper optimizer (AdamW).
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
### 2. Optimizer Choice is CRITICAL
|
| 151 |
+
|
| 152 |
+
| Optimizer | Result | Reason |
|
| 153 |
+
|-----------|--------|--------|
|
| 154 |
+
| Adafactor (buggy) | β FAILED | Variance not applied |
|
| 155 |
+
| Adafactor (canonical) | β οΈ 2x gap | Configuration differences |
|
| 156 |
+
| **AdamW** | β
**WORKS** | Proven convergence |
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
+
|
| 160 |
+
### 3. Beta1 Trade-off in Adafactor
|
| 161 |
+
|
| 162 |
+
| Beta1 Value | Learning Speed | Stability | Result |
|
| 163 |
+
|-------------|---------------|-----------|--------|
|
| 164 |
+
| None (0.0) | FAST | UNSTABLE | COLLAPSED |
|
| 165 |
+
| 0.9 | SLOW | STABLE | HEALTHY but slow learning |
|
| 166 |
+
|
| 167 |
+
---
|
| 168 |
+
|
| 169 |
+
### 4. Memory vs Performance Trade-off
|
| 170 |
+
|
| 171 |
+
| Optimizer | Optimizer State | Performance | Trade-off |
|
| 172 |
+
|-----------|----------------|-------------|-----------|
|
| 173 |
+
| AdamW | 51.68 MB | β
Best (val loss 1.69-1.92) | More memory |
|
| 174 |
+
| Canonical Adafactor | 0.16 MB | β οΈ Gap (val loss 4.82) | 316x less memory |
|
| 175 |
+
|
| 176 |
+
**Use case dependent:** AdamW for quality, Adafactor for memory-constrained scenarios.
|
| 177 |
+
|
| 178 |
+
---
|
| 179 |
+
|
| 180 |
+
## Checkpoints Included
|
| 181 |
+
|
| 182 |
+
### Working Models (Upload as evidence)
|
| 183 |
+
|
| 184 |
+
| File | Type | Val Loss | Status | Description |
|
| 185 |
+
|------|------|----------|--------|-------------|
|
| 186 |
+
| `checkpoint-fp32-adamw-working.pt` | FP32 | **1.69** | β
WORKING | AdamW baseline, coherent generation |
|
| 187 |
+
| `checkpoint-bitlinear-adamw-working.pt` | BitLinear | **1.92** | β
WORKING | Ternary quantization, coherent generation |
|
| 188 |
+
|
| 189 |
+
---
|
| 190 |
+
|
| 191 |
+
### Experimental/Failed Models (Already uploaded)
|
| 192 |
+
|
| 193 |
+
| File | Type | Val Loss | Status | Description |
|
| 194 |
+
|------|------|----------|--------|-------------|
|
| 195 |
+
| `checkpoint-step5000-experiment.pt` | BitLinear | 8.45 | β
Pipeline verified | First test, proved architecture works |
|
| 196 |
+
| `checkpoint-step50000-failed-collapsed.pt` | BitLinear | 3.16 | β COLLAPSED | Beta1=None, repetitive output |
|
| 197 |
+
| `checkpoint-step50000-experiment-gibberish.pt` | BitLinear | 7.56 | β οΈ Not useful | Beta1=0.9, healthy but slow learning |
|
| 198 |
|
| 199 |
---
|
| 200 |
|
| 201 |
## Training Configuration
|
| 202 |
|
| 203 |
+
### Working Models Configuration
|
| 204 |
+
|
| 205 |
+
| Setting | FP32 + AdamW | BitLinear + AdamW |
|
| 206 |
+
|---------|--------------|-------------------|
|
| 207 |
+
| Dataset | TinyStories | TinyStories |
|
| 208 |
+
| Steps | 5,000 | 9,500 |
|
| 209 |
+
| Batch size | 4 | 4 |
|
| 210 |
+
| Gradient accumulation | 8 | 8 |
|
| 211 |
+
| Effective batch size | 32 | 32 |
|
| 212 |
+
| Optimizer | AdamW | AdamW |
|
| 213 |
+
| Max Learning Rate | 0.001 | 0.001 |
|
| 214 |
+
| Min Learning Rate | 0.0001 | 0.0001 |
|
| 215 |
+
| Warmup steps | 100 | 100 |
|
| 216 |
+
| Weight decay | 0.01 | 0.01 |
|
| 217 |
+
| Gradient clipping | 1.0 | 1.0 |
|
| 218 |
+
|
| 219 |
+
---
|
| 220 |
+
|
| 221 |
+
### Failed Experiments Configuration
|
| 222 |
+
|
| 223 |
| Setting | Value |
|
| 224 |
|---------|-------|
|
| 225 |
+
| Dataset | TinyStories |
|
| 226 |
| Samples | 50,000 |
|
| 227 |
| Batch size | 4 |
|
| 228 |
| Gradient accumulation | 8 |
|
| 229 |
| Effective batch size | 32 |
|
| 230 |
+
| Optimizer | Adafactor (buggy) |
|
| 231 |
| Max Learning Rate | 0.0003 |
|
| 232 |
| Min Learning Rate | 0.00003 |
|
| 233 |
| Warmup steps | 1,000 |
|
|
|
|
| 236 |
|
| 237 |
---
|
| 238 |
|
| 239 |
+
## Total Time Invested
|
| 240 |
|
| 241 |
+
| Phase | Duration | Outcome |
|
| 242 |
+
|-------|----------|---------|
|
| 243 |
+
| Initial experiments (August) | 167 hours | Identified beta1 issues |
|
| 244 |
+
| Root cause investigation (September) | 5 days | Found Adafactor bug |
|
| 245 |
+
| Working models (August-September) | 15+ hours | β
Both models working |
|
| 246 |
+
| Canonical Adafactor (October) | 1 day | Implementation verified, performance gap observed |
|
| 247 |
|
| 248 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
+
## Lessons Learned
|
| 251 |
|
| 252 |
+
### Technical Lessons
|
| 253 |
|
| 254 |
+
1. **Optimizer implementation bugs are subtle** - Adafactor computed variance but didn't apply it
|
| 255 |
+
2. **Always verify against reference implementations** - PyTorch Adafactor differs from custom implementation
|
| 256 |
+
3. **AdamW is robust for ternary quantization** - Proven to work where Adafactor failed
|
| 257 |
+
4. **Memory vs performance trade-offs exist** - 316x memory savings vs 2x performance gap
|
| 258 |
+
5. **Lower loss β better model** - Collapsed model had lower loss (3.16 vs 7.56) due to repetitive output
|
| 259 |
|
| 260 |
+
### Research Lessons
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
+
1. **Entropy monitoring is CRITICAL** - Loss alone doesn't indicate model health
|
| 263 |
+
2. **Systematic investigation pays off** - Line-by-line code audit found the bug
|
| 264 |
+
3. **Document everything** - 59 phases of investigation documented
|
| 265 |
+
4. **Test one variable at a time** - Controlled experiments essential for debugging
|
| 266 |
|
| 267 |
---
|
| 268 |
|
| 269 |
+
## How to Use Working Models
|
| 270 |
|
| 271 |
+
### FP32 + AdamW Baseline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
+
```python
|
| 274 |
+
import torch
|
| 275 |
+
from src.model.gpt import GPT
|
| 276 |
+
from src.tokenizer.bpe_tokenizer import BPETokenizer
|
| 277 |
|
| 278 |
+
# Load model architecture (FP32)
|
| 279 |
+
model = GPT(
|
| 280 |
+
vocab_size=4000,
|
| 281 |
+
d_model=256,
|
| 282 |
+
n_heads=8,
|
| 283 |
+
n_layers=6,
|
| 284 |
+
d_ff=1024,
|
| 285 |
+
max_seq_len=256
|
| 286 |
+
)
|
| 287 |
|
| 288 |
+
# Load checkpoint
|
| 289 |
+
checkpoint = torch.load('checkpoint-fp32-adamw-working.pt', map_location='cpu')
|
| 290 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 291 |
+
model.eval()
|
|
|
|
|
|
|
| 292 |
|
| 293 |
+
# Load tokenizer
|
| 294 |
+
tokenizer = BPETokenizer.load('tokenizer.json')
|
| 295 |
|
| 296 |
+
# Generate text
|
| 297 |
+
input_ids = torch.tensor([tokenizer.encode("Once upon a time")])
|
| 298 |
+
# ... generation code ...
|
| 299 |
+
```
|
| 300 |
|
| 301 |
+
---
|
| 302 |
+
|
| 303 |
+
### BitLinear + AdamW (Ternary)
|
| 304 |
|
| 305 |
```python
|
| 306 |
import torch
|
| 307 |
from src.model.bitlinear import BitLinearGPT
|
| 308 |
from src.tokenizer.bpe_tokenizer import BPETokenizer
|
| 309 |
|
| 310 |
+
# Load model architecture (BitLinear)
|
| 311 |
model = BitLinearGPT(
|
| 312 |
vocab_size=4000,
|
| 313 |
d_model=256,
|
|
|
|
| 317 |
max_seq_len=256
|
| 318 |
)
|
| 319 |
|
| 320 |
+
# Load checkpoint
|
| 321 |
+
checkpoint = torch.load('checkpoint-bitlinear-adamw-working.pt', map_location='cpu')
|
| 322 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 323 |
model.eval()
|
| 324 |
|
| 325 |
# Load tokenizer
|
|
|
|
| 330 |
# ... generation code ...
|
| 331 |
```
|
| 332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
---
|
| 334 |
|
| 335 |
## Tokenizers
|
| 336 |
|
| 337 |
| File | Description |
|
| 338 |
|------|-------------|
|
| 339 |
+
| `tokenizer-5k-experiment.json` | Tokenizer for early experiments |
|
| 340 |
+
| `tokenizer-50k-experiments.json` | Tokenizer for 50k step experiments |
|
| 341 |
|
| 342 |
---
|
| 343 |
|
|
|
|
| 349 |
|
| 350 |
Includes:
|
| 351 |
- Complete training scripts
|
| 352 |
+
- Model architecture (FP32 and BitLinear)
|
| 353 |
+
- Optimizer implementations
|
| 354 |
- Training history documentation
|
| 355 |
- Monitoring tools
|
| 356 |
+
- 59 phases of investigation documented
|
| 357 |
|
| 358 |
---
|
| 359 |
|
| 360 |
+
## Documentation
|
| 361 |
+
|
| 362 |
+
Complete investigation documentation:
|
| 363 |
|
| 364 |
+
**https://github.com/kishxrx/ARTN/blob/main/experiments/results/ROOT_CAUSE_INVESTIGATION_SUMMARY.md**
|
| 365 |
|
| 366 |
+
Covers:
|
| 367 |
+
- Phases 1-59 of systematic debugging
|
| 368 |
+
- Root cause analysis
|
| 369 |
+
- Verification experiments
|
| 370 |
+
- Evidence chain
|
| 371 |
|
| 372 |
---
|
| 373 |
|
| 374 |
## Next Steps
|
| 375 |
|
| 376 |
+
| Phase | Status | Plan |
|
| 377 |
+
|-------|--------|------|
|
| 378 |
+
| 1 | β
COMPLETE | FP32 baseline established (val loss 1.69) |
|
| 379 |
+
| 2 | β
COMPLETE | BitLinear + AdamW working (val loss 1.92) |
|
| 380 |
+
| 3 | β
COMPLETE | Root cause identified (Adafactor bug) |
|
| 381 |
+
| 4 | β
COMPLETE | Canonical Adafactor implemented and tested |
|
| 382 |
+
| 5 | π IN PROGRESS | Scale training with AdamW (longer runs) |
|
| 383 |
+
| 6 | π PLANNED | Evaluate on larger datasets |
|
| 384 |
+
| 7 | π PLANNED | Release v1.0 with working models |
|
| 385 |
|
| 386 |
---
|
| 387 |
|
|
|
|
| 395 |
title = {ARTN: Adaptive Ternary Recurrent Network - 1.58-bit Quantization Experiments},
|
| 396 |
year = {2026},
|
| 397 |
publisher = {HuggingFace},
|
| 398 |
+
url = {https://huggingface.co/kishxrx/ARTN}
|
| 399 |
}
|
| 400 |
```
|
| 401 |
|
|
|
|
| 411 |
|
| 412 |
**THIS IS EXPERIMENTAL SOFTWARE.**
|
| 413 |
|
| 414 |
+
- Working models produce coherent text but are experimental
|
| 415 |
+
- Failed models are for learning purposes only
|
| 416 |
+
- Not suitable for production use without further testing
|
| 417 |
- No guarantees of any kind
|
| 418 |
|
| 419 |
---
|
|
|
|
| 425 |
|
| 426 |
---
|
| 427 |
|
| 428 |
+
**Last Updated:** October 15, 2026
|
| 429 |
|
| 430 |
+
**Version:** v0.2-research-progress
|