Simplicity report · NVIDIA/hyperflare-inference #231

Raw Markdown for agents: https://autobot.eidonix.com/p/74fb2225-a2dc-43d7-a825-66f66f7b7d3c.md

PR #231 — Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections

Review lens D (simplicity): what can be deleted. I read the full diff, every changed function in context (ignition/components/bf16_bmm.py, ignition/components/linear.py, ignition/preparation/tuning.py, tests/components/test_bf16_bmm.py, tests/components/test_bf16_bmm_cuda.py, tests/preparation/test_toolchain.py), the sibling components the new one is modelled on (sm103_projection.py, moe_sm103.py, window_attention.py, gated_norm_preparation.py), and the project rules (AGENTS.md, docs/design-review.md, charter). Per charter line 44 I report no design proposals for the _bmm_kernel body or the _TILES contents — only defects, and there I found nothing to report.

Key findings


Should fix

1. flare::bmm_out is left dead in linear.py after its only caller is replaced

File/lines: ignition/components/linear.py:89-96

@torch.library.custom_op("flare::bmm_out", mutates_args=("out",))
def _bmm_out(source: torch.Tensor, weight: torch.Tensor, out: torch.Tensor) -> None:
    torch.bmm(source, weight, out=out)


@_bmm_out.register_fake
def _fake_bmm_out(source, weight, out):
    pass

What is wrong: the diff replaces _bmm_out(source, self.weight, self.output) inside BatchedUnquantizedProjection.__call__ with bf16_bmm.execute(...) (linear.py:85), and nothing else calls _bmm_out. A repo-wide search for bmm_out returns only four hits in this file: the definition and fake at 89-96, and the unrelated flare::sm103_bmm_out op at 463-469, whose caller at 452 is intact.

Why it matters: it is exactly the kind of leftover the project rejects. AGENTS.md:73-78 ("Reject unsupported abstractions and churn… Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost") and docs/design-review.md principle 15 ("Reject scope expansion…") both point at it: a registered Torch custom op is public surface (torch.ops.flare.bmm_out) that no path uses, and it implies a cuBLAS entry point that the new component is supposed to own. The same pattern in bf16_bmm.py:131-139 registers the replacement op, so the old one is now not just dead but duplicated in purpose.

Fix: delete linear.py:89-96. This cannot strand a prepared artifact: the compiled-forward cache key hashes every .py file under ignition/ (ignition/preparation/aot.py:583-590, feeding hashlib.sha256 at 581-592), so removing the op changes the cache key by construction. Verified by reading that loop.

2. _NATIVE_JITS registration belongs at module scope, not inside compile_bmm

File/lines: ignition/components/bf16_bmm.py:26 and :108

from b12x._lib import compile_plan          # line 26
...
    compile_plan._NATIVE_JITS.add(_bmm_kernel)   # line 108, inside compile_bmm

What is wrong: the component imports the private compile_plan module only to reach the private set _NATIVE_JITS and mutates it from inside the compile function. Both existing components do the same registration once, at import, with the set imported by name:

