Skip to content

Commit 056c71f

Browse files
committed
docs(tutorials): add Runnable Code section to 3 paired tutorials
Bidirectional discoverability between tutorials and the new code/ contributions in docs/tutorials/code/: - attention_tutorial.md (+ _en) -> mha.py, axial_attention.py - flow_matching_tutorial.md (+ _en) -> flow_matching.py - image_generation_systems_tutorial.md (+ _en) -> mmdit_block.py, toy_mmdit_t2i_pipeline.py Each tutorial gains a short "Runnable Code" section at the bottom pointing to the paired scripts and to code/README.md. HTML regenerated via tools/render_html.py with original title/eyebrow/ subtitle preserved.
1 parent dda29b2 commit 056c71f

12 files changed

Lines changed: 148 additions & 42 deletions

docs/tutorials/attention_tutorial.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<meta name="generator" content="ARIS render-html (academic, v1)">
99
<meta name="aris:source-path" content="docs/tutorials/attention_tutorial.md">
10-
<meta name="aris:source-sha256" content="8d8d5146c1a9a924cd5e29973b7419d9fe14f5009c392db4b4ad6ff3a12ab1e0">
11-
<meta name="aris:generated-at" content="2026-05-19 03:40 UTC">
10+
<meta name="aris:source-sha256" content="970e8a0a0538e0022a8bf1ec44765f3d6a12987ed2d4c322b034e10eb1c3817e">
11+
<meta name="aris:generated-at" content="2026-05-26 11:27 UTC">
1212

1313
<!-- MathJax 3 -->
1414
<script>
@@ -380,6 +380,8 @@ <h3>Contents</h3>
380380
</li>
381381
<li><a href="#a-附录完整-from-scratch-代码骨架">§A 附录:完整 from-scratch 代码骨架</a>
382382
</li>
383+
<li><a href="#runnable-code">📜 Runnable Code</a>
384+
</li>
383385
</ol>
384386
</nav>
385387

@@ -388,11 +390,11 @@ <h3>Contents</h3>
388390
<div class="eyebrow">Interview Prep · Attention / MHA / Cross-Attention</div>
389391
<h1>Attention 面试 Cheat Sheet</h1>
390392
<p class="subtitle">公式推导 + From-Scratch 代码 + 25 高频题(L1 必会 · L2 进阶 · L3 顶级 lab)</p>
391-
<p class="byline">By <strong>Ruofeng Yang (杨若峰), Shanghai Jiao Tong University</strong></p>
393+
392394
<div class="meta">
393395
<span><strong>Source:</strong> <code>docs/tutorials/attention_tutorial.md</code></span>
394-
<span><strong>SHA256:</strong> <code>8d8d5146c1a9</code></span>
395-
<span><strong>Rendered:</strong> 2026-05-19 03:40 UTC</span>
396+
<span><strong>SHA256:</strong> <code>970e8a0a0538</code></span>
397+
<span><strong>Rendered:</strong> 2026-05-26 11:27 UTC</span>
396398

397399
</div>
398400
</header>
@@ -759,12 +761,17 @@ <h2 id="a-附录完整-from-scratch-代码骨架">§A 附录:完整 from-scrat
759761
[h] d_model not divisible by num_heads -&gt; ValueError ✓
760762
[i] return_weights=False -&gt; weights is None ✓</code></pre>
761763
<p>代码经独立 reviewer 静态检查 + PyTorch 实跑 sanity check,与 <code>nn.MultiheadAttention</code> diff = 0。</p>
764+
<hr />
765+
<h2 id="runnable-code">📜 Runnable Code</h2>
766+
<p>本 tutorial 的核心概念在 <a href="code/"><code>docs/tutorials/code/</code></a> 里有最小可跑的 PyTorch 实现:</p>
767+
<ul><li><a href="code/mha.py"><code>mha.py</code></a> — 标准 Multi-Head Self-Attention + causal mask + 跟 <code>nn.MultiheadAttention</code> 数值对齐验证</li><li><a href="code/axial_attention.py"><code>axial_attention.py</code></a> — H/W 轴向 attention + 复杂度对比表 + 感受野隔离测试</li></ul>
768+
<p>每个脚本默认 CPU 几秒跑完,自带 <code>assert</code> sanity check。完整说明见 <a href="code/README.md"><code>code/README.md</code></a></p>
762769

