Simplicity scratchpad · NVIDIA/hyperflare-inference #231

Raw Markdown for agents: https://autobot.eidonix.com/p/0afb7fa7-c407-4855-b4c2-c58b21da8fb4.md

#1 [high] should fix: flare::bmm_out custom op left dead in linear.py

ignition/components/linear.py:89-96 still defines @torch.library.custom_op("flare::bmm_out", mutates_args=("out",)) _bmm_out and _fake_bmm_out. The PR's diff replaced the only call site (_bmm_out(source, self.weight, self.output) inside BatchedUnquantizedProjection.__call__) with bf16_bmm.execute(...). Repo-wide search for _bmm_out returns only linear.py:90 and linear.py:94-95 (definition + fake). flare::sm103_bmm_out (linear.py:463) is a separate op and still has a caller at linear.py:452.

Fix: delete lines 89-96. Safe for old artifacts: the compiled-forward cache key hashes every file under ignition/ (ignition/preparation/aot.py:583-590), so removing the op changes the cache key and cannot strand a cached forward that references flare::bmm_out.

#2 [high] should fix: _NATIVE_JITS registration inside compile_bmm differs from repo pattern

ignition/components/bf16_bmm.py:26 imports the module (from b12x._lib import compile_plan) and line 108 mutates the private set at compile time: compile_plan._NATIVE_JITS.add(_bmm_kernel) inside compile_bmm.

Every other component does it once at import with the set imported directly:

Smaller version: import _NATIVE_JITS alongside the other compile_plan names (line 27) and add one module-level _NATIVE_JITS.update((_bmm_kernel,)) next to the kernel with the existing three-line comment; delete the in-function statement and the compile_plan module import. Compile workers import this module to resolve the CompileJob target ("ignition.components.bf16_bmm:compile_bmm", line 173), which is exactly the mechanism moe_sm103/sm103_projection rely on for workers, so worker-side registration still happens before planning.

#5 [high] Research summary

Reviewed PR #231 through lens D (simplicity): read the full diff, every changed function in context (ignition/components/bf16_bmm.py, linear.py, ignition/preparation/tuning.py), the project charter, AGENTS.md, docs/design-review.md, docs/preparation-development.md and the repo-prose skill, plus the sibling components the new one is modelled on (sm103_projection.py, gated_norm_preparation.py, window_attention.py, moe_sm103.py).

Four findings, none blocking:

  1. should fix — ignition/components/linear.py:89-96: the PR deletes the only caller of flare::bmm_out but leaves the custom op and its fake registration; repo-wide search shows no remaining reference. Delete the eight lines (old cached forwards cannot break: the forward cache key hashes all of ignition/, aot.py:583-590).
  2. should fix — ignition/components/bf16_bmm.py:26,108: _NATIVE_JITS is mutated inside compile_bmm via the private compile_plan module, whereas sm103_projection.py:33,258 and moe_sm103.py:31,357 import the set directly and register once at module scope, which also covers compile workers. Move to one module-level _NATIVE_JITS.update((_bmm_kernel,)) and drop the module import.
  3. nit — tests/components/test_bf16_bmm.py:22-33: the two tile tests restate the _TILES table and the filter expression at bf16_bmm.py:54-56, so any legal table edit fails them without behaviour changing; only the rejection test proves behaviour, and GPU tile behaviour is covered by the CUDA test.
  4. low — bf16_bmm.py:156-162 exposes prepared_state as public API whose only non-plan caller is one test (siblings inline the materializer as a closure), and linear.py:70-74 uses the package's only Sphinx :mod: role in a docstring.

The tuning.py change (toolchain preparation at import, two call sites deleted) is a net simplification and I found nothing to cut there; the CUDA test's graph-replay test exercises real contract behaviour (no allocation, NaN tail, one-ulp rounding) and should stay.

#6 [high] Supporting facts for the report: non-findings, citations, open question

Facts to support the report's non-findings and citations (verified in code):

A. ignition/preparation/tuning.py (findings: none). The PR moves _prepare_compiler_toolchain() to module import (line 66, right after the def at 47-63) and deletes the two lazy call sites (old lines in RecordedPreparationSession.__init__ and in declare). Net −2 call sites, +5 comment lines. It is a strict deletion of duplicated work, not an added 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). Nothing left to cut; the docstring/comment rewrite (tuning.py:48, 57-61) explains why the ordering matters, which the repo-prose skill requires for a non-obvious constraint. AGENTS.md:73-78 would reject a new fallback layer here, but there is none.

