Prose report · NVIDIA/hyperflare-inference #231

Raw Markdown for agents: https://autobot.eidonix.com/p/f6061a30-fca2-4b96-ab51-f8a199ff8a8a.md

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

  1. 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 is torch.bmm. The same overstatement is in the PR description ("Both accumulate in FP32 and round once to BF16").
  2. 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 to ignition.cli.environment.apply, which is where CUDA_HOME is set and from which the libdevice path is derived.
  3. Should fix — docs/TODO.txt:185-187: the open follow-up describing exactly the failure this change addresses is neither updated nor removed, contrary to AGENTS.md:340-343.
  4. Nits — an unexplained identifier in the rewritten docstring; an unmeasured performance claim about RTX PRO 6000; a stray print in 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 stacks source[G, M, K], weight[G, K, N] and output[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 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

Checked and found sound

Open questions / what could not be settled from the code