763770
<footer class="aris-footer">
764771
Generated by <a href="https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/render-html/SKILL.md">ARIS <code>/render-html</code></a> ·
765772
source path <code>docs/tutorials/attention_tutorial.md</code> ·
766-
SHA256 <code>8d8d5146c1a9</code> ·
767-
generated at 2026-05-19 03:40 UTC.
773+
SHA256 <code>970e8a0a0538</code> ·
774+
generated at 2026-05-26 11:27 UTC.
768775
This is a generated view — edit the source Markdown, then re-render.
769776
</footer>
770777
</main>

docs/tutorials/attention_tutorial.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,14 @@ FP16 下直接手写 naive attention 不做 fp32 accumulation。
810810
```
811811

812812
代码经独立 reviewer 静态检查 + PyTorch 实跑 sanity check,与 `nn.MultiheadAttention` diff = 0。
813+
814+
---
815+
816+
## 📜 Runnable Code
817+
818+
本 tutorial 的核心概念在 [`docs/tutorials/code/`](code/) 里有最小可跑的 PyTorch 实现:
819+
820+
- [`mha.py`](code/mha.py) — 标准 Multi-Head Self-Attention + causal mask + 跟 `nn.MultiheadAttention` 数值对齐验证
821+
- [`axial_attention.py`](code/axial_attention.py) — H/W 轴向 attention + 复杂度对比表 + 感受野隔离测试
822+
823+
每个脚本默认 CPU 几秒跑完,自带 `assert` sanity check。完整说明见 [`code/README.md`](code/README.md)

docs/tutorials/attention_tutorial_en.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!DOCTYPE html>
2-
<html lang="zh-CN">
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Attention Tutorial En</title>
77

88
<meta name="generator" content="ARIS render-html (academic, v1)">
99
<meta name="aris:source-path" content="docs/tutorials/attention_tutorial_en.md">
10-
<meta name="aris:source-sha256" content="ecb6fe924cee8db5b2dd0daa4fb81c3866ec6b47ceadaa73ba0011378eb07e67">
11-
<meta name="aris:generated-at" content="2026-05-19 18:47 UTC">
10+
<meta name="aris:source-sha256" content="52fb9664c6793bc81ab2abdec83fbd0978574b6e370057af74ae62525bacf33a">
11+
<meta name="aris:generated-at" content="2026-05-26 11:27 UTC">
1212

1313
<!-- MathJax 3 -->
1414
<script>
@@ -380,6 +380,8 @@ <h3>Contents</h3>
380380
</li>
381381
<li><a href="#a-appendix-full-from-scratch-code-skeleton">§A Appendix: Full from-scratch code skeleton</a>
382382
</li>
383+
<li><a href="#runnable-code">📜 Runnable Code</a>
384+
</li>
383385
</ol>
384386
</nav>
385387

@@ -391,8 +393,8 @@ <h1>Attention Tutorial En</h1>
391393

392394
<div class="meta">
393395
<span><strong>Source:</strong> <code>docs/tutorials/attention_tutorial_en.md</code></span>
394-
<span><strong>SHA256:</strong> <code>ecb6fe924cee</code></span>
395-
<span><strong>Rendered:</strong> 2026-05-19 18:47 UTC</span>
396+
<span><strong>SHA256:</strong> <code>52fb9664c679</code></span>
397+
<span><strong>Rendered:</strong> 2026-05-26 11:27 UTC</span>
396398

397399
</div>
398400
</header>
@@ -759,12 +761,17 @@ <h2 id="a-appendix-full-from-scratch-code-skeleton">§A Appendix: Full from-scra
759761
[h] d_model not divisible by num_heads -&gt; ValueError ✓
760762
[i] return_weights=False -&gt; weights is None ✓</code></pre>
761763
<p>Code passed independent reviewer static check + PyTorch sanity-check run, diff vs <code>nn.MultiheadAttention</code> = 0.</p>
764+
<hr />
765+
<h2 id="runnable-code">📜 Runnable Code</h2>
766+
<p>Minimal runnable PyTorch implementations of this tutorial's core concepts live in <a href="code/"><code>docs/tutorials/code/</code></a>:</p>
767+
<ul><li><a href="code/mha.py"><code>mha.py</code></a> — standard Multi-Head Self-Attention + causal mask + numerical parity check against <code>nn.MultiheadAttention</code></li><li><a href="code/axial_attention.py"><code>axial_attention.py</code></a> — H/W factorized axial attention + complexity comparison table + receptive-field isolation test</li></ul>
768+
<p>Each script runs on CPU in seconds with built-in <code>assert</code> sanity checks. Full overview in <a href="code/README.md"><code>code/README.md</code></a>.</p>
762769

763770
<footer class="aris-footer">
764771
Generated by <a href="https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/render-html/SKILL.md">ARIS <code>/render-html</code></a> ·
765772
source path <code>docs/tutorials/attention_tutorial_en.md</code> ·
766-
SHA256 <code>ecb6fe924cee</code> ·
767-
generated at 2026-05-19 18:47 UTC.
773+
SHA256 <code>52fb9664c679</code> ·
774+
generated at 2026-05-26 11:27 UTC.
768775
This is a generated view — edit the source Markdown, then re-render.
769776
</footer>
770777
</main>

docs/tutorials/attention_tutorial_en.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,14 @@ Actual sanity-check output (PyTorch 2.x, single-machine GPU):
810810
```
811811