B. Import-time side effect check: the function does not initialize CUDA, and tests/preparation/test_toolchain.py asserts exactly that (assert not torch.cuda.is_initialized() at line 74, with torch.cuda._lazy_init patched to raise, lines 27-29). The new "import" parametrization at line 16/46-49 tests the new ordering, so it is behaviour, not scaffolding.

C. tests/components/test_bf16_bmm_cuda.py — nothing to cut. Lines 41-64 test a real contract (one-ulp rounding against cuBLAS, NaN row tail left untouched, max error within 1.05x of cuBLAS's own error); lines 67-122 test raced selection plus captured-graph replay with allocation counters unchanged. AGENTS.md:79-84 requires exactly this kind of runtime validation, so the distance > 0 fraction assert (line 63) and the cublas_error bound (line 64) are both load-bearing.

D. Deleted validation relocation, not lost: old BatchedUnquantizedProjection.__init__ inline checks (dtypes/devices, matching stacks) moved into bf16_bmm.query_from_call (bf16_bmm.py:142-153) and are still exercised by tests/components/test_bf16_bmm.py:36-44. No weakened guarantee. AGENTS.md:67-72.

E. Rule citations used: AGENTS.md:73-78 (reject unsupported abstractions, fallback layers, configuration switches, comment expansion), AGENTS.md:235-237 (prefer proven b12x operators — relevant to the "did this need a new kernel" question, but kernel design is out of lens), docs/design-review.md principle 15, charter line 44 (GPU kernel code: report concrete defects only — so I did not propose kernel changes for the _bmm_kernel body or _TILES contents, only for the test that transcribes them).

F. Not established / needs hardware: whether the CPU tactic tests would catch a real regression in the row-window filter is only settleable by knowing which row windows the GLM recipe actually requests; the CUDA test covers (2, 65, 4096) rows only, so a smaller row window than the recipe uses is untested on device. That is a coverage observation, not a defect I can show from code.

#3 [medium] nit: two CPU tests restate the _TILES table instead of a behaviour

tests/components/test_bf16_bmm.py:22-33. The two tile tests do not test behaviour: the parametrization at line 22-23 ((1,{16}) (16,{16,32}) (64,{16,32,64,128}) (256,{32,64,128}) (8192,{32,64,128})) and lines 32-33 (tactic[2] <= 256) re-encode the filter expression in _tiles (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)) plus the _TILES table. Any legal table edit (a new tile, a different row window) makes them fail without any runtime behaviour having changed. test_declarations_reject_strided_rows_and_unaligned_stacks (line 36-44) is the one that proves real behaviour (query rejection) and should stay; the tactic-set expectations add nothing beyond "the table is what the table says". GPU behaviour for the tiles is covered by test_bf16_bmm_cuda.py:41-64.

#4 [low] low: prepared_state as public API and a Sphinx-role docstring in linear.py

  1. ignition/components/bf16_bmm.py:156-162 prepared_state(query, tactic, device) is a public per-tactic materializer whose only non-plan caller is tests/components/test_bf16_bmm_cuda.py:57. Sibling components keep materialize as a local closure and expose nothing: window_attention.py:197-205, gated_norm_preparation.py:78-86, qk_norm_rope.py:143-145, region_selection.py:155-158. Smaller version: inline it into declare_bmm's materialize= argument so the module exports only the contract, the kernel, query_from_call and declare_bmm; the test can call compile_bmm + load_programs for its per-tactic loop. Note it is genuinely used for the numerical race in that test, so removing it costs the test a couple of lines.

  2. ignition/components/linear.py:70-74 class docstring uses a Sphinx cross-reference :mod:ignition.components.bf16_bmm``, the only :mod: role in the package (repo-wide search: one match). The neighbouring component docstrings (sm103_projection.py:5-24, linear.py:9-14 style) name the module in plain prose. Nit: (see ignition/components/bf16_bmm.py) or drop the sentence — the constructor's call to bf16_bmm.declare_bmm already names the module.