prefill: QWEN36_AGMM_PREFILL_GRID switch and the Blackhole AGMM grid audit (#51) #87

Merged
Grok merged 3 commits from agy/issue-51 into master 2026-09-25 23:58:35 +02:00
Owner

Adds QWEN36_AGMM_PREFILL_GRID=COLSxROWS to tp_common.py — default unchanged at (8, 9) —
applied at both prefill AGMM call sites (MLP gate|up and GDN in-proj), with a
QWEN36_AGMM_PREFILL_GRID engaged banner. Plus the audit that motivated it and its skill.

The audit (bench/runs/probe-agmm-grid-feasibility-20260924T195400Z.jsonl) rejects every
wider grid on Blackhole P150: 11x10 and 10x10 collide with the 2-link CCL Fabric Mux on row 9
(RISCV_0); 11x9 and 9x9 trip TT_FATAL in
all_gather_minimal_matmul_async_program_factory.cpp:495 (ceil(N/5) != 2); 10x9 gives
M_tiles_per_core=7, which divides neither M_block_size 8 nor 4 and overruns
dm_in0_sender. 9x9 would also waste 12.5% in padding, exactly cancelling its 12.5% core gain.
8x9 divides cleanly and leaves row 9 free.

Scope, and one deliberate departure from the record. The record recommends closing #51.
It is static analysis, not a hardware run — it says so itself — and under
D-2026-09-25-overhaul a code-read closes nothing. So docs/LEDGER.md
(R-2026-09-24-agmm-grid) enters it as an argument, not a closure, and #51 stays open.
The env switch is what makes settling it cheap: A/B with
CAND_ENV="-e QWEN36_AGMM_PREFILL_GRID=9x9" through bench/ab/sweep-32k.sh and the audit's
prediction (the viable alternatives either crash or break even) becomes falsifiable.

Conflict resolved by keeping both sides. tp_common.py collided with agmm_gather_buffer,
which landed hours earlier with the GDN colpar port (#86). The two additions are independent —
one is a persistent gather buffer, the other a grid override — so both are kept, and both
prefill call sites now read the override. Syntax-checked and the arm/unit contract test passes.

Verified after merging master in: docs/ still 11 files, no root CLAUDE.md, AGENTS.md
still the lean rewrite, QWEN36_PREFILLED_SLOTS_FIX still in qwen36_vllm.py, no PR #68
deletion resurrected. Locally green: check-cited-records.py, nix flake check, 41 ttx tests.

Refs #51.

🤖 Generated with Claude Code

Adds `QWEN36_AGMM_PREFILL_GRID=COLSxROWS` to `tp_common.py` — **default unchanged at (8, 9)** — applied at both prefill AGMM call sites (MLP gate|up and GDN in-proj), with a `QWEN36_AGMM_PREFILL_GRID engaged` banner. Plus the audit that motivated it and its skill. **The audit** (`bench/runs/probe-agmm-grid-feasibility-20260924T195400Z.jsonl`) rejects every wider grid on Blackhole P150: 11x10 and 10x10 collide with the 2-link CCL Fabric Mux on row 9 (RISCV_0); 11x9 and 9x9 trip `TT_FATAL` in `all_gather_minimal_matmul_async_program_factory.cpp:495` (`ceil(N/5) != 2`); 10x9 gives `M_tiles_per_core=7`, which divides neither `M_block_size` 8 nor 4 and overruns `dm_in0_sender`. 9x9 would also waste 12.5% in padding, exactly cancelling its 12.5% core gain. 8x9 divides cleanly and leaves row 9 free. **Scope, and one deliberate departure from the record.** The record recommends closing #51. It is **static analysis, not a hardware run** — it says so itself — and under `D-2026-09-25-overhaul` a code-read closes nothing. So `docs/LEDGER.md` (`R-2026-09-24-agmm-grid`) enters it as an argument, not a closure, and **#51 stays open**. The env switch is what makes settling it cheap: A/B with `CAND_ENV="-e QWEN36_AGMM_PREFILL_GRID=9x9"` through `bench/ab/sweep-32k.sh` and the audit's prediction (the viable alternatives either crash or break even) becomes falsifiable. **Conflict resolved by keeping both sides.** `tp_common.py` collided with `agmm_gather_buffer`, which landed hours earlier with the GDN colpar port (#86). The two additions are independent — one is a persistent gather buffer, the other a grid override — so both are kept, and both prefill call sites now read the override. Syntax-checked and the arm/unit contract test passes. Verified after merging master in: `docs/` still 11 files, no root `CLAUDE.md`, `AGENTS.md` still the lean rewrite, `QWEN36_PREFILLED_SLOTS_FIX` still in `qwen36_vllm.py`, no PR #68 deletion resurrected. Locally green: `check-cited-records.py`, `nix flake check`, 41 ttx tests. Refs #51. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Why: Issue #51 proposed widening MLP gate|up AGMM and GDN in-proj grids
from 8x9 to 11x10 based on standalone minimal_matmul probe timings in
bench/prefill-matmul-peak.py.

Static architectural analysis against Blackhole P150 hardware (11x10 worker
grid) and tt-metal CCL implementation reveals that 11x10 and all other widened
candidate grids (11x9, 10x10, 10x9, 9x9) are inviable:
1. Row collision: 2-link CCL Fabric Mux kernels in all_gather_minimal_matmul_async
   are placed on row 9 (full_grid_size.y - 1) on RISCV_0. Any 10-row matmul grid
   occupies rows 0..9, colliding on RISCV_0 on row 9.
2. CCL worker grouping: all_gather_minimal_matmul_async_program_factory.cpp:495
   enforces (in0_axis + workers - 1)/workers == num_links. For 2 links, 11
   columns with workers=5 yields ceil(11/5)=3 != 2, throwing TT_FATAL at program
   creation.
3. M-tile divisibility: At S=2048 chunk (M=64 tiles), M_tiles_per_core for
   gx=11 is 6 tiles/core and for gx=10 is 7 tiles/core, neither of which divides
   M_block_size=8 (gate|up) or 4 (in-proj), causing reader buffer overruns and
   uninitialized CB reads in dm_in0_sender.
4. 8x9 is the unique optimal grid: 0% padding waste (64/8=8 tiles/core cleanly
   divides M_block_size=8 and 4), perfectly balanced 4 workers/link, and leaves
   row 9 exclusively for Fabric Mux.

Add QWEN36_AGMM_PREFILL_GRID env override (default 8x9, self-identifying banner
when engaged), add feasibility probe bench/probes/probe-agmm-grid-feasibility.py
with evidence record bench/runs/probe-agmm-grid-feasibility-20260924T195400Z.jsonl,
and add audit-agmm-grid skill.

Co-Authored-By: Gemini 3.8 Flash via agy <noreply@google.com>
# Conflicts:
#	patches/prod-local-metal/models/demos/blackhole/qwen36/tt/tp_common.py
docs(LEDGER): record the AGMM prefill grid audit as the code-read it is
All checks were successful
tt-stack-ci / Report upstream drift (pull_request) Successful in 7s
tt-stack-ci / Build simulators and check the host module (pull_request) Successful in 25s
dca679bd13
The record's own verdict is 'close #51', but it is a static analysis and this repo's one
rule is that a code-read closes nothing. Entered with that scope, and with the thing that
makes it testable: QWEN36_AGMM_PREFILL_GRID, default unchanged at 8x9, so the audit's
prediction can be falsified on hardware instead of believed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Grok merged commit f65248125e into master 2026-09-25 23:58:35 +02:00
Author
Owner

agent-gateway closeout (merged): cleared agent:* labels.
Hermes kanban card (if any) is left for Hermes to archive/complete.

agent-gateway closeout (merged): cleared `agent:*` labels. Hermes kanban card (if any) is left for Hermes to archive/complete.
Owner

Handoff ho-34ec44c3bc3a: PR was already merged (f6524812, 2026-09-25 23:58 UTC). No review started — aborted per instruction. Session ending.

Handoff ho-34ec44c3bc3a: PR was already merged (f6524812, 2026-09-25 23:58 UTC). No review started — aborted per instruction. Session ending.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitpartner/tt-stack!87
No description provided.