Repository navigation
Optimized GPT-style Language Model Engine — Initial Setup → main - #1
Merged
Merged
Conversation
- Add 7-module architecture scaffolding (tokenizer, dataset, model, attention, training, inference, optimization, benchmark) - Implement byte-level BPE tokenizer with train/encode/decode/save/load + tests - Add centralized config-driven setup via configs/default.yaml - Add TDD docs, build-order plan, and consolidated markdown docs in docs/ - Add free-tier CI (ruff lint + format, mypy typecheck, pytest matrix, import smoke) - Add .gitignore for caches, checkpoints, data, secrets, and scratch files Co-authored-by: aadityasinha <555aaditya@proton.me>
… holds in training
…pport early stopping
…y scaling and quantization cost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimized GPT-style Language Model Engine — Initial Setup → main
Summary
This PR promotes the
Initial-Setupbranch intomain. It delivers a complete,from-scratch decoder-only transformer language model engine built in PyTorch —
no pretrained weights, no HuggingFace. Every core component (BPE tokenizer, data
engine, GQA + RoPE attention with three interchangeable kernels, training loop,
inference/serving, optimization, and benchmarking) is hand-written and covered by a
test-driven suite.
Scale of change: 72 files, ~11,780 insertions across 41 commits.
Highlights
Hand-written stack (the only thing borrowed from PyTorch is tensor math)
tokenizer/— byte-level BPE (GPT-2 style rendered-unicode keys) withtraining, greedy encode/decode, special tokens, serialization, and
pre-tokenization that speeds up BPE encode from ~2.9 KB/s to ~67 MB/s.
dataset/— memory-mapped (uint16mmap) streaming corpora, windowing,sharding, content-hashed train/val splits, corpus download, and email/chat
message document preparation with cleaning & redaction.
attention/— grouped-query attention (8 query heads → 2 KV heads, 4xsmaller KV cache), RoPE, KV cache, and three interchangeable kernels:
manual— readable reference / double-precision oraclesdpa— torch fused F.scaled_dot_product_attentionflash— a hand-written tiled online-softmax kernel with a recomputingbackward (O(T) memory in training)
training/— hand-written AdamW, cosine LR + warmup, gradientclipping, AMP (bf16 on MPS), gradient accumulation, checkpointing, best-model
tracking, early stopping, and held-out validation loss / perplexity.
inference/— temperature / top-k / top-p sampling, KV cache pagedgeneration, and batched generation with left padding that correctly handles
ragged rows (masked keys match single-stream decoding).
optimization/— INT8/INT4 quantization and a KV-cache memory pool.benchmark/— latency (p50/p90/p95/p99), throughput, memory, and evidenceharness, plus a
showcaseCLI printing architecture, memory, latency, and livecompletions.
System & Engineering
configs/default.yaml,configs/tinyshakespeare.yaml).mps → cuda → cpufor Apple Silicon.rufflint + format,mypytypecheck,pytest(3.x matrix +coverage), and import-smoke jobs.
docs/(TDD, build order) and the global vault.Architecture
tokenizer/dataset/model/CausalLMattention/training/inference/optimization/benchmark/Why this architecture (engineering rationale)
stat()alone; no bulkcopy into RAM even with multiprocessing workers.
contexts and shrinks the KV cache (2048 KiB → 512 KiB per layer at 512 tokens)
and attention parameters by 37.5%.
at O(T) instead of O(T²), removing the long-context scalability wall.
serving with measurable, gated performance (per TDR-012 benchmarking baselines).
Test status
attention, inference, optimizer, trainer, quantization, KV pool, and benchmarks.
end to end.
rufflint + format,mypytypecheck,pyteston 3.x matrix, andimport smoke — all must pass before merge.
Docs & vault
docs/TDD.md— full technical design document (v1.1+)docs/TDD_PROMPT.md— original TDD promptdocs/BUILD_ORDER.md— dependency-aware build plan & module contracts~/vault/).Notes for reviewers
mainis locked; this PR is the single entry point for the whole feature set..gitignorekeeps caches, checkpoints, datasets,secrets, and scratch files out of version control.
arxiv.txtcorpus dump(regenerable via the dataset pipeline).