Causal attention on CPU
Numerical verification of scaled dot-product causal attention, shape invariants, and zero-leakage future masking on CPU.
Companion implementations · 12 reproducible CPU labs
12 self-contained CPU implementations and test suites paired with the writing. Every mechanism—from bounded Go admission gates to DeepSeek MLA matrix absorption—runs locally without GPUs or external API keys.
Deterministic CPU PyTorch proofs: RoPE, Online Softmax tiling, KV cache, MLA absorption & GRPO
Numerical verification of scaled dot-product causal attention, shape invariants, and zero-leakage future masking on CPU.
Block-causal masking, confidence-thresholded parallel unmasking, and KV-cached prefix reuse for discrete diffusion LLMs.
Low-rank KV latent compression, RoPE key decoupling, weight-matrix absorption, and critic-free GRPO advantage normalization.
Asymmetric compressed-encoder decoding (CED), depth-wise attention residuals (AttnRes), and 5-step Newton-Schulz Muon orthogonalization.
Incremental key-value state caching vs. full recomputation, verifying exact floating-point logit parity across decode steps.
Recurrent shared-weight depth iteration, terminal-loop constant KV cache, and adaptive compute halting criteria.
Complex-plane RoPE rotation invariance, SwiGLU gating dynamics, and RMSNorm gradient stability checks in pure PyTorch.
Online Softmax blockwise tiling and HBM/SRAM arithmetic-intensity roofline verification against naive quadratic attention.
Bounded admission control, graceful draining, and deterministic agent loops tested under -race
Deterministic tool-use state machine with bounded step budgets, structured error recovery, and context-driven cancellation.
Semaphore-bounded admission control, per-request timeout propagation, and graceful server draining tested under Go's race detector.
Structured TaskGroup cancellation and streaming TTFT/ITL latency measurement
Structured asyncio.TaskGroup fan-out, semaphore backpressure, and fail-fast cancellation across heterogeneous tool calls.
Time-to-first-token (TTFT) and inter-token latency (ITL) quantile telemetry over asynchronous server-sent event streams.
Twelve reproducible experiments accompany Engineering Reliable Model Systems and LLM & AI Infrastructure from First Principles. These are teaching implementations, not a deployable model-serving platform.
From the repository root (or extracted archive root):
python3 -m venv labs/.venv
labs/.venv/bin/python -m pip install -r labs/requirements.txtOr with uv:
uv run --with torch python -m unittest discover -s labs/llm/modern-transformer -p 'test_*.py' -vPython 3.11+ and Go 1.24+ are required. Only the LLM tensor labs require PyTorch. No model downloads or API keys are used. All tensor operations explicitly run on CPU.
(cd labs/go && go test -race ./...)
python3 -m unittest discover -s labs/python/concurrency -p 'test_*.py' -v
python3 -m unittest discover -s labs/python/streaming -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/attention -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/kv-cache -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/modern-transformer -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/roofline-flash -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/deepseek-mla-grpo -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/flagship-2026 -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/looped-transformer -p 'test_*.py' -v
labs/.venv/bin/python -m unittest discover -s labs/llm/block-diffusion -p 'test_*.py' -vpython3 labs/python/streaming/measure.py > labs/results/stream-fixture.json
labs/.venv/bin/python labs/llm/attention/attention.py
labs/.venv/bin/python labs/llm/kv-cache/benchmark.py --output labs/results/cache-results.json
labs/.venv/bin/python labs/llm/modern-transformer/modern_blocks.py
labs/.venv/bin/python labs/llm/roofline-flash/roofline_flash.py
labs/.venv/bin/python labs/llm/deepseek-mla-grpo/mla_grpo.py
labs/.venv/bin/python labs/llm/flagship-2026/flagship_blocks.py
labs/.venv/bin/python labs/llm/looped-transformer/looped_transformer.py
labs/.venv/bin/python labs/llm/block-diffusion/block_diffusion.pyThe stream report uses prescribed timestamps, not a measured model. Decoder timings are local CPU microbenchmarks over a random-weight, one-block model. Compare correctness first, then timings under the same environment. Do not extrapolate these records to GPU throughput, language quality, or production capacity.
go-review project's cmd/inference-lab/main.go. It isolates admission and draining instead of copying its HTTP gateway.pi-go project's internal/agent/loop.go and tests. That project is a Go rewrite of pi-mono. This lab is not wire compatible and is not a claim to the upstream design.The original project checkouts are not dependencies. No credentials, session history, personal progress records, or upstream project files are packaged in the download.