AI Engineering Lab Standard

Every lab in this track builds a runnable, test-verified miniature of a real AI mechanism — the attention block, the autograd tape, the LoRA delta, the DPO loss, the PagedAttention block table, the all-reduce ring, the ANN index, the ReAct loop — so the internals become muscle memory instead of framework folklore. You do not "call model.generate()"; you build the sampler that turns logits into the next token. That is what makes the knowledge defensible in a senior interview and useful at 2 a.m. when generation is wrong, slow, or unsafe.

Why miniatures (and not a 70B model on a GPU cluster)

A real training/serving stack is non-deterministic, costs thousands of dollars, needs GPUs and credentials, and hides the mechanism behind CUDA kernels and a framework API. A lab that reimplements the algorithm — the softmax-with-max-subtraction, the reverse-mode chain rule, the NF4 quantization grid, the Bradley-Terry gradient, the KV-block allocator, the ring-reduce schedule, the HNSW greedy descent — is offline, deterministic, free, and teaches the part interviewers actually probe. Each lab README ends with a "How this maps to the real stack" section that ties the miniature back to PyTorch / vLLM / DeepSpeed / FAISS / LangChain, its limits, and the real API equivalent.

Required files (per lab)

FileContract
README.mdthe problem, what you build, key concepts table, file map, run commands, success criteria, "How this maps to the real stack", extensions, interview/resume bullets
lab.pylearner implementation with focused # TODO markers and signatures/docstrings already in place; never a blank file
solution.pycomplete reference; python solution.py runs a worked example and prints output; deterministic
test_lab.pypositive, negative, boundary, and determinism tests; runnable against either module via LAB_MODULE
requirements.txtusually pytest only — labs are pure stdlib otherwise

The runnable core is Python (stdlib + pytest), offline, deterministic. No GPU, no CUDA, no network, no model download, no pip install torch, no Date.now()/unseeded random. Where a lab needs vectors or matrices, implement them with stdlib lists/array/math so the mechanism is visible — NumPy is allowed only if a lab explicitly declares it in its requirements.txt, and even then the algorithm (not a one-line library call) must be the thing the learner writes. Multi-language work (the C++/CUDA kernel, the real torch/vllm run) appears only as build specs in the README "Extensions" section for the learner's own hardware.

Determinism rules (these labs touch probability — be careful)

  • Any randomness goes through an explicit, seeded random.Random(seed) passed in or defaulted; same seed → same bytes. Tests assert this.
  • Floating-point comparisons in tests use pytest.approx (or an explicit abs-tolerance), never == on floats.
  • softmax, log-sum-exp, and any loss must use the max-subtraction / log-space trick so the tests can include large-logit inputs without overflow — that numerical-stability detail is part of the lesson.

The test contract

import importlib, os
lab = importlib.import_module(os.environ.get("LAB_MODULE", "lab"))

Run both ways; the reference must pass, and your lab.py passes once the TODOs are filled:

pytest test_lab.py -v                       # against your lab.py (red until you implement)
LAB_MODULE=solution pytest test_lab.py -v   # against the reference (must be green)
python solution.py                          # the worked example

Test taxonomy every flagship lab includes: happy path; malformed / out-of-range input (raises ValueError); boundary cases — the off-by-one interviewers probe (empty sequence, single token, top_k=1 ⇒ greedy, temperature→0, LoRA r=0, a full KV-block, an empty retrieval set, a degenerate preference pair); numerical-stability cases (large logits don't overflow, log(0) is guarded); invariants (softmax sums to 1, probabilities are non-negative, a merged-LoRA forward equals base+delta, dequant∘quant is within the error bound, all-reduce result equals the serial sum); and deterministic output (same seed → same bytes).

The four teaching docs (per phase)

Every phase explains the same material through four lenses, because senior-level understanding is their intersection:

DocumentVoiceWhat it gives you
README.mdthe syllabuswhy the phase exists, concept map, lab spec table, integrated-scenario ideas, deliverables checklist, key takeaways
WARMUP.mdthe professorzero-to-senior primer: every term from first principles → what it is → why it exists → how it works under the hood (mechanism, diagrams, small code/math) → production significance → common misconceptions; then a Lab Walkthrough, Success Criteria, Interview Q&A, and References (primary sources: papers, the PyTorch/vLLM/HF docs, talks)
HITCHHIKERS-GUIDE.mdthe senior who's been therecompressed practitioner tour: 30-second mental model, the numbers to tattoo on your arm, the framework one-liners, war stories, vocabulary, beginner mistakes
BROTHER-TALK.mdyour brother, off the recordcandid real-talk: what nobody tells you, the 2 a.m. pager truth, what's worth caring about, the career framing

Doc conventions (mdBook-compatible)

  • WARMUP.md opens with a Table of Contents of working anchor links, kept in sync with the headings.
  • MathJax for any math (\( … \) inline, $$ … $$ block). Standard Markdown only.
  • No bare angle brackets in prose — wrap <like-this> in backticks so mdBook does not eat them as HTML. (This bites constantly in this domain: <bos>, <image>, <|endoftext|>, generic types — always fence them.)
  • File references use relative links. Code fences are language-tagged.

Definition of done

A lab is complete only when: the reference suite passes (LAB_MODULE=solution pytest), the learner lab.py passes after the TODOs are filled in, python solution.py prints a sensible worked example, the README's success criteria are testable, and the "How this maps to the real stack" section is accurate about the production framework and its limits. A phase is complete when all four teaching docs exist, the WARMUP's ToC anchors resolve, and every lab in it is done.