Skip to content

Feature/tog notebook - #493

Merged
YWHyuk merged 16 commits into
micro2026from
feature/tog-notebook
Oct 28, 2026
Merged

YWHyuk merged 16 commits into
micro2026from
feature/tog-notebook

Conversation

@YunseonShin

Copy link
Copy Markdown
Collaborator

Title: Tutorial session1 for the MICRO 2026 slides: TOG.ipynb replaces CompilerOptimization.ipynb; Mapping, ExecutionMode, TOGSimConfig and Training updated

Base: micro2026 ← feature/tog-notebook

Summary

This brings tutorial/session1 in line with the MICRO 2026 slides, so the next micro2026-<n> tag publishes an image whose notebooks match them. The tutorial changes are confined to tutorial/session1/.

Besides the tutorial commits, the branch merges pytorchsim-triton-backend up to e6b1c90. That merge adds five upstream commits that micro2026 does not have yet:

micro2026's own three commits, which move Coprocessor's tutorial branch up to f0c0ae0, touch docker/tutorial/ and third_party/tutorial.json only. They do not conflict with this branch.

Changes (tutorial/session1/)

TOG.ipynb replaces CompilerOptimization.ipynb

The tutorial no longer covers compiler optimization (fusion on and off). TOG.ipynb runs on togsim_config.yml, with both functional and timing modes on, and covers two kernels.

ReLU:

  • compiles a 1024 x 1024 bf16 ReLU into tog/relu/ and prints its tog.cpp.

Embedding (data-dependent): compiles 256 ids into an 8192 x 512 bf16 table, into tog/embedding/, and shows:

  • the runtime attribute that kernel.json declares, which comes from in_ptr0 (the ids);

  • the addresses Spike recorded for the latest launch in attr_<program>_0.bin, whose row starts are 512 * id;

  • the Gather(ATTR0) on the table's load in tog.cpp;

  • the same TOG relaunched with three patterns of ids. For each launch, the notebook prints the cycles, and the DRAM reads and bandwidth from that launch's TOGSim log:

    ids cycles DRAM reads DRAM GB/s
    one row 2,318 128 108
    sequential rows 2,728 8,256 181
    random rows 3,141 8,096 156

Mapping.ipynb: a 4096 x 4096 bf16 mm, instead of a 2 x 1024³ bmm

  • A 1024 mm is built as the resident mm whatever the strategy. On the bmm, the three strategies were within 1% of each other.
  • On the 4096 mm they differ by up to 1.75x:
    • heuristic: 2,653,758 cycles (tile 256/2048/1024);
    • external: 3,829,310 cycles (512/512/256);
    • autotune: 2,184,773 cycles (512/2048/256).
  • The external tile comes from tutorial_external_mapping.json, which is now keyed 4096_4096_4096.
  • Each run takes 10 to 20 minutes, and the notebook says so.

ExecutionMode.ipynb: a 1024 x 1024 bf16 mm, instead of 512 x 512

  • At 512, Spike's time was hidden by compiling and by torch's start-up, so the three modes took about the same time.
  • At 1024, the cells take 69.6 s (functional and timing), 53.3 s (functional only) and 34.0 s (timing only), cold.

TOGSimConfig.ipynb: a compute-bound bmm (8 x 1024³ bf16), instead of a 4096 x 4096 mm

  • The 4096 mm is bound by DRAM bandwidth on two cores: 1.16x.
  • The bmm is compute bound on one core and on two: 284,919 → 153,733 cycles, 1.85x.

Training.ipynb: the MSE loss is compiled too

  • It is compiled separately from the model, as opt_loss = torch.compile(loss_fn).
  • fused_mse_loss, fused_mse_loss_backward and the bias gradient's fused_sum are simulated, instead of running on the CPU through the npu fallback.

Testing

On ghcr.io/psal-postech/tutorial-micro2026:bea36e137609d59a94b158635ffa596878338b5c (micro2026-2, compiler pin 940c671, amd64), with tutorial/ replaced by this branch's:

  • All nine session1 notebooks run end to end with 0 error cells.
  • TOG.ipynb takes 15 to 38 s, and Mapping.ipynb 46 min.
  • Training.ipynb logs no [Eager Mode] op. Its losses and trained parameters match the fp32 CPU reference.

Not tested yet:

  • The notebooks have not been run on the compiler pin this branch brings in (8402097).
  • They have not been run with Coprocessor f0c0ae0 (micro2026-5).

Once this is merged and a new micro2026-<n> tag has built its image, I will rerun the nine notebooks on that image and update any cycle counts that change.

YunseonShin and others added 15 commits October 27, 2026 16:59
third_party/pytorchsim-triton-backend.json moves from 940c671 to PTB main e3a0576, whose image is published.
PSAL-POSTECH/PyTorchSim-Triton-Backend@940c671...e3a0576
third_party/pytorchsim-triton-backend.json moves from e3a0576 to PTB main 8402097, whose image is published.
PSAL-POSTECH/PyTorchSim-Triton-Backend@e3a0576...8402097
…its weight once

The grouped kernel ran one program per BM-row block of a group, and each program read the group's whole
weight tile (BK covers K, so its K loop ran once). Every block read the expert's weight again: Qwen3-30B-A3B's
gmm_down reads 383 x 3 MB at T4096 (255 x at T2048), and the TOG was bound on HBM (MXU 21% busy), where v6e's
grouped matmul reads each expert's weight about once.

A program is now one group with rows: it walks the group's rows BM at a time, and when the B tile holds all
of K (BK == KP) reads it once before the walk. Otherwise each row block walks K as before. At most A's rows
groups have rows, so the grid is min(groups, rows) programs: program i takes the i-th group with rows from a
table: the group whose running count of groups with rows is i + 1, with its first row and row count, all
three zero for a program left over, which then reads nothing. The table the TOG reads is that group, first
row and row count per program. test_grouped_mm pins the grid: one program per group with rows (8 for 8
groups with rows, 4 for 4 rows over 16 groups).

Measured locally on the validation bundle's kernels against PTB main 940c671c (TOGSim 1f05af9, tpuv6e),
TOGSim / v6e, main's CI (940c671c) -> this commit:
gmm_down T1 0.875 -> 0.884, gmm_gate_up T1 0.933 -> 0.940; layer decode S4096 1.058 -> 1.062.
At T >= 128 A has at least as many rows as there are groups, so the grid is one program per group, as it was
before the table; measured with that earlier table: gmm_down T2048 1.059 -> 0.943, T4096 1.629 -> 0.909;
gmm_gate_up T2048 1.042 -> 0.979, T4096 (CI timeout) -> 0.870; layer prefill S1024 1.111 -> 1.074, S2048
1.129 -> 1.088, S4096 (CI timeout) -> 0.980.
[Frontend] grouped_mm runs one program per group with rows and reads its weight once
[Simulator] Compiler pin: PTB main 8402097
@YunseonShin
YunseonShin requested a review from YWHyuk October 28, 2026 05:18
@YWHyuk
YWHyuk merged commit 2520221 into micro2026 Oct 28, 2026
@YWHyuk
YWHyuk deleted the feature/tog-notebook branch November 19, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants