AIToday

30M-param LLM trained from scratch reveals scaling assumptions were wrong

Hacker News4h ago
30M-param LLM trained from scratch reveals scaling assumptions were wrong

Key takeaway

A researcher trained a 30 million-parameter language model from scratch on a single free Kaggle GPU, discovering that the supposed scaling "floor" limiting small models is actually compute-constrained rather than a hard architectural limit. The scaling study fitted the results to a power law and showed that models specialized for their training distribution outperform larger, more general models on the same task—challenging conventional assumptions about how small models must be and what training resources they require.

Summaries like this, in your inbox every morning.

Sign up free →

3 Key Points

  • What happened

    A researcher built a ~30M-parameter transformer language model from scratch using PyTorch on Kaggle's free T4 GPU, trained on the TinyStories dataset. The model achieved a validation loss of 1.401 and produces coherent short stories. The project included ablation studies comparing RMSNorm vs LayerNorm (quality tie; LayerNorm ~33% faster), warmup-length effects (negligible), and a scaling study fit to a power law: L ≈ 1.16 + 0.78·N^−0.276 (R² 0.9975).

  • Why it matters

    The scaling study found that the widely-assumed model-size "floor" limiting small models was a mirage—the real constraint at 80k training steps was compute, not data or model architecture. On-distribution specialization (tuned specifically for TinyStories) outperformed raw scale in evaluation. These findings challenge conventional wisdom about minimum viable model sizes and training budgets for language models.

  • What to watch

    The technical blog post (linked in the project) documents the full findings, including attention-head interpretability (previous-token and attention-sink heads identified), training-trick ablations, and a custom TinyStories rubric evaluated by Llama-3.3-70B. All code, configs, and tokenizers are reproducible via the GitHub repo.

In Depth

The researcher built a decoder-only transformer from the ground up to understand how language models work by implementing and testing each piece by hand. The model architecture is standard—embeddings, multi-head causal self-attention with heads vectorized into a single batched matrix multiplication, and position-wise feed-forward networks with GeLU activation and d_ff = 4 × hidden_size—but every component is written in raw PyTorch tensor operations. The baseline configuration (configs/small.yaml) uses a hidden size of 512, 8 layers, 8 attention heads, a vocabulary of 8,000 tokens, and a sequence length of 256, yielding 33.6 million parameters. Training ran for 80,000 steps on the TinyStories dataset using AdamW with a linear warmup of 2,000 steps followed by cosine decay to 10% of peak learning rate, achieving a throughput of ~42,000 tokens per second with mixed-precision (fp16) training and batch size 32 on a single free Kaggle T4 GPU over approximately 4.5 hours.

A series of controlled ablation studies isolated the effect of specific design choices. The normalization ablation compared hand-written RMSNorm (which divides each token vector by its root-mean-square and applies a learned scale) against LayerNorm (which adds mean-subtraction and a shift parameter). Both 22k-step training runs produced quality ties (equivalent validation loss), but LayerNorm was ~33% faster due to the unfused RMSNorm implementation. The warmup-length ablation tested 50, 500, and 2,000 warmup steps and found negligible differences; even a stress variant with 10× learning rate and no gradient clipping did not diverge, confirming that AdamW dampens the importance of warmup at this scale. The learning-rate sweep (3e-4, 1e-3, 3e-3) identified 1e-3 as optimal, cutting validation loss by 0.042 compared to the original 3e-4 baseline, suggesting that peak learning rate is the real training lever.

The scaling study fit five models across a ladder from 1.8M to 56.6M non-embedding parameters to a power law L ≈ 1.16 + 0.78·N^−0.276 with R² 0.9975. A diagnostic run at 80k steps showed the floor was compute-limited rather than a data ceiling—contradicting the conventional assumption that small models hit an immovable architectural limit. The sample output from the prompt "Once upon a time" generated: "Once upon a time, there was a little girl named Lily. She loved to play in the garden with her toys. One day, she found a shiny rock and she wanted to keep it safe. She put it in her pocket and went to play with her toys. … She remembered the shiny rock in her pocket and thought it might make a magic wand." The model produces fluent, coherent TinyStories-style narratives with consistent characters and clear arcs, with only residual small-model artifacts (occasional repetition or mild logic drift) at this scale.

