Note: This repo is entirely generated by Agents. Feel free to contact us for any inquiries.
An interactive, puzzle-first walkthrough of DeepSeek-V4's reference implementation
(model.py and kernel.py). The repo ships:
- A 20-lesson curriculum (
tutorial/lesson_specs.py) that slices the reference into small, testable chunks pinned to line ranges in the real source. - A browser IDE (
site/) with syntax-highlighted lessons, clickable fill-in-the-blank "puzzle pills", a free editor, the reference solution, and a local test runner with per-check pass/fail diffs. - A generator (
tools/build_tutorial.py) that materialises runnable workshop files, solution files, reference slices,lessons.json, and the site bootstrap from a single source of truth. - A checker (
tools/check_lesson.py) that executes a lesson's validator against whatever the user just submitted (blanks map or full code), in a sandboxed namespace.
The UI and pedagogy are inspired by skyzh/tiny-llm and shareAI-lab/learn-claude-code;
the technical content is grounded in model.py, kernel.py, and the
DeepSeek_V4.pdf paper in this repo.
Requirements: Python 3.10+ and Node.js 18+.
npm install # no runtime deps; records Node engine
npm run dev # builds lessons + starts the local tutor at :3000Then open http://localhost:3000. Pick a lesson from the sidebar, click the highlighted pills inside the code to enter your answer, and hit Run tests. To compare against the published fix, hit Run solution.
| Command | What it does |
|---|---|
npm install |
Installs the empty runtime manifest (the project is pure static + Python). |
npm run build |
Regenerates tutorial/generated/** and site/assets/lessons-data.js from lesson_specs.py. |
npm run dev |
Runs build then starts the dev server at http://localhost:3000. Autoreloads lesson data on each page load. |
npm start |
Starts the dev server without rebuilding. |
npm test |
Rebuilds, then runs the smoke test suite (tests/test_tutorial_build.py). |
npm run check:all |
Runs every lesson's validator against both the solution blanks and the starter blanks. Fails on any crash. |
You do not need a CUDA build to take the lessons; each lesson uses small
pure-Python stubs that mimic torch / tilelang behaviour where relevant.
Twenty lessons spread across five stages (42 blanks total, ~2 per lesson).
s01Linear Dispatch —model.py:108-120s02Weight & Scale Layout —model.py:123-150s03Row vs Column Parallel Shards —model.py:155-180s04RMSNorm in Float32 —model.py:183-196
s05Base RoPE Frequencies —model.py:220-224s06YaRN Smooth Interpolation —model.py:221-229s07Apply Rotary Embedding —model.py:232-244
s08Compressor Prefill —model.py:316-342s09Window KV Cache —model.py:518-533s10Window + Compressed Top-k —model.py:507-516s11Lightning Indexer Scoring —model.py:418-427
s12Gate (sqrt-softplus + bias) —model.py:564-584s13Sparse MoE Dispatch —model.py:635-645s14SwiGLU Expert —model.py:589-606s15mHC Pre-Mix —model.py:674-682s16mHC Post-Mix —model.py:684-687
s17Block-wise FP8 Activation Quant —kernel.py:41-102s18FP4 GEMM Scale Alignment —kernel.py:442-515s19Sparse Attention Online Softmax —kernel.py:276-352s20mHC Sinkhorn Iterations —kernel.py:371-438
Every lesson entry in lesson_specs.py includes: a tagline, difficulty, tags,
paper anchor, "what you learn", step-by-step workshop notes, pitfalls, the
runnable starter code, the blanks table, and the validator. The generator is the
only thing that turns that spec into files and site data.
lesson_specs.pydefines the spec.starter_codeis a real, runnable Python module; each blank is represented by a__B_<id>__identifier rather than an opaqueBLANKstring.npm run buildsubstitutes__B_<id>__with the starter value to producetutorial/generated/puzzles/NN_<id>.py, and with the solution value to producetutorial/generated/solutions/NN_<id>.py. Both files are importable on their own with no special harness.- The site loads the starter code, then overlays each blank as a click-to-edit "puzzle pill" with its hint and expected value.
- Run tests POSTs
{ lessonId, blanks }to/api/check. The server shells out totools/check_lesson.py, which substitutes blanks, runs the resulting module in a restricted namespace, then runs the lesson's validator which returns structuredchecks(name,passed,expected,actual). - The frontend renders the per-check result with green/red badges and an
expected-vs-actual diff, plus captured
stdoutand Python tracebacks. - Run solution does the same but uses the published solution values, which is handy for comparing behaviour or catching a stale lesson spec.
.
├── model.py Reference DeepSeek-V4 model
├── kernel.py Reference DeepSeek-V4 kernels (TileLang)
├── DeepSeek_V4.pdf Paper (cited from lesson "paper_anchor" fields)
├── tutorial/
│ ├── lesson_specs.py Single source of truth for all 20 lessons
│ └── generated/ Built artefacts (do not edit by hand)
│ ├── puzzles/NN_<id>.py
│ ├── solutions/NN_<id>.py
│ ├── references/NN_<id>.py
│ └── lessons.json
├── tools/
│ ├── build_tutorial.py Spec -> generated + site bootstrap
│ ├── check_lesson.py /api/check backend (runs user code + validator)
│ └── check_all_lessons.py npm run check:all helper
├── site/
│ ├── index.html Dark-theme shell, matches shareAI-lab palette
│ ├── styles.css Responsive grid + puzzle-pill styling
│ ├── app.js Client-side renderer + test runner
│ ├── dev-server.mjs Static server + /api/check endpoint
│ └── assets/lessons-data.js Built lesson bundle (for static hosting)
└── tests/test_tutorial_build.py
- Pick a slice of
model.py/kernel.py. Keep it to a single idea; most lessons are 15-80 lines. - Add a dict to
LESSON_SPECSintutorial/lesson_specs.py:id,order,session,stage,track,title,tagline.source_path+line_start+line_end(used for the "reference" tab and a build-time sanity test).summary,what_you_learn,workshop_steps,pitfalls,paper_anchor.blanks: each entry has anid,label,hint, a runnablestarterexpression, and thesolutionexpression.starter_code: a self-contained Python module with__B_<id>__tokens wherever a blank belongs. The code must be runnable even with all starters (thecheck:allhelper enforces this).validator_code: a module body that definesdef validate(ns)and returns a list of{name, passed, expected, actual}dicts.
- Run
npm testto regenerate files and verify the lesson (including the new "every starter must run" and "every solution must pass" assertions). - Run
npm run devand walk through the lesson in the browser.
Tips:
- Keep runtime imports out of
starter_code; use tiny local stubs if you need something fromtorch. Lessons should execute fast and without GPUs. - If your solution depends on operator precedence (e.g.
a / (b + c)), wrap__B_<id>__in parentheses instarter_codeso the starter evaluates safely. - If a starter value might divide by zero or overflow, pick a non-pathological
default (e.g.
"score"rather than"running_max"before it's updated).
"Some checks failed: …" with expected vs actual. Good signal: your code ran but the validator disagreed with the spec. Read the expected/actual diff under the failing check.
Traceback card appears in the inspector. Your code crashed before the
validator finished. Read the traceback (file paths map to the virtual path
lesson://<id>), fix the crash, and re-run.
npm run dev reports EADDRINUSE 3000. Another process is on port 3000;
either stop it or set PORT=4000 npm run dev.
Blanks don't appear. Make sure starter_code actually contains the token
__B_<id>__. The site only renders a puzzle pill for tokens it finds in the
rendered workshop; npm test asserts this for every declared blank.
Same license as the reference implementation. See the parent DeepSeek-V4 release for details.
If you have any questions, please raise an issue or contact us at Foreverlasting1202@outlook.com.