Prose review: PR #231 — Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections
Scope: the PR description, the two commit messages, and every prose passage the diff adds or rewrites, judged against AGENTS.md §"Required prose review" (AGENTS.md:24-41), §"Task tracking" (AGENTS.md:338-343), the repository prose skill (.agents/skills/repo-prose/SKILL.md (not opened)), the charter, and the ordering statements in docs/preparation-development.md and ignition/cli/environment.py. Files read in full or in relevant context: ignition/components/bf16_bmm.py (new, 185 lines), ignition/components/linear.py (changed region), ignition/preparation/tuning.py:1-80, tests/components/test_bf16_bmm.py, tests/components/test_bf16_bmm_cuda.py, tests/preparation/test_toolchain.py, docs/TODO.txt:178-195, docs/preparation-development.md:50-75, ignition/cli/environment.py:1-62, AGENTS.md:1-120,300-344, .agents/skills/repo-prose/SKILL.md (not opened).
Key findings
- Should fix —
ignition/components/bf16_bmm.py:7-9: the module docstring presents FP32 accumulation with a single BF16 rounding as the operator's invariant, but only the Triton tactic guarantees it; the default/champion tactic istorch.bmm. The same overstatement is in the PR description ("Both accumulate in FP32 and round once to BF16"). - Should fix —
ignition/preparation/tuning.py:66: preparing the compiler toolchain at module import is a documented-ordering change that neither the description nor a test pins down relative toignition.cli.environment.apply, which is whereCUDA_HOMEis set and from which the libdevice path is derived. - Should fix —
docs/TODO.txt:185-187: the open follow-up describing exactly the failure this change addresses is neither updated nor removed, contrary toAGENTS.md:340-343. - Nits — an unexplained identifier in the rewritten docstring; an unmeasured performance claim about RTX PRO 6000; a stray
printin a test.
Should fix
1. ignition/components/bf16_bmm.py:7-9 — the docstring states a numerical invariant the selected tactic does not enforce
The module docstring says:
"
output[g] = source[g] @ weight[g]for BF16 stackssource[G, M, K],weight[G, K, N]andoutput[G, M, N]with FP32 accumulation and one BF16 rounding per result."
Read as prose, "with FP32 accumulation and one BF16 rounding per result" is the operator's declared numerical contract. The code shows it is only one tactic's property. The Triton kernel is explicit — acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32) (bf16_bmm.py:78) and a single acc.to(output.dtype.element_ty) at store (bf16_bmm.py:84) — but the champion tactic is cuBLAS through torch.bmm, taken whenever no program was prepared: if self.program is None: torch.bmm(source, weight, out=output) (bf16_bmm.py:124-126), and cuBLAS is unconditionally the first entry of the race, return ("cublas", *tiles) (bf16_bmm.py:57).
What cuBLAS does is not in this file's control: PyTorch's BF16 matmul honours torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction, which defaults to True, so the reduction may be carried in BF16. The repository treats that switch as a real distinction — other CUDA tests disable it specifically to get exact BF16 matmul results (tests/recipes/test_deepseek41_indexer_batches_cuda.py:39-44 (not opened), tests/recipes/test_step5_reference_cuda.py:38-43 (not opened)). Nothing in bf16_bmm.py sets or reads the flag, and the PR description's "Both accumulate in FP32 and round once to BF16" repeats the overstatement.
Why it matters: AGENTS.md:67-72 ("Reject weakened guarantees … Numerical bounds must follow the required arithmetic") and the prose skill's rule that invariants be stated as they actually exist (SKILL.md:13-14) make a docstring the place a downstream recipe author will trust. A caller who relies on this sentence to reason about accumulation precision is relying on something only the Triton path provides.
Fix: state per-tactic arithmetic, e.g. "The Triton tile accumulates in FP32 and rounds once to BF16; the cuBLAS tactic's accumulation follows PyTorch's BF16 matmul settings (torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction). The CUDA test bounds every tactic to one BF16 ulp of torch.bmm." Correct the matching sentence in the PR description too.
Evidence that supports the softened wording and is worth keeping: the CUDA test compares each tactic against torch.bmm and asserts distance.max() <= 1 with at most one in a thousand elements differing (tests/components/test_bf16_bmm_cuda.py:57-59,70-73). That is a one-ulp agreement, not an identity — which is why "bitwise equal" measurements in the description should stand as measurements, not be promoted into the docstring's invariant.
2. ignition/preparation/tuning.py:66 — import-time toolchain preparation contradicts the documented ordering, and the description does not say where it sits
The diff deletes _prepare_compiler_toolchain() from RecordedPreparationSession.__init__ and from declare() and adds it as a bare module-level call (ignition/preparation/tuning.py:66, after the function at lines 47-63). The function runs runtime_patches.apply() (line 51) and then _set_triton_libdevice_path() under config.patch(emulate_precision_casts=...) (lines 62-63).
The repository documents a different order. docs/preparation-development.md:59-63: "ignition.runtime_patches.apply() installs process-local Dynamo, Inductor, and Triton fixes after dependency environment setup and before compilation or artifact loading." ignition/cli/environment.py:5-10 states the same relationship from the other side: the module's apply "sets the environment before installing runtime patches", and its body sets TRITON_CACHE_DIR (line 47), CUDA_HOME (line 54) and CUDA_PATH/PTXAS (lines 55-57) before calling runtime_patches.apply() at line 61. It is invoked from ignition/cli/serve.py:211 (not opened),322,476,587, ignition/cli/bench.py:176 (not opened), and qualify/muse_spark_logits.py:591-599 (not opened) — that is, at CLI runtime, after module import.
I did not trace the import chain from ignition/cli/serve.py (not opened) to ignition.preparation.tuning, so I cannot assert that the new import-time call runs first in every path; what I can show is that the code no longer guarantees the documented order, while the behaviour depends on it: the libdevice path is selected from the toolkit root, i.e. one of the CUDA_HOME-derived locations, and tests/preparation/test_toolchain.py:31-35 computes the expected toolkit library as Path(CUDA_HOME) / "nvvm/libdevice/libdevice.10.bc". Selecting it at import time, before environment.apply has chosen CUDA_HOME, is precisely the identity mismatch the new comment at tuning.py:57-61 sets out to prevent.
Two prose obligations follow, and either satisfies this finding:
- The PR description should state the new ordering explicitly — that the toolchain is prepared at import of
ignition.preparation.tuning, which precedesignition.cli.environment.apply, and why that is safe (for example becauseenvironment.applyre-applies patches and the cache directory is not part of the program identity). The description currently says only "prepares the compiler toolchain (runtime patches, then the CUDA toolkit libdevice) at import instead of at session construction", which leaves the interaction with the documented environment-before-patches order unstated;AGENTS.md:33-35requires rewriting passages that "claim results beyond the stated evidence", anddocs/preparation-development.md:59-63is the claim being modified. - Or the code re-asserts the libdevice choice after environment setup, and the description says so.
The new subprocess test covers the three session kinds (tests/preparation/test_toolchain.py:16,46-63) and asserts the import-time identity equals the post-_set_triton_libdevice_path identity (lines 65-74), but it sets CUDA_VISIBLE_DEVICES="" and pops TRITON_LIBDEVICE_PATH (lines 76-77) rather than exercising ignition.cli.environment.apply; so no test settles the environment-ordering question. That is the check that would settle it.
Positive note, no action: the rewritten comment at tuning.py:57-61 is good prose — it names the mechanism (Triton memoizes by specialization without the library path) and the consequence (a kernel reused under an identity native discovery never declared), which is exactly what the prose skill asks for (SKILL.md:37-38). The description's matching sentences ("Triton memoizes compiled kernels by specialization and launch options only", "preparation used undeclared programs") are consistent with it.
3. docs/TODO.txt:185-187 — the entry this work resolves is left stale
Still open at the PR head:
[ ] Invalidate b12x preparation discovery's cached compiler context when
Inductor selects a different libdevice in the same process. Repeated GPU
test preparation can restore program keys for the preceding library.
This is the same failure the PR describes ("a kernel compiled against Triton's bundled libdevice before a session existed was later reused under an identity that native discovery had not declared"), and the second commit is titled "Select the CUDA toolkit libdevice when the tuning module is imported". AGENTS.md:340-343: "Use docs/TODO.txt for miscellaneous follow-up items … Update or remove entries as work is completed." The prose skill adds that canonical documentation is a present-state specification and stale claims should be replaced, not layered over (SKILL.md:26-28), and that TODOs name the missing condition and the criterion for removal (SKILL.md:38).
Fix: if the import-time selection closes the item, delete the entry in this PR. If some part remains (for example, an already-cached context in a process that outlives the switch), rewrite the entry to say what is still missing and the criterion for removal.
Nits
ignition/preparation/tuning.py:48— the docstring reads "Resolve forward math libraries before any Triton program identity is recorded." "Forward math libraries" is an unexplained identifier: the function resolves exactly one library, libdevice, and the phrase occurs nowhere else in the repository (grepoverignition/returns only this line and the surrounding comment).AGENTS.md:33-35andSKILL.md:22-25require explaining concepts before identifiers. Rewrite: "Resolve the CUDA toolkit's libdevice before any Triton program identity is recorded."ignition/components/bf16_bmm.py:16-17— "while RTX PRO 6000 selects wide tensor-op tiles near its byte floor" is a performance claim with no measurement behind it in this PR: the measurements table in the description is GB10-only, and the RTX PRO 6000 evidence is correctness ("passed 5 tests on one RTX PRO 6000 with an empty Triton cache"). The GB10 half of the same sentence is backed by the table (3.53 ms vs 1.84 ms for a plain copy of the same bytes,bf16_bmm.py:13-18). Either cite the RTX PRO 6000 measurement or narrow the sentence to what was measured.SKILL.md:34-36.tests/components/test_bf16_bmm_cuda.py:96—print(f"{torch.cuda.get_device_name(device)} selected {selected} for {source.shape[1]} rows")leaves diagnostic chatter in a committed test.AGENTS.md:335-336asks for ordinary tests and raw benchmark measurements, not development output.
Checked and found sound
- The description's structure follows
AGENTS.md:83-84andSKILL.md:39-42: it gives the problem (cuBLAS's 32x32 WMMA kernel and its cost at 8,192 rows), the resulting behaviour, the measurements as a table with the plain-copy column as a byte floor, the validation with hardware named, and a Limitations section that names the unrun checks (GB10, the GLM MLA checkpoint test, SM103) — matchingSKILL.md:29-36's distinction between implemented and qualified. - The claim "Every tile is bitwise equal to
torch.bmmat the probed GLM shapes" is presented as a measurement, and the following clause correctly states the weaker contract the test enforces ("the test contract allows one BF16 ulp"), consistent withtests/components/test_bf16_bmm_cuda.py:70-73. ignition/components/linear.py:70-74— the new docstring paragraph onBatchedUnquantizedProjectionis accurate: it names the race, points atignition.components.bf16_bmm, and says neither tactic uses scratch, which matchesscratch_bytes=lambda t: 0(bf16_bmm.py:160in the diff) and the no-allocation replay assertion in the CUDA test.- Commit subjects are imperative, state the behaviour, and contain no narration of attempts ("Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections", "Select the CUDA toolkit libdevice when the tuning module is imported") —
SKILL.md:39-42.
Open questions / what could not be settled from the code
- Does
ignition.preparation.tuningget imported beforeignition.cli.environment.applyin every CLI path? Settled by an import-order trace or a test that callsenvironment.applyafter importing the tuning module; I could not show it from the diff. - Whether the
_NATIVE_JITSregistration atbf16_bmm.py:108has a prose consequence for the description: the description does state the constraint ("b12x evicts only kernels defined in its own modules otherwise"), and the code comment atbf16_bmm.py:105-107explains it without development history, so this reads as adequate. - Whether unimported symbols in
bf16_bmm.py(attach_programs,load_programs,CompileJob,PreparedCallare imported and some used later in the file beyond line 140) are all used — outside this lens; left to the code reviewers.