πŸ¦‰ Hedwig 97.6M β€” From-Scratch Offline Storyteller & Grammar Helper

Hedwig is a ChatGPT-style language model built 100% from scratch in pure PyTorch (no HF Trainer, no Lightning) β€” including its own BPE tokenizer, modern Transformer (RoPE + RMSNorm + SwiGLU + SDPA + bf16), Stage 2 SFT, Stage 3 Anchored DPO, and from-scratch 8-bit / packed 4-bit quantization.

Model Summary

  • Parameters: 97,581,824 (~97.6M knobs: 12 layers, 768 width, 12 heads, block_size = 256)
  • Tokenizer: Custom 8,192-piece BPE (tokenizer.json)
  • Pretraining corpus (614 MB, 159M tokens):
    • 366.7 MB TinyStories (roneneldan/TinyStories)
    • 262.1 MB FineWeb-Edu (karpathy/fineweb-edu-100b-shuffle, ODC-By)
    • 10 public-domain Project Gutenberg novels (pre-1929)
  • Post-training:
    • Stage 2 SFT: 30,930 mixed pairs (TinyStories-Instruct + 15,000 Apache-2.0 grammarly/coedit grammar/tone rewrites)
    • Stage 3 Anchored DPO: 22,236 πŸ‘ chosen vs πŸ‘Ž rejected pairs
  • Training hardware & cost: 1Γ— NVIDIA A40 (48 GB) on RunPod, 66 minutes, **$0.65 total**.

Measured Results

Checkpoint Precision File Size Val / Test Loss Notes
brain.pt bfloat16 195.6 MB 2.619 Stage 1 pretrain (20,000 steps, 8k vocab)
brain_chat.pt bfloat16 195.6 MB 1.336 Stage 2 SFT (1,500 steps)
brain_chat_int8.pt int8 98.2 MB 1.3577 From-scratch 8-bit quantization
brain_chat_int4.pt int4 55.2 MB 1.3693 From-scratch packed 4-bit quantization
brain_dpo.pt bfloat16 195.6 MB 1.235 Stage 3 DPO (96.7% peak / 95.0% saved win-rate)
brain_dpo_int8.pt int8 98.2 MB 1.4000 From-scratch 8-bit quantization
brain_dpo_int4.pt int4 55.2 MB 1.4118 From-scratch packed 4-bit quantization

Sample Output (54 tok/s offline on Apple M4)

Prompt: Write a story about a boy named Harry Potter.

Harry Potter was a humble boy who liked to play. One day, he decided to go out and play. He walked down the street, laughing and having so much fun. Suddenly, Harry saw something shiny in a store window...

Limitations

  • At 97.6M parameters, Hedwig is a lightweight educational & bedtime-storytelling model, not a general-purpose assistant.
  • Grammar mode handles short everyday edits, but can still truncate or miss tense changes on longer workplace messages.

Code & Offline Mac UI

Full pure-PyTorch training scripts, interactive Brain X-Ray UI (app.py), and learning logs live at https://github.com/ansarbuilds/hedwig.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Datasets used to train ansarbuilds/hedwig-97m

Space using ansarbuilds/hedwig-97m 1