812812
Code passed independent reviewer static check + PyTorch sanity-check run, diff vs `nn.MultiheadAttention` = 0.
813+
814+
---
815+
816+
## 📜 Runnable Code
817+
818+
Minimal runnable PyTorch implementations of this tutorial's core concepts live in [`docs/tutorials/code/`](code/):
819+
820+
- [`mha.py`](code/mha.py) — standard Multi-Head Self-Attention + causal mask + numerical parity check against `nn.MultiheadAttention`
821+
- [`axial_attention.py`](code/axial_attention.py) — H/W factorized axial attention + complexity comparison table + receptive-field isolation test
822+
823+
Each script runs on CPU in seconds with built-in `assert` sanity checks. Full overview in [`code/README.md`](code/README.md).

docs/tutorials/flow_matching_tutorial.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<meta name="generator" content="ARIS render-html (academic, v1)">
99
<meta name="aris:source-path" content="docs/tutorials/flow_matching_tutorial.md">
10-
<meta name="aris:source-sha256" content="ab4358901d204fec676df6ce3b8559be4e69fec3833f764bcfc937b113eea281">
11-
<meta name="aris:generated-at" content="2026-05-19 03:40 UTC">
10+
<meta name="aris:source-sha256" content="435d9a5281b792c9796dffb814c5dd474e15a4173d514405fe3589e22e4b3982">
11+
<meta name="aris:generated-at" content="2026-05-26 11:27 UTC">
1212

1313
<!-- MathJax 3 -->
1414
<script>
@@ -367,6 +367,8 @@ <h3>Contents</h3>
367367
</li>
368368
<li><a href="#8-完整可运行示例2d-toy">§8 完整可运行示例(2D toy)</a>
369369
</li>
370+
<li><a href="#runnable-code">📜 Runnable Code</a>
371+
</li>
370372
</ol>
371373
</nav>
372374

@@ -375,11 +377,11 @@ <h3>Contents</h3>
375377
<div class="eyebrow">Interview Prep · Flow Matching / Diffusion Generative Modeling</div>
376378
<h1>Flow Matching Quick Reference</h1>
377379
<p class="subtitle">Conditional Flow Matching · Rectified Flow / VP / VE · 训练 + 采样 + SD3 / FLUX 实战</p>
378-
<p class="byline">By <strong>Ruofeng Yang (杨若峰), Shanghai Jiao Tong University</strong></p>
380+
379381
<div class="meta">
380382
<span><strong>Source:</strong> <code>docs/tutorials/flow_matching_tutorial.md</code></span>
381-
<span><strong>SHA256:</strong> <code>ab4358901d20</code></span>
382-
<span><strong>Rendered:</strong> 2026-05-19 03:40 UTC</span>
383+
<span><strong>SHA256:</strong> <code>435d9a5281b7</code></span>
384+
<span><strong>Rendered:</strong> 2026-05-26 11:27 UTC</span>
383385

