Repository navigation
Tiny Transformer
Sudhanshu edited this page Nov 11, 2026
·
1 revision
This PyTorch-only educational model demonstrates next-token training without a pretrained-model download. It is intentionally not a large language model.
flowchart TD
Text["UTF-8 text"] --> Bytes["Byte token IDs: bytes + 2, EOS=1, PAD=0"]
Bytes --> Emb["Token embedding: vocab 258, width 64"]
Pos["Learned positions up to seq_len"] --> Sum["Sum embeddings"]
Emb --> Sum
Sum --> Layer["1 TransformerEncoderLayer: 4 attention heads; FFN width 128"]
Mask["Upper-triangular causal attention mask"] --> Layer
Layer --> LN["LayerNorm"] --> Head["LM head: 64 to 258 logits"]
Head --> CE["Shifted next-token cross entropy"]
Labels["Labels: pad positions ignored (-100)"] --> CE
- Vocabulary size: 258 (
PAD=0,EOS=1, bytes mapped to2..257). - Model width: 64; 4 attention heads; 1 Transformer encoder layer with a feed-forward dimension of 128.
- Learned positional embeddings; upper-triangular causal attention mask.
- LayerNorm and Linear head mapping hidden width
64 → 258logits. - Forward returns loss, not generated text. No text-generation loop or sampling API is implemented.
AdamW defaults to 3e-4 unless overridden. Training clips gradients to maximum norm 1.0. The single-process CPU smoke-test command is:
python llm_ddp_parallel_training.py --model tiny --cpu --max-steps 2The tiny checkpoint includes model_state_dict, seq_len, width, and heads; this project does not provide a standalone loader/inference CLI for it.
Distributed LLM Training · PyTorch DDP (educational) — Home · System-Architecture · Low-Level-Design · Publishing-the-Wiki
This project is licensed under the Apache License, Version 2.0.© 2026 Sudhanshu Shukla · Licensed under the Apache License, Version 2.0.