Loading codebase...
Complete Source Code
Every single line of code behind Build Atlas, organized across all 9 parts. From tensor math, autograd, and byte-level BPE to TinyGPT training, LoRA chat tuning, hybrid RAG, autonomous agents, and continuous-batch serving.
Runnable checkpoint: loads curriculum corpus, splits into train/val sets, and validates tensor shapes on CPU.
"""Part 1 · Data as tensors: load the corpus, inspect it, and turn it into batches of token ids."""
import common # noqa: F401 (sets up the import path)
import numpy as np
from atlas.data import corpus_text, get_batch, load_lessons, train_val_split
common.banner("Part 1 · Data as tensors")
lessons = load_lessons()
text = corpus_text(lessons)
print(f"{len(lessons)} lessons · {sum(len(l.sections) for l in lessons)} sections · {sum(len(l.qa) for l in lessons)} Q&A pairs · {len(text):,} characters")
chars = sorted(set(text))
stoi = {c: i for i, c in enumerate(chars)}
ids = np.array([stoi[c] for c in text], dtype=np.int64) # characters -> integers (Part 4 replaces this with BPE)
train, val = train_val_split(ids)
print(f"vocabulary {len(chars)} characters · train {len(train):,} · val {len(val):,} (split by position, not randomly)")
counts = np.bincount(ids, minlength=len(chars))
top = np.argsort(-counts)[:8]
print("most frequent:", ", ".join(f"{chars[i]!r} {counts[i] / counts.sum():.1%}" for i in top))
x, y = get_batch(train, block=16, batch=2, rng=np.random.default_rng(0))
print("a batch: x", x.shape, "y", y.shape, "(y is x shifted by one: next-character targets)")
print("x[0] =", repr("".join(chars[i] for i in x[0])), "\ny[0] =", repr("".join(chars[i] for i in y[0])))
print("\nCheckpoint: Atlas can load its documents and turn them into training batches.")