384386
</div>
385387
</header>
@@ -740,12 +742,17 @@ <h2 id="8-完整可运行示例2d-toy">§8 完整可运行示例(2D toy)</h2
740742
<div class="callout callout-warn"><div class="callout-title">Production 化要补的(教学版未含)</div><p>上线前需补的工程项如下。</p></div>
741743
<ul><li><strong>EMA scheduler</strong>:训练后期 decay 更接近 1(如 0.9999 → 0.99995)</li><li><strong>Gradient checkpointing</strong>:U-Net / DiT 显存优化</li><li><strong>Mixed precision</strong>:fp16 / bf16 + GradScaler</li><li><strong>Latent space</strong>:高分辨率图像在 VAE latent 里跑 FM(LDM / SD3 / FLUX)</li><li><strong>Conditioning</strong>:text encoder (T5 / CLIP) + cross-attention 或 token concat</li><li><strong>Distributed</strong>:DDP / FSDP for multi-GPU</li><li><strong>Loss weighting</strong>:SD3 用 logit-normal $t$ 已隐式 reweighting;EDM 显式 SNR weighting</li></ul>
742744
<p><strong>Flow Matching Quick Reference</strong> · 主要参考:Lipman et al. 2023 (Flow Matching), Liu et al. 2022 (Rectified Flow), Esser et al. 2024 (SD3 / MM-DiT)</p>
745+
<hr />
746+
<h2 id="runnable-code">📜 Runnable Code</h2>
747+
<p>本 tutorial 的核心概念在 <a href="code/"><code>docs/tutorials/code/</code></a> 里有最小可跑的 PyTorch 实现:</p>
748+
<ul><li><a href="code/flow_matching.py"><code>flow_matching.py</code></a> — Rectified Flow on 2D toy moons:训练 <code>(x_1 - x_0)</code> velocity + Euler ODE 采样 + 轨迹可视化</li></ul>
749+
<p>CPU 30 秒左右跑完(matplotlib 可选),自带 sanity 检查。完整说明见 <a href="code/README.md"><code>code/README.md</code></a></p>
743750

744751
<footer class="aris-footer">
745752
Generated by <a href="https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/render-html/SKILL.md">ARIS <code>/render-html</code></a> ·
746753
source path <code>docs/tutorials/flow_matching_tutorial.md</code> ·
747-
SHA256 <code>ab4358901d20</code> ·
748-
generated at 2026-05-19 03:40 UTC.
754+
SHA256 <code>435d9a5281b7</code> ·
755+
generated at 2026-05-26 11:27 UTC.
749756
This is a generated view — edit the source Markdown, then re-render.
750757
</footer>
751758
</main>

docs/tutorials/flow_matching_tutorial.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,13 @@ if __name__ == "__main__":
535535
- **Loss weighting**:SD3 用 logit-normal $t$ 已隐式 reweighting;EDM 显式 SNR weighting
536536

537537
**Flow Matching Quick Reference** · 主要参考:Lipman et al. 2023 (Flow Matching), Liu et al. 2022 (Rectified Flow), Esser et al. 2024 (SD3 / MM-DiT)
538+
539+
---
540+
541+
## 📜 Runnable Code
542+
543+
本 tutorial 的核心概念在 [`docs/tutorials/code/`](code/) 里有最小可跑的 PyTorch 实现:
544+
545+
- [`flow_matching.py`](code/flow_matching.py) — Rectified Flow on 2D toy moons:训练 `(x_1 - x_0)` velocity + Euler ODE 采样 + 轨迹可视化
546+
547+
CPU 30 秒左右跑完(matplotlib 可选),自带 sanity 检查。完整说明见 [`code/README.md`](code/README.md)

docs/tutorials/flow_matching_tutorial_en.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!DOCTYPE html>
2-
<html lang="zh-CN">
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Flow Matching Tutorial En</title>
77

88
<meta name="generator" content="ARIS render-html (academic, v1)">
99
<meta name="aris:source-path" content="docs/tutorials/flow_matching_tutorial_en.md">
10-
<meta name="aris:source-sha256" content="90243d531e3f172dc24c2345e6ada197471f80f92dd45892bc0d002afa86c3f0">
11-
<meta name="aris:generated-at" content="2026-05-19 18:47 UTC">
10+
<meta name="aris:source-sha256" content="30fb19ce90837b396223edc71b7d1276adb53fa6ab8b488e27d89a9507b577e7">
11+
<meta name="aris:generated-at" content="2026-05-26 11:27 UTC">
1212

1313
<!-- MathJax 3 -->
1414
<script>
@@ -367,6 +367,8 @@ <h3>Contents</h3>
367367
</li>
368368
<li><a href="#8-complete-runnable-example-2d-toy">§8 Complete runnable example (2D toy)</a>
369369
</li>
370+
<li><a href="#runnable-code">📜 Runnable Code</a>
371+
</li>
370372
</ol>
371373
</nav>
372374

