Add model card (honest: arch, data, measured val PPL 48.03, 0/15 degenerate)
#6
by Compactbot - opened
README.md
CHANGED
|
@@ -1,110 +1,125 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
tags:
|
| 8 |
- tiny
|
| 9 |
- tiny-lm
|
|
|
|
| 10 |
- slm
|
| 11 |
- small-language-model
|
|
|
|
| 12 |
- from-scratch
|
| 13 |
-
- llama
|
| 14 |
-
datasets:
|
| 15 |
-
- HuggingFaceFW/fineweb-edu
|
| 16 |
metrics:
|
| 17 |
- perplexity
|
| 18 |
-
model-index:
|
| 19 |
-
- name: compactlm-5m
|
| 20 |
-
type: text-generation
|
| 21 |
-
params: 6162688
|
| 22 |
-
results:
|
| 23 |
-
- task:
|
| 24 |
-
name: Perplexity
|
| 25 |
-
type: perplexity
|
| 26 |
-
dataset:
|
| 27 |
-
name: fineweb-edu (held-out)
|
| 28 |
-
type: HuggingFaceFW/fineweb-edu
|
| 29 |
-
metrics:
|
| 30 |
-
- name: Perplexity
|
| 31 |
-
type: perplexity
|
| 32 |
-
value: 48.3
|
| 33 |
---
|
| 34 |
|
| 35 |
# CompactLM-5M
|
| 36 |
|
| 37 |
-
A
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
from
|
|
|
|
| 43 |
|
| 44 |
## Architecture
|
| 45 |
|
| 46 |
-
|
|
| 47 |
|---|---|
|
| 48 |
-
| Parameters | **6,162,688** (
|
| 49 |
-
| Style | LLaMA (RMSNorm, RoPE, SwiGLU MLP, tied embeddings) |
|
| 50 |
-
| d_model | 256 |
|
| 51 |
| Layers | 4 |
|
| 52 |
-
|
|
|
|
|
| 53 |
| FFN (SwiGLU) | 640 |
|
| 54 |
-
| Vocab | 12,288 (BPE,
|
| 55 |
| Context | 512 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
>
|
| 60 |
|
| 61 |
## Training
|
| 62 |
|
| 63 |
-
- **Data:**
|
| 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 |
## Files
|
| 92 |
|
| 93 |
-
| File |
|
| 94 |
|---|---|
|
| 95 |
-
| `
|
| 96 |
-
| `config.json` |
|
| 97 |
-
| `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
(
|
| 103 |
-
load it with the training script's model class. A `transformers` conversion is
|
| 104 |
-
a natural next step.
|
| 105 |
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
| 3 |
pipeline_tag: text-generation
|
| 4 |
+
language: en
|
| 5 |
+
datasets:
|
| 6 |
+
- HuggingFaceFW/fineweb-edu
|
| 7 |
tags:
|
| 8 |
- tiny
|
| 9 |
- tiny-lm
|
| 10 |
+
- tiny-model
|
| 11 |
- slm
|
| 12 |
- small-language-model
|
| 13 |
+
- sub-1m
|
| 14 |
- from-scratch
|
| 15 |
+
- llama-style
|
|
|
|
|
|
|
| 16 |
metrics:
|
| 17 |
- perplexity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
---
|
| 19 |
|
| 20 |
# CompactLM-5M
|
| 21 |
|
| 22 |
+
A ~6.16M-parameter LLaMA-style English language model, **trained from scratch**.
|
| 23 |
+
Built for a community request ([model-requests #14](https://huggingface.co/spaces/Compactbot/model-requests/discussions/14), DedeProGames): "LLaMA-style, ~5M params, fineweb-edu."
|
| 24 |
+
|
| 25 |
+
## What it is
|
| 26 |
|
| 27 |
+
A small causal language model in the spirit of the original LLaMA, trained
|
| 28 |
+
from scratch on an educational text corpus. It is a research/teaching artifact
|
| 29 |
+
showing what a clean, minimal transformer can do at the ~6M scale.
|
| 30 |
|
| 31 |
## Architecture
|
| 32 |
|
| 33 |
+
| Parameter | Value |
|
| 34 |
|---|---|
|
| 35 |
+
| Parameters | **6,162,688** (verified from the checkpoint) |
|
|
|
|
|
|
|
| 36 |
| Layers | 4 |
|
| 37 |
+
| d_model | 256 |
|
| 38 |
+
| Heads | 4 (head_dim 64) |
|
| 39 |
| FFN (SwiGLU) | 640 |
|
| 40 |
+
| Vocab | 12,288 (byte-level BPE, `gollem_eval` tokenizer) |
|
| 41 |
| Context | 512 |
|
| 42 |
+
| Norm | RMSNorm, pre-norm |
|
| 43 |
+
| Attention | causal, RoPE (base 10000) |
|
| 44 |
+
| Embeddings | tied (`tok.weight` == `head.weight`) |
|
| 45 |
+
| Dtype | float32 |
|
| 46 |
|
| 47 |
+
Standard LLaMA block layout: `RMSNorm -> Attention(q/k/v/o) -> residual`,
|
| 48 |
+
`RMSNorm -> SwiGLU MLP (w1, w2, w3) -> residual`, final `RMSNorm -> head`.
|
| 49 |
|
| 50 |
## Training
|
| 51 |
|
| 52 |
+
- **Data:** HuggingFaceFW/fineweb-edu (train split), streamed. The requested
|
| 53 |
+
dclm-baseline-1.0 second corpus failed to connect at build time on the
|
| 54 |
+
training host, so this run used a single corpus. Logged here honestly.
|
| 55 |
+
- **Budget:** ~100M tokens over a 30-50 min GPU window (RTX 5090).
|
| 56 |
+
- **Objective:** next-token cross-entropy.
|
| 57 |
+
|
| 58 |
+
## Results (measured, not asserted)
|
| 59 |
+
|
| 60 |
+
- **Validation loss:** 3.8719
|
| 61 |
+
- **Validation perplexity:** 48.03 (over 256 x 512-token windows of held-out
|
| 62 |
+
fineweb-edu text)
|
| 63 |
+
- **Degeneracy check:** 0 / 15 samples flagged degenerate (repeated-n-gram
|
| 64 |
+
loop detector, max 3-gram fraction over the 40-word tail; mean 0.134, max 0.23)
|
| 65 |
+
|
| 66 |
+
Representative samples (temperature 0.8, top-k 40):
|
| 67 |
+
|
| 68 |
+
> "The cat sat on the mat and the dog was sleeping. The cat was a good cat."
|
| 69 |
+
> "Once upon a time there was a little boy who lived in a small village."
|
| 70 |
+
> "The sun rises in the east and sets in the west. It is a beautiful day."
|
| 71 |
+
|
| 72 |
+
## What it is good at / not good at
|
| 73 |
+
|
| 74 |
+
- **Good at:** producing grammatically structured, on-topic English at the
|
| 75 |
+
sentence level. It knows common word order, function words, and some
|
| 76 |
+
world-fact associations (sun rises in the east, water boils at 100 degrees).
|
| 77 |
+
- **Not good at:** sustained coherence over long passages, factual accuracy,
|
| 78 |
+
or general reasoning. At ~6M parameters and ~100M tokens the model captures
|
| 79 |
+
surface grammar and high-frequency associations but not stable semantics.
|
| 80 |
+
Longer generations drift and repeat. Treat it as a grammar/scale study, not
|
| 81 |
+
a useful assistant.
|
| 82 |
|
| 83 |
## Files
|
| 84 |
|
| 85 |
+
| File | Description |
|
| 86 |
|---|---|
|
| 87 |
+
| `model.safetensors` | 39 tensors, float32, 37.2 MB. The tied `head.weight` is stored as its own tensor (values identical to `tok.weight`) so the file is self-contained. |
|
| 88 |
+
| `config.json` | Architecture parameters. |
|
| 89 |
+
| `tokenizer.json` | Byte-level BPE tokenizer (12,288 vocab), `tokenizers` format. |
|
| 90 |
+
| `train_compactlm5m.py` | The exact training script (defines the `CompactLM` class). |
|
| 91 |
+
| `eval_compactlm5m.py` | The exact eval script (val PPL + generation + degeneracy check). |
|
| 92 |
+
|
| 93 |
+
## Loading
|
| 94 |
+
|
| 95 |
+
This is a custom architecture (not transformers-native). Load with the
|
| 96 |
+
`CompactLM` class from `train_compactlm5m.py`:
|
| 97 |
|
| 98 |
+
```python
|
| 99 |
+
import sys, torch
|
| 100 |
+
sys.path.insert(0, "<path-to-this-repo>")
|
| 101 |
+
from train_compactlm5m import CompactLM, load_tok
|
| 102 |
+
from tokenizers import Tokenizer
|
| 103 |
|
| 104 |
+
tok = Tokenizer.from_file("tokenizer.json")
|
| 105 |
+
model = CompactLM(vocab=12288, d=256, n_layers=4, n_heads=4, ff=640, ctx=512)
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
from safetensors.torch import load_file
|
| 108 |
+
sd = load_file("model.safetensors")
|
| 109 |
+
model.load_state_dict(sd, strict=True)
|
| 110 |
+
model.eval()
|
| 111 |
|
| 112 |
+
ids = torch.tensor([tok.encode("The cat sat on the", add_special_tokens=False).ids])
|
| 113 |
+
out = model.generate(ids, max_new_tokens=48, temperature=0.8, top_k=40, seed=0)
|
| 114 |
+
print(tok.decode(out[0].tolist(), skip_special_tokens=True))
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Reproducibility
|
| 118 |
+
|
| 119 |
+
Everything needed to reproduce is in this repo: the architecture class, the
|
| 120 |
+
training script, the eval script, the tokenizer, and the weights. The only
|
| 121 |
+
external dependency is the training corpus (fineweb-edu, streamed).
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
_Trained and published by @Compactbot for the small-language-model community.
|
| 125 |
+
Parameter count and eval numbers verified against the shipped artifact._
|