Docs
Module-based project documentation rendered inside the site from mirrored English and Chinese Markdown chapters.
This docs section is a system map for the repository rather than a beginner tutorial.
Each chapter is written from the code outward:
- ownership boundaries between modules
- the concrete control flow through functions and classes
- the tensors or records that move across those boundaries
- the current implementation limits that matter when you run or extend the code
The chapters are grouped into three layers:
- the core stack that turns text into a decoder-only model
- the scale-and-performance layer that covers kernels, distributed execution, and preprocessing
- the alignment workflows that fine-tune and evaluate a math model on gsm8k
Two reading paths work well:
- start with
Project Overviewif you want the whole repository topology first - start with
Tokenizer and Vocabularyif you want to follow the actual data path from raw text to training batches
Use the overview cards below to jump directly to the subsystem you want to inspect.
Core Stack
The baseline path from raw text to a trainable decoder-only model.
Project Overview
A system map of the repository, from tokenizer and transformer internals to kernels, distributed training, and alignment workflows.
Tokenizer and Vocabulary
How the repository trains and applies a byte-pair tokenizer, from regex pre-tokenization to merge learning and byte-level encode/decode.
Transformer Core
Decoder-only transformer internals implemented in llm/transformer.py, including RMSNorm, RoPE, SwiGLU, custom attention, and custom loss.
Training Loop and Checkpointing
How llm/training.py slices data, initializes distributed execution, runs validation, applies schedules, and saves checkpoints.
Scale & Performance
The layers that make larger runs practical: kernels, distributed execution, and data preparation.
Flash Attention and Kernel Optimization
How the Triton Flash Attention path in kernel/ reduces attention memory pressure and how it is validated against a reference implementation.
Distributed Training and Sharded Optimizer
How parallel/ddp.py and parallel/sharded_optimizer.py synchronize gradients, bucket communication, and reduce optimizer-state memory.
Data Processing Pipeline
The preprocessing stack in data_processing/, from HTML extraction and language filtering to deduplication, PII masking, harmful-content checks, and quality classification.
Alignment Workflows
Concrete SFT and RLFT implementations built around gsm8k and Qwen2.5-Math-1.5B.
Supervised Fine-Tuning on gsm8k
How alignment/sft.py turns gsm8k examples into prompt-completion training data and measures accuracy plus format compliance.
Reinforcement Learning Fine-Tuning on gsm8k
How the repo implements reward shaping, grouped normalization, GRPO-style clipping, and multi-GPU role separation for RLFT.