@@ -378,8 +380,8 @@ <h1>Flow Matching Tutorial En</h1>
378380

379381
<div class="meta">
380382
<span><strong>Source:</strong> <code>docs/tutorials/flow_matching_tutorial_en.md</code></span>
381-
<span><strong>SHA256:</strong> <code>90243d531e3f</code></span>
382-
<span><strong>Rendered:</strong> 2026-05-19 18:47 UTC</span>
383+
<span><strong>SHA256:</strong> <code>30fb19ce9083</code></span>
384+
<span><strong>Rendered:</strong> 2026-05-26 11:27 UTC</span>
383385

384386
</div>
385387
</header>
@@ -740,12 +742,17 @@ <h2 id="8-complete-runnable-example-2d-toy">§8 Complete runnable example (2D to
740742
<div class="callout callout-warn"><div class="callout-title">Production additions (not in this pedagogical version)</div><p>engineering items to add before deployment.</p></div>
741743
<ul><li><strong>EMA scheduler</strong>: decay closer to 1 in late training (e.g. 0.9999 → 0.99995)</li><li><strong>Gradient checkpointing</strong>: U-Net / DiT memory optimization</li><li><strong>Mixed precision</strong>: fp16 / bf16 + GradScaler</li><li><strong>Latent space</strong>: high-resolution images run FM in VAE latent space (LDM / SD3 / FLUX)</li><li><strong>Conditioning</strong>: text encoder (T5 / CLIP) + cross-attention or token concat</li><li><strong>Distributed</strong>: DDP / FSDP for multi-GPU</li><li><strong>Loss weighting</strong>: SD3 implicitly reweights via logit-normal $t$; EDM uses explicit SNR weighting</li></ul>
742744
<p><strong>Flow Matching Quick Reference</strong> · Main references: Lipman et al. 2023 (Flow Matching), Liu et al. 2022 (Rectified Flow), Esser et al. 2024 (SD3 / MM-DiT)</p>
745+
<hr />
746+
<h2 id="runnable-code">📜 Runnable Code</h2>
747+
<p>Minimal runnable PyTorch implementations of this tutorial's core concepts live in <a href="code/"><code>docs/tutorials/code/</code></a>:</p>
748+
<ul><li><a href="code/flow_matching.py"><code>flow_matching.py</code></a> — Rectified Flow on 2D toy moons: train to regress <code>(x_1 - x_0)</code> velocity + Euler ODE sampling + trajectory viz</li></ul>
749+
<p>Runs on CPU in ~30 seconds (matplotlib optional) with built-in sanity checks. Full overview in <a href="code/README.md"><code>code/README.md</code></a>.</p>
743750

744751
<footer class="aris-footer">
745752
Generated by <a href="https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/render-html/SKILL.md">ARIS <code>/render-html</code></a> ·
746753
source path <code>docs/tutorials/flow_matching_tutorial_en.md</code> ·
747-
SHA256 <code>90243d531e3f</code> ·
748-
generated at 2026-05-19 18:47 UTC.
754+
SHA256 <code>30fb19ce9083</code> ·
755+
generated at 2026-05-26 11:27 UTC.
749756
This is a generated view — edit the source Markdown, then re-render.
750757
</footer>
751758
</main>

docs/tutorials/flow_matching_tutorial_en.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,13 @@ if __name__ == "__main__":
535535
- **Loss weighting**: SD3 implicitly reweights via logit-normal $t$; EDM uses explicit SNR weighting
536536

537537
**Flow Matching Quick Reference** · Main references: Lipman et al. 2023 (Flow Matching), Liu et al. 2022 (Rectified Flow), Esser et al. 2024 (SD3 / MM-DiT)
538+
539+
---
540+
541+
## 📜 Runnable Code
542+
543+
Minimal runnable PyTorch implementations of this tutorial's core concepts live in [`docs/tutorials/code/`](code/):
544+
545+
- [`flow_matching.py`](code/flow_matching.py) — Rectified Flow on 2D toy moons: train to regress `(x_1 - x_0)` velocity + Euler ODE sampling + trajectory viz
546+
547+
Runs on CPU in ~30 seconds (matplotlib optional) with built-in sanity checks. Full overview in [`code/README.md`](code/README.md).

0 commit comments

Comments
 (0)