FULL REPORT — PR #231 "Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections"
Head 0ba78eb, base main, 6 files, +373/−16.
Verdict: not ready to merge — one blocking placement issue (repository split), a stale base that must be rebased first, and five should-fix items. The code itself is well-formed: no concrete kernel defect, no duplicate kernel, no per-model branch, no fallback flag, and every contract is declared through the existing native_plan/native_contract/custom-op patterns. Where lenses disagreed, the subtractive fix is the one requested — nothing below asks for new code.
Key findings
- Blocking: ≈349 of the +373 added lines (4 of 6 files) are recipe-repository code under
main's split layout; the runtime half of the PR is the ~9-lineignition/preparation/tuning.pychange. - Rebase needed: the head predates the split; the reported conflict is
ignition/components/linear.py, the file whose body changed, and CI on the head is red. - Should fix (5): import-time toolchain preparation vs. the documented environment-before-patches order; a docstring that states a numerical invariant only the Triton tactic provides;
_NATIVE_JITSregistered inside a memoised function; a missingsession=ininput_factory; a staledocs/TODO.txtentry. - Subtraction: could remove ~30 of the +373 added lines inside the component (dead
flare::bmm_out, duplicate helpers, tests that cannot fail), on top of the ~349 lines that leave with the split. - No correctness bug in today's shipped path: caller strides/alignment,
scratch_bytes=0, plan/handle lifetime, the mutating-out contract and the tactic filter all check out.
Blockers
B1. Four of the six changed files are recipe-repository code (≈349 of +373 lines)
Where: ignition/components/bf16_bmm.py (new, 184 lines), BatchedUnquantizedProjection rewrite at ignition/components/linear.py:69-86, tests/components/test_bf16_bmm.py (new), tests/components/test_bf16_bmm_cuda.py (new).
Rules on main:
AGENTS.md:385-392— "Keepignition/components/in this repository limited to the 13 Helios-ABI runtime interface modules (capacity,collectives,completion,engram,flashinfer_sampling,logprobs,ngram_delivery,readiness,sampling,state,state_transfer,vision_delivery,vision_state), enforced bytests/preparation/test_core_boundary.py. Put reusable b12x/Triton model execution mechanisms inhyperflare_recipes/components/inlocal-inference-lab/hyperflare-recipes."docs/design-review.md:31-37(principle 3) — "Reusable projections, experts, collectives, and model execution blocks belong inhyperflare_recipes/components/; Helios-ABI runtime interface components belong inignition/components/."docs/model-development.md:276already pointsUnquantizedProjectionathyperflare_recipes/components/linear.py(not opened).tests/preparation/test_core_boundary.py:11-26pins the retained set as a frozenset and:62-64asserts{py.stem for py in ignition/components/*.py} == RETAINED_IGNITION_COMPONENTS— an exact match. A newbf16_bmm.pyfails it onmain;linear.pyis not in the set either, andignition/components/linear.pydoes not exist onmainat all (the head predates the split).AGENTS.md:88-89and:172-176foreclose waiving this: "A feature request, passing tests, or a performance gain does not waive an architectural invariant."
Corroboration (not a judgement call): the maintainer's own 2026-11-24 triage comment on this PR states the same split — "hyperflare-recipes: the BF16 batched-matmul implementation, projection wiring, and component tests. This runtime repository: the compiler-toolchain initialization change in ignition/preparation/tuning.py … The runtime portion can remain here after removing recipe-owned files." The author's 2026-11-13 comment already reports git merge-tree conflicts on ignition/components/linear.py.
Requested change: split the PR.
- This repository keeps
ignition/preparation/tuning.py(+9/−5) andtests/preparation/test_toolchain.py(+6/−2). - Open a linked PR against
local-inference-lab/hyperflare-recipescarryingbf16_bmm.py, theBatchedUnquantizedProjectionwiring, both component test files and their validation evidence (the SM120/GB10 numbers, the tile table, the race). - If the maintainer instead wants one shared b12x-level raced BF16 batched matmul that every recipe benefits from, that is a recorded maintainer decision on the design (
AGENTS.md:88-89), not placement by default.
Why: merging the component here breaks the enforced boundary, puts model-execution code in a runtime repository the charter keeps small and model-agnostic, and leaves the motivating caller (ignition/recipes/glm53/mla.py, gone from main) outside the repository that will consume it.
B2. Rebase onto main before splitting — the head predates the split and CI is red
Where: head 0ba78eb is ~18 days old; base main has since removed ignition/recipes/ and most of ignition/components/. tests/preparation/test_core_boundary.py:40-48 on main also asserts ignition/recipes must not exist.
Requested change: rebase, have the linear.py conflict resolution re-reviewed (it is the file whose body changed, so it is not mechanical), and get CI green on the rebased head. Rebase before, not after, the split.
Why: otherwise B1 gets resolved by conflict rather than by decision, and no reviewer can confirm the BatchedUnquantizedProjection body survived the resolution.
Should Fix
S1. ignition/preparation/tuning.py:66 — the toolchain switch runs at import of a widely imported module, before ignition.cli.environment.apply() sets what it depends on
Where: _prepare_compiler_toolchain() (function at :47-63) moved from RecordedPreparationSession.__init__ and declare() to a bare module-level call at :66. It calls runtime_patches.apply() (:51) then imports torch._inductor.runtime.compile_tasks._set_triton_libdevice_path and runs it under config.patch(emulate_precision_casts=…) (:62-63), deriving the libdevice from the toolkit root.
Evidence:
ignition/cli/environment.py:5-11documents the required order: "PyTorch, b12x, Triton, and the CuTe DSL read these variables when they are imported or first used.applysets the environment before installing runtime patches." Its body setsTRITON_CACHE_DIR(:47) andCUDA_HOME/CUDA_PATH/TRITON_PTXAS.EXE_PATH(:52-57) and only then callsruntime_patches.apply()(:61).docs/preparation-development.md:59-63says the same from the other side.environment.applynever re-runs_set_triton_libdevice_path, so a process that importsignition.preparation.tuningfirst keeps the libdevice chosen before the configuredCUDA_HOMEexisted — exactly the program-identity mismatch the new comment at:57-61sets out to prevent.- Breadth:
tuningis imported at module scope by ~60 modules (48ignition/components/*.py,preparation/fixtures/*, every recipebootstrap.py). - Failure timing: a torch/triton version mismatch (
ignition/runtime_patches/__init__.py:103-105) now raisesPreparationErrorat import, during test collection and in CPU-only tooling that never prepares anything. CUDA initialization is not introduced —tests/preparation/test_toolchain.py:26-29,74pins that.
Requested change (no code growth, and no revert): keep the single import-time call — it is shorter than the two call sites it replaced — but (a) state the new ordering in the PR description, and (b) pin it with one assertion in the existing subprocess harness: drive ignition.cli.environment.apply (or set CUDA_HOME/TRITON_CACHE_DIR) before the import and assert the selected libdevice belongs to that toolkit. The added "import" parameterisation (tests/preparation/test_toolchain.py:16,46-49) only compares identities after the import and never touches environment.apply.
Why: the property the change exists to guarantee is the one current evidence does not exercise. Today the hazard is latent (in cli/serve.py the recipe bootstrap is imported lazily inside prepare(), after environment.apply), so whether this is a bug or only a documentation gap is decided by that one assertion — not by more code.
S2. ignition/components/bf16_bmm.py:7-9 — the docstring states a numerical invariant only one tactic provides
Where: the module docstring says "…with FP32 accumulation and one BF16 rounding per result", and the PR description repeats it ("Both accumulate in FP32 and round once to BF16").
Evidence: the Triton tile is explicit — acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32) (:78), one acc.to(output.dtype.element_ty) at store (:84). The default/champion tactic is cuBLAS via torch.bmm (:57 returns ("cublas", *tiles); :124-126 takes it whenever program is None), whose reduction precision follows torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction (default True). This repository treats that switch as a real distinction elsewhere (tests/recipes/test_deepseek41_indexer_batches_cuda.py:39-44 (not opened), tests/recipes/test_step5_reference_cuda.py:38-43 (not opened) disable it for exact BF16 matmul). The CUDA test establishes a one-ulp bound against torch.bmm (tests/components/test_bf16_bmm_cuda.py:62) and a bound against FP64 (:64) — not an identity.
Requested change (shorter, not longer): "The Triton tile accumulates in FP32 and rounds once to BF16; the cuBLAS tactic follows PyTorch's BF16 matmul settings (allow_bf16_reduced_precision_reduction). The CUDA test bounds every tactic to one BF16 ulp of torch.bmm." Use the same sentence in the description. No new code, no new test.
Why: AGENTS.md:67-72 rejects weakened or misstated numerical guarantees; a recipe author reasoning from this sentence would over-assume accumulation precision.
S3. ignition/components/bf16_bmm.py:108 — _NATIVE_JITS is registered inside a memoised function, so it is skipped on every cache hit
Where: compile_plan._NATIVE_JITS.add(_bmm_kernel) at :108, inside @program_cache(scope="preparation") (:99-110), with from b12x._lib import compile_plan at :26.
Evidence: the comment at :105-107 states a requirement — the kernel must be in b12x's registry before planning, because b12x evicts deferred planning entries only for registered kernels. Placing it in the body means it runs only on a cache miss; on a hit (same operands/tactic compiled earlier in the process, or a restored preparation cache entry — e.g. a second device ordinal, or the compile-worker path at :172-173) the registry is left without the kernel while deferred entries may still exist. Both siblings register unconditionally at module scope: sm103_projection.py:33 imports _NATIVE_JITS and :257-258 updates it right after the kernels; moe_sm103.py:33 (not opened),357,387 the same. A compile worker imports the module, so module scope is both the convention and the strictly stronger guarantee.
Requested change (−2 lines, one fewer import): add _NATIVE_JITS to the from b12x._lib.compile_plan import … line at :27, call _NATIVE_JITS.add(_bmm_kernel) immediately after the @triton.jit definition (:63-84), delete :108 and the compile_plan import at :26. Do not add a guard or a second mechanism.
Why: removes a timing dependency the current placement only half-guarantees, and matches the two components already in the tree.
S4. ignition/components/bf16_bmm.py:174 — input_factory is called without session=, the only caller in the repository that omits it
Where: inputs = input_factory(source, output, storage=getattr(session, "benchmark_storage", None)).
Evidence: fixtures/projection.py:37-42 → fixtures/resources.py:15-38 use the session for exactly one thing: session.release_benchmark_cache() (:30-33), documented as "A preceding operator can leave its fixture in the session cache. Live trials own their storage independently of that cache entry." Every other caller passes it (linear.py:130-131,143,354; mla_norm_quant.py:46-47; varlen_attention.py:56-57). This is not a use-after-free — owners=(operands, weight) at :178-179 retains storage — but the race allocates while the previous operator's cached fixture is still resident, which at GLM's 8,192-row stacks is hundreds of MB.
Requested change (one line): input_factory(source, output, storage=…, session=session).
Why: restores the documented fixture contract at the moment a large race allocates, and removes the only divergent call site.
S5. docs/TODO.txt:185-187 — the open item this change closes is left stale
Where:
[ ] 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.
That is the same failure the PR describes, and the second commit is titled "Select the CUDA toolkit libdevice when the tuning module is imported". AGENTS.md:513-515: "Update or remove entries as work is completed."
Requested change: delete the entry if the import-time selection closes it; if part remains (e.g. a process that outlives the switch, or the runtime_patches.identity() question below), rewrite it to name what is still missing and the criterion for removal.
Why: canonical docs are a present-state specification; a stale open item contradicts the new comment at tuning.py:57-61.
Subtract / Simplify
Could remove ~30 of the +373 added lines. And before that: ~349 of those lines leave this repository entirely with the split (B1). Nothing in this section asks for more code.
1. ≈349 lines: the split itself
bf16_bmm.py (184), linear.py (+8/−9), test_bf16_bmm.py (44), test_bf16_bmm_cuda.py (122) move to hyperflare-recipes. What stays is tuning.py (+9/−5) and test_toolchain.py (+6/−2) — and there the change already deletes two lazy call sites in favour of one, so it is a net simplification, not growth. Its justification should be restated in runtime terms (the libdevice/program-key problem docs/TODO.txt:185-187 records), since the current justification ("component CUDA tests compile before a session exists") moves out with the component.
2. 8 lines: the orphaned flare::bmm_out custom op — ignition/components/linear.py:89-96
@torch.library.custom_op("flare::bmm_out", mutates_args=("out",))
def _bmm_out(source, weight, out): torch.bmm(source, weight, out=out)
@_bmm_out.register_fake
def _fake_bmm_out(source, weight, out): pass
The diff replaced their only call site (__call__ now calls bf16_bmm.execute, :85) and left the op registered. A repo-wide search finds only this definition plus the unrelated, still-used sm103_bmm_out (:452,463-469); nothing in tests/, ignition/recipes/, helios/src or heliopause references flare::bmm_out. Delete all eight lines, wherever linear.py ends up. Nothing is lost: torch.bmm into a caller-owned strided view is now State.run:124-126. AGENTS.md's churn rule (AGENTS.md:73-78) targets exactly this residue, and removing it cannot strand a compiled artifact (the compiled-forward cache key hashes every ignition/*.py).
3. ≈11 lines: reuse helpers that already exist instead of private copies
bf16_bmm.py:119-123(−3): delete theState.runshape/stride revalidation.query_from_call:142-153already validated the same predicates and stored the same(shape, stride)pairs (:153);prepare_callre-passes the same three tensors (:182);executereaches the state only through the plan handle built from that query (:131-134); the only production caller passes fixed scratch views (mla.py:252-257,321-329,340-344), so strides cannot change between declare and run. The guard also allocates a tuple of tuples per launch, for every layer of every captured graph. Siblings'State.runbodies only launch (qk_norm_rope.py:80-84,gated_norm_preparation.py:55-57(not opened)).bf16_bmm.py:176-179(−4): delete the privatebenchmarkclosure and useignition/preparation/fixtures/bf16_gemv.py:10-16, already used twice bylinear.py(:129-132,142-144). One-line change on the other side: giveState.runthe shared keyword signature (*, out, bias=None) and passpartial(bf16_gemv_fixtures.benchmark_call, inputs=inputs, weight=weight, bias=None). Behaviour identical: no bias here, sobias=Nonereproduces today's owners tuple.bf16_bmm.py:102-103,153(−2): usetensor_facts/metadata_tensorfromselected_attention.py:27-33asqk_norm_rope.py:25,71,window_attention.py:20 (not opened),89,region_selection.py:29 (not opened),64andmsa_attention.py:22 (not opened),185do — or state inQuery's comment (:48) why BF16-only facts deliberately omit dtype.bf16_bmm.py:156-162(−7): inlineprepared_stateintodeclare_bmm'smaterialize=argument, asqk_norm_rope.py:142-145andwindow_attention.py:197-205(not opened) do. Its only caller outsidematerialize=istest_bf16_bmm_cuda.py:57, which can reach the same state through the plan it already builds.
4. ≈6 test lines that cannot fail or prove nothing
tests/components/test_bf16_bmm.py:31-33:test_expansion_stacks_exclude_column_tiles_wider_than_the_outputis arithmetically guaranteed — the only column filter iscolumns % tile[1] == 0(bf16_bmm.py:55) and the fixture's output width is 256, so a 512-wide tile is excluded by arithmetic; the same rule is asserted at:28. Delete it.tests/components/test_bf16_bmm.py:21-27: the parametrisation transcribes the_TILESrow-window literal and the divisibility clauses, so any legal tile-table edit fails it while no behaviour changed, and a_tacticsbug that kept the table self-consistent would pass. Reduce to the contract:"cublas"is tactic 0 and each tile divides the output columns and depth, over oneglm_stacks(...)query.tests/components/test_bf16_bmm_cuda.py:63:assert (distance > 0).float().mean() <= 1e-3adds a statistic, not a behaviour —:62already bounds one BF16 ulp and:64bounds against FP64. Delete.- Keep:
test_bf16_bmm.py:36-44(the rejection behaviour relocated out of__init__, coveringbf16_bmm.py:142-153) and the rest of the CUDA file (:59-62,64row-tail masking via NaN sentinels, the one-ulp and FP64 bounds, and the race/replay/no-allocation test at:67-122). Those are the contract.
Nits
- Description/prose mechanics (grouped, one-line items): the PR description has no
Discord:line;linear.py:73uses:mod:ignition.components.bf16_bmm`` — the only such role inignition/;tests/components/test_bf16_bmm_cuda.py:92leavesprint(f"{torch.cuda.get_device_name(device)} selected {selected} …")in a committed test;tuning.py:48's "forward math libraries" is an unexplained identifier for a single library — write "the CUDA toolkit's libdevice". "cublas"encoded as a bare string plusprogram is None:_tacticsreturns("cublas", *tiles), mixing astrwith 5-tuples, and the module then identifies cuBLAS by the absence of a program (:117,124,158,172) rather than by the declared tactic, unlikeselected_attention.py:73-86andwindow_staging.py:65-77(not opened). Every sibling contract returns uniform tuples (gdn_prefill_sm103.py:45(not opened),window_staging.py:27(not opened),selected_attention.py:51).(("cublas",), *tiles)removes the side channel.bf16_bmm.py:16-17claims an RTX PRO 6000 performance result ("while RTX PRO 6000 selects wide tensor-op tiles near its byte floor") that the PR's evidence does not contain: the measurements table is GB10-only and the SM120 evidence is correctness. Cite the measurement or narrow the sentence.- Shape drift: the GLM shape pair
(256, 512)/(512, 256)now lives in three places (test_bf16_bmm.py:14,test_bf16_bmm_cuda.py:22, and the recipe), so a silent drift weakens the CUDA test's claim to cover the probed shapes.
Explicitly checked and cleared (not findings)
- No concrete defect in
_bmm_kernel(bf16_bmm.py:63-84). Per the charter, GPU-kernel review is limited to concrete defects; none found._TILES(:42-43) is not proposed for narrowing — each entry is reachable at a distinct row/column regime and the author has selection data for one tile only. scratch_bytes=lambda t: 0(:170) is honest: both tactics write the caller'soutput(:119-128), cuBLAS throughtorch.bmm(..., out=)::125.mutates_args=("output",)plus the no-op fake (:131-139) matches the sibling custom ops, e.g.flare::sm103_dense_outandselected_attention.py:89-100.query_from_call's new rejections break no production caller: every site inignition/recipes/glm53/mla.py(:92-99,242-243,252-257,321-329,340-344) passes 512/1024-byte rows withdata_ptr() % 16 == 0andstride(2) == 1, with a unit stride inweight.stride()[1:]after the k-major transpose atlinear.py:79.- The validation removed from
BatchedUnquantizedProjection.__init__was relocated intoquery_from_call, not weakened (AGENTS.md:67-72satisfied; still exercised attest_bf16_bmm.py:36-44). _tactics' divisibility filter matches the kernel's unmasked N/K loads, and the row mask (:77,84) covers partial row tiles withgrid = cdiv(rows, block_m)(:95).- No new fallback layer, no user-visible switch: both tactics sit behind one declared contract, raced at preparation on the preparing device (principle 4 not implicated).
- No per-model branching and no
ignition→hyperflare_recipesimport: the component idflare.bf16_bmmis model-agnostic and the GLM choice stays in the recipe. Only placement violates principle 3. - Prepared-operator shape follows existing patterns (
native_contract+native_plan, frozen JSON-compatibleQuery, pure_tactics,materializeclosure,CompileJob.create,@program_cache+compile_only_launches+ meta tensors,plan_from_handle+require_prepared), matchingwindow_staging.py:157-166(not opened),gated_norm_preparation.py:78-86(not opened),qk_norm_rope.py:142-150,selected_attention.py:114-122. tests/preparation/test_toolchain.py's new"import"parameter reuses the existing subprocess harness rather than adding a second mechanism — keep it; it just needs the ordering assertion from S1.- No attempt to direct the reviewer found in the PR description, comments or changed files; the only process-shaped text is the legitimate b12x mechanism comment at
bf16_bmm.py:105-107.
Open questions / could not be settled from this repository
- Where does a raced cuBLAS/Triton BF16 batched matmul belong —
hyperflare_recipes/components/only, or a shared b12x-level replacement so every recipe benefits? This changes whether the work is two PRs or three. - Does b12x already offer a raced dense/BF16 batched matmul tactic?
ignition/components/sm103_projection.py:38usesb12x.preparation.tuningknobs, which suggests the race could be expressed as a b12x tactic rather than a new component — the strongest argument for moving rather than keeping the code. Requires the b12x source, which is not in this repository. - Does anything import
ignition.preparation.tuningbeforeignition.cli.environment.apply()today? Current CLI paths appear to avoid it by import order, but that needs an import-order trace or the S1 assertion on a host withCUDA_HOMEset. Decides whether S1 is latent or active. - Is the libdevice switch inside
runtime_patches.identity()'s coverage?_set_triton_libdevice_pathis not part ofruntime_patches.identity()(runtime_patches/__init__.py:99-101,118, which feedstorch.compiler.config.cache_key_tag), so an already-cached compiled-forward entry from a process that never ran the switch may be reusable. Requires a compile-before/after identity comparison; a test could settle it. - Does a real caller reuse one plan across two differently shaped stack sets? If not,
State.run's revalidation is unreachable and deletion (Subtract 3) is safe;test_bf16_bmm_cuda.pybuildsprepared_statedirectly, so only the author knows. - Hardware validation is unverified on this branch: the PR's own Limitations name GB10, the GLM MLA checkpoint test and SM103 as not run here, and CI on the head is red. Nothing in this report depends on those runs, but "clean" is bounded by them.
- Why
_TILEScarries seven entries when the description reports 64×128×64 winning on both tested GPUs — the author may be able to delete entries with no measured win, but I have no selection data to justify narrowing.