hc-model-study · README · GitHub

Learning path

Foundation-model architectures studied for GPU and edge inference: where the tensors go, what each operation costs, and which optimizations matter. Nine modules in order, a step-by-step Transformer primer, ten build-it-yourself coding labs, an efficiency cookbook, and two hands-on tutorials.

9 modules, each with an interactive guide, a runnable .py and a README 10 coding labs with an automatic checker 2 hands-on tutorials: an LLM and an agent Runs on a CPU; torch>=2.1

Map

Arrows point from a prerequisite to the module that builds on it. Numbers give the recommended order; dashed boxes are the hands-on tutorials. Click a box to open its guide.

1Transformer 2ViT 5Mamba (SSM) 6MoE LLMs T1Build an LLM 3VLM 4Diffusion (DiT) 7BEV T2Build an agent 8VLA 9Robot FM start here T1: after module 1 + labs 01–03 T2: optional, suggested last

Recommended order: Transformer primer → full Transformer guide → labs 01–03 → T1 Build an LLM → modules 2–8, each followed by its lab (04–10) → 9 Robot FM → T2 Build an agent (optional; it needs only T1, so any time after it works too). Keep the efficiency cookbook (E) open throughout as a reference. Mamba and MoE need only the Transformer, so you can take them earlier; the numbered order interleaves vision and language so each module reuses something recent.

Main track

Each module has an interactive *_guide.html (open it in a browser), a runnable reference implementation with shape and FLOP printouts, and a README with the key bottlenecks.

  1. 1

    Transformer

    Attention from first principles, with the FLOP and memory accounting every later module reuses.

    Builds on: linear algebra, PyTorch basicsAdds: O(N²) attention, KV cache, FlashAttention, kernel fusion
  2. 2

    Vision Transformer

    Images as sequences of patches, encoded with bidirectional attention.

    Builds on: TransformerAdds: patch embedding, [CLS] token, image token counts vs. resolution
  3. 3

    Vision-Language Models

    A vision encoder and a projector feed image tokens into an LLM.

    Builds on: ViT, TransformerAdds: projector, image-token prefix, image-dominated prefill (TTFT)
  4. 4

    Diffusion (DiT)

    Generation by iterative denoising, with a transformer as the denoiser.

    Builds on: ViTAdds: timestep conditioning (adaLN-Zero), DDIM / flow matching, step reduction
  5. 5

    Mamba (SSM)

    A selective linear recurrence: parallel scan for training, constant-size state for decoding.

    Builds on: TransformerAdds: selective scan, dual-mode compute, no KV cache, hybrid stacks
  6. 6

    Mixture-of-Experts LLMsnew

    Sparse expert FFNs chosen by a router, plus multi-head latent attention: the shape of most large open LLMs.

    Builds on: TransformerAdds: top-k routing, total vs. active parameters, expert parallelism, compressed KV cache (MLA)
  7. 7

    BEV Perception

    Many cameras fused into one bird's-eye-view grid of tokens.

    Builds on: ViTAdds: learnable BEV queries, deformable cross-attention, multi-camera token budgets
  8. 8

    Vision-Language-Action

    A VLM backbone plus an action expert that generates robot action chunks.

    Builds on: VLM, DiffusionAdds: action expert, flow matching on action chunks, control-rate latency
  9. 9

    Robot Foundation Models

    A slow reasoning system and a fast action system, across robot bodies.

    Builds on: VLAAdds: System 1 / System 2 split, heterogeneous inputs and outputs, multi-embodiment

Hands-on track

Build the models yourself. Do the matching lab right after each module (labs 01–03 after the full Transformer guide), take the LLM tutorial right after labs 01–03, keep the efficiency cookbook open whenever a guide talks about memory or speed, and finish with the optional agent tutorial.

  1. L

    Build-it-yourself labs10 labs

    Fill-in-the-blank files that build the core of every module from scratch: attention, a transformer block, GPT generation with a KV cache, ViT, VLM fusion, diffusion, the Mamba scan, MoE routing, BEV projection and flow matching. A checker reports PASS / TODO / FAIL with hints; solutions are included.

    After: each matching module (01–03 after the full Transformer guide, 04–10 after modules 2–8)Adds: the ability to write each model's core yourself
  2. E

    Memory & inference efficiency cookbookcookbook

    Where memory goes (weights, KV cache, activations), a "will it fit?" calculator for Jetson and GPUs, the roofline, and one card per technique: quantization, GQA/MLA, FlashAttention, paged KV, prefix caching, speculative decoding, fusion, sparsity, LoRA and checkpointing, plus the Jetson deployment workflow.

    When: a reference used throughout, from the Transformer module on (review it at the end)Adds: a toolbox for saving memory and speeding up inference and training
  3. T1

    Build an LLM from scratchtutorial

    Byte-level BPE, a GPT decoder (RMSNorm, RoPE, SwiGLU, tied embeddings), pretraining, sampling, a tested KV cache and SFT. Trains in about a minute on 4 CPU threads, no downloads.

    After: the full Transformer guide and labs 01–03, before module 2Adds: the full training and inference pipeline, written and run yourself
  4. T2

    Build a personal agenttutorial

    A tool-use loop on the Claude Messages API with notes search, memory, guardrails and evals. A scripted mock model runs everything offline.

    When: optional, any time after Build an LLM; suggested last, after Robot FMAdds: agent loop, safe tools, BM25 retrieval, guardrails, evaluation, Agent SDK and MCP

How to study this repo

The same five steps for every module. The guides end with the material for steps 3 and 4.

  1. Read the guideFollow the tensor shapes through each diagram; use the calculators with your own model sizes.
  2. Run the .pypython <module>.py prints shapes, parameter counts and FLOPs. Change a dimension and predict the output first.
  3. Do the exercisesEach has a self-verification step, usually an assertion you can run.
  4. Take the self-checkAnswer before opening the hidden answers; redo the numeric ones on paper.
  5. Revisit after a few daysRetake the self-check cold. Whatever you missed, reread that section only.

Suggested study cadence

About two modules a week, at 4–6 hours per module including its lab, running the code and some exercises. Plan more time if you do every exercise, less if you only read.

WeekStudyReview (self-check, cold)
11 Transformer (primer, full guide, labs 01–03) · T1 Build an LLM–
22 ViT · 3 VLMTransformer
34 DiffusionBuild an LLM, ViT
45 Mamba · 6 MoEVLM, Diffusion
57 BEV · 8 VLAMamba, MoE
69 Robot FM · E cookbook (review) · T2 Build an agent (optional)BEV, VLA, and the Transformer again
Spaced review works better than rereading: retake each module's self-check about a week after you first study it, and again a few weeks later. Keep a list of questions you missed; it is your personal index into the guides.

About this project

These guides are written with AI and reviewed by me, Hokwang Choi, as I study the models myself. Worked numbers come from the scripts in each module, and every guide links the papers it follows. They can still be wrong.

Every page has a Feedback button. Your note reaches me by email, I fix the page, and the banner at the top counts it as one more piece of human feedback in the loop. The source is on GitHub (MIT license).