Why it matters: the in-function statement is a second path to the same state and is not what makes the invariant hold. The mechanism the PR relies on — compile workers resolving the CompileJob target "ignition.components.bf16_bmm:compile_bmm" (bf16_bmm.py:173) — imports this module, so a module-scope registration also runs in the worker before planning, which is precisely why moe_sm103 and sm103_projection can register at module scope and still work under compile_jobs. Keeping the mutation inside the function additionally means the registry is not populated in any process that imports the component without compiling (e.g. a rank that reuses another rank's artifact), which is a narrower guarantee than the sibling components give. AGENTS.md:73-78 again: a duplicate mechanism with no concrete requirement.

Smaller version:

from b12x._lib.compile_plan import (_NATIVE_JITS, attach_programs, compile_only_launches,
                                    launch_triton, load_programs)
...
# Compile planning leaves a deferred program in the kernel's Triton memo. b12x evicts those
# entries only from kernels in its registry, so register ours here (once, at import).
_NATIVE_JITS.update((_bmm_kernel,))

placed after _bmm_kernel (after line 84), and delete line 108 plus the from b12x._lib import compile_plan import on line 26. Net −2 lines and one fewer import.


Nits

3. tests/components/test_bf16_bmm.py:21-33 restate the _TILES table instead of a behaviour

The two tests encode, as literal expectations, the filter expression at bf16_bmm.py:54-56 (columns % tile[1] == 0 and depth % tile[2] == 0 and tile[0] <= max(16, 2 * rows) and 4 * tile[0] >= min(rows, 128)) together with the _TILES table at bf16_bmm.py:42-43:

So any legal edit to _TILES (adding a tile, widening a row window) fails them while no runtime behaviour changed, and a bug in _tactics that happened to keep the table self-consistent would pass. AGENTS.md:79-84 says tests must "exercise the affected behavior or contract", and docs/design-review.md principle 12 says to validate the real path. This is the tile-menu subset of the contract, not its behaviour.

The behavioural part of this file is the rejection test at lines 36-44 (strided rows, unaligned base, mismatched stacks → ValueError), which covers the validation relocated out of BatchedUnquantizedProjection.__init__ (bf16_bmm.py:142-153) and should stay. Tile behaviour on device is covered by test_bf16_bmm_cuda.py:41-64.

Fix: delete test_tactics_start_with_cublas_and_size_row_tiles_by_capacity and test_expansion_stacks_exclude_column_tiles_wider_than_the_output (lines 21-33), or reduce them to the one property that is a contract rather than a table transcription — that "cublas" is tactic 0 and every Triton tactic's tiles divide the output columns and depth — dropped to a single assertion over one glm_stacks(...) query. If maintainers want the row window pinned, that is a design-review judgement for the kernel lens, not something a transcription test can establish.

4. Two small surface-area nits

a) ignition/components/bf16_bmm.py:156-162 — prepared_state is public API with one test consumer. Every sibling component keeps the materializer as a local closure and exports nothing extra: window_attention.py:197-205, gated_norm_preparation.py:78-86, qk_norm_rope.py:143-145 (not opened), region_selection.py:155-158 (not opened). Here the only caller outside declare_bmm's materialize= argument (bf16_bmm.py:171) is tests/components/test_bf16_bmm_cuda.py:57. Smaller version: inline the body into the materialize= lambda in declare_bmm; the test can reach the same state via the plan it already builds. Note this genuinely costs the CUDA test a couple of lines, so it is a nit, not a defect.

b) ignition/components/linear.py:70-74 — the package's only Sphinx :mod: role. The new docstring sentence reads (see :mod:ignition.components.bf16_bmm). docs/design-review.md principle 16 and the repo-prose skill ask for prose an outside reader can follow; the neighbouring component docstrings (sm103_projection.py:5-24, linear.py:9-14) name modules in plain text, and a repo-wide search finds no other :mod: role in this package. Also, BatchedUnquantizedProjection.__init__ line 82 calls bf16_bmm.declare_bmm, which names the module already. Fix: (see ignition/components/bf16_bmm.py) or drop the parenthetical.


Checked and found nothing to cut

ignition/preparation/tuning.py — net simplification, no finding. The change moves _prepare_compiler_toolchain() to module import (tuning.py:66, immediately after its definition at 47-63) and deletes the two lazy call sites that used to exist in RecordedPreparationSession.__init__ and declare. That is two call sites → one, not a parallel path. The function is idempotent (_set_triton_libdevice_path() plus runtime_patches.apply(), which no-ops after _APPLIED — ignition/runtime_patches/__init__.py:90-110), so the import-time call cannot double-apply anything. The five-line comment at 57-61 explains a non-obvious ordering constraint (Triton memoizes compiled kernels per specialization without the library path), which AGENTS.md:73-78 permits — this is required context, not comment expansion. The change does not initialize CUDA, and tests/preparation/test_toolchain.py:74 asserts exactly that (assert not torch.cuda.is_initialized(), with torch.cuda._lazy_init patched to raise at lines 27-29); the new import parametrization at line 16 / 46-49 tests the new ordering, so it is behaviour, not scaffolding.

tests/components/test_bf16_bmm_cuda.py — nothing to cut. Lines 41-64 assert real contract properties (bitwise/one-ulp agreement with cuBLAS, the NaN row tail left untouched, distance > 0 and the cublas_error bound); lines 67-122 exercise raced selection plus captured-graph replay with allocation counters unchanged. AGENTS.md:79-84 and docs/design-review.md principle 12 require this validation.

Deleted validation was relocated, not weakened. The checks removed from BatchedUnquantizedProjection.__init__ (dtypes, devices, matching stacks) reappear in bf16_bmm.query_from_call (bf16_bmm.py:142-153) and are still exercised by test_bf16_bmm.py:36-44. AGENTS.md:67-72 (reject weakened guarantees) is satisfied.

No new fallback layer or configuration switch. The cuBLAS branch is a raced tactic within one prepared contract (bf16_bmm.py:57, and State.run's program is None path at 124-126), not a user-visible option; AGENTS.md:73-78 and principle 4's ban on interchangeable backends do not bite because both tactics run behind the same declared contract and the race selects one on the preparing device.


Open questions / not established