Evaluation used a custom TinyStories rubric with Llama-3.3-70B as an LLM judge, and comparison against GPT-2. A key finding was that specialization beats scale on the target distribution—the 30M model tuned for TinyStories outperformed larger, more general models when evaluated on that specific task. Interpretability analysis identified previous-token and attention-sink heads at both model sizes, with induction heads only weakly emerging. The project is fully reproducible: all code, versioned configs, shape and gradient-flow tests, and instructions for running on Kaggle are published in the GitHub repository, and the tokenized dataset is available as a private Kaggle Dataset so that the full 80k-step training can be repeated on free GPU.

Context & Analysis

The project stands out as a deliberate, hands-on deep-dive into transformer mechanics rather than a benchmark chase. By implementing every component—embeddings, multi-head causal self-attention, feed-forward networks, and the training loop—directly on PyTorch tensor operations (no high-level model libraries), the researcher gained direct visibility into which design choices actually matter at scale. The ablations were carefully scoped: RMSNorm vs LayerNorm produced a quality tie (LayerNorm ~33% faster due to unfused RMSNorm), warmup length proved negligible (AdamW makes it redundant), and learning rate was identified as the primary lever (1e-3 cutting validation loss by 0.042 vs the original 3e-4).

The most significant claim is the reinterpretation of the scaling "floor." Standard wisdom suggests small models plateau quickly and that scaling is the only path forward. The power-law fit (R² 0.9975) and the 80k diagnostic instead suggest the plateau observed at this compute budget is an artifact of insufficient training, not a model-size ceiling. When the researcher evaluated the model on its native distribution (TinyStories rubric via Llama-3.3-70B as judge), specialization to that distribution outperformed scale—a practical finding that smaller, domain-tuned models can be more useful than larger general ones when the task is well-defined.

The reproducibility constraints are deliberately tight: the code ships with versioned YAML configs, fixed random seeds, shape and gradient-flow tests in each module, and paths configured to run identically on Kaggle (where the model was trained) or locally. The tokenized dataset and tokenizer are published as a private Kaggle Dataset, so the full 80k-step training is repeatable on free GPU.

FAQ

How long did training take and on what hardware?
The ~30M-parameter baseline model trained for the full 80k-step schedule on a single free Kaggle T4 GPU in approximately 4.5 hours at ~42k tokens/sec throughput (using fp16 mixed-precision, batch 32).
What was the final validation loss and can you see example outputs?
The baseline achieved a validation loss of 1.401 (training loss 1.433) at max learning rate 1e-3. A sample output from the prompt "Once upon a time" generated: "Once upon a time, there was a little girl named Lily. She loved to play in the garden with her toys..." producing fluent, coherent TinyStories-style narratives with consistent characters and clear story arcs.
What was the key finding from the scaling study?
The scaling study (5-point width+depth ladder from 1.8M–56.6M non-embedding parameters) fit the results to the power law L ≈ 1.16 + 0.78·N^−0.276 (R² 0.9975) and showed that at 80k steps, the scaling floor was compute-limited rather than a data ceiling—contradicting assumptions that small models hit a hard architectural barrier.

Get the latest Large Language Models news every morning

AI-summarized, only the topics you pick — one digest a day via Email, Slack, or Discord.

Free · takes 30 seconds · unsubscribe anytime

Discussion

No comments yet. Be the first to share your thoughts!

Log in to join the discussion

Related Articles

Stay ahead with AI news

Get curated AI news from 200+ sources delivered daily to your inbox. Free to use.

Get Started Free

Free · takes 30 seconds · unsubscribe anytime

1 minute a day. The AI essentials.

200+ sources · Email / LINE / Slack

Get it free →