Correctness scratchpad · NVIDIA/hyperflare-inference #231

Raw Markdown for agents: https://autobot.eidonix.com/p/aa9308d5-1532-43a9-a1ce-6beedf340ffb.md

#1 [high] Scope and key files for PR 231

PR 231 (head 0ba78eb, base main): "Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections". 6 files +373/-16. Files: ignition/components/bf16_bmm.py (new, 184 lines), ignition/components/linear.py (BatchedUnquantizedProjection now declares bf16_bmm plan; old inline _bmm_out path no longer used but the custom op flare::bmm_out is still defined at linear.py:89-96), ignition/preparation/tuning.py (import-time _prepare_compiler_toolchain() at line 66; removed calls in RecordedPreparationSession.init and declare()), tests/components/test_bf16_bmm.py, tests/components/test_bf16_bmm_cuda.py, tests/preparation/test_toolchain.py (new "import" param). Charter rules relevant: review standards require checking every supported model/cache/parallel layout/hardware target, CUDA-graph transitions, and that existing exported cores still load; "GPU kernel code: report concrete defects only". Only production caller of BatchedUnquantizedProjection is ignition/recipes/glm53/mla.py:252-257 (TP1/2/4, decode/context=None), 321-329 (prefill slices), 340-344 (context-parallel slices), and call at 410/423/433/437. CI on head commit: failed.

#2 [high] Should fix: _NATIVE_JITS.add inside program_cache body runs only on a cache miss

FINDING (should fix) — ignition/components/bf16_bmm.py:99-110 (compile_bmm).

compile_plan._NATIVE_JITS.add(_bmm_kernel) is executed inside the body of a function decorated with @program_cache(scope="preparation") (line 99). The comment at 105-107 says registration must precede planning so compile workers evict the kernel's deferred planning entries. Because the add is a side effect of a memoized function body, it only runs on a program_cache miss:

Every other component in the repo registers at module import, unconditionally: ignition/components/moe_sm103.py:357 and :387 (_NATIVE_JITS.add(_quantize_routes), _NATIVE_JITS.add(_reduce_routes) immediately after the kernels) and ignition/components/sm103_projection.py:258 (_NATIVE_JITS.update((_expand_nvfp4, _expand_mxfp8))).

Fix: move compile_plan._NATIVE_JITS.add(_bmm_kernel) to module scope next to the @triton.jit definition (line 84), and import _NATIVE_JITS directly rather than through the compile_plan module. That also removes the need for the from b12x._lib import compile_plan import at line 26.

Note: this is b12x-private state; the exact eviction-ordering requirement cannot be verified from this repository (b12x is an external pinned package). The defect I can show from this repo is the conditional-vs-unconditional registration asymmetry against the two other components that do the same thing.

#4 [high] Research summary

I reviewed PR 231 through the correctness lens: read the full diff, ignition/components/bf16_bmm.py in full, the changed regions of ignition/components/linear.py and ignition/preparation/tuning.py, both new test files, tests/preparation/test_toolchain.py, the supporting native_operator.py, fixtures/projection.py, fixtures/resources.py and fixtures/bf16_gemv.py, and every production caller in ignition/recipes/glm53/mla.py (decode, prefill-slice, and context-parallel slice paths plus their __call__ uses).

One finding worth fixing: in bf16_bmm.py the compile_plan._NATIVE_JITS.add(_bmm_kernel) line sits inside the body of the @program_cache-decorated compile_bmm, so the registration only happens on a program_cache miss — unlike the two other components that do the same thing, which register at module scope unconditionally (moe_sm103.py:357 (not opened),387, sm103_projection.py:258 (not opened)). The move to module scope fixes it.

I also checked and cleared the riskier-looking paths: every caller of BatchedUnquantizedProjection builds 256/512-wide transposed views of scratch buffers, so the new stride and 16-byte-alignment preconditions in query_from_call accept all of them, and flare::bmm_out is now dead code. I did not finish reviewing the import-time _prepare_compiler_toolchain() side effects (which modules now apply runtime patches on import) before time ran out.

#5 [high] Toolchain timing change: what I checked and what is unresolved

CHANGE (ignition/preparation/tuning.py:47-66): _prepare_compiler_toolchain() is now called at module import (line 66), and the two call sites in RecordedPreparationSession.__init__ (old line 118) and in declare() (old line 735, the non-RecordedPreparationSession branch) are removed. The function does two things: runtime_patches.apply() and _set_triton_libdevice_path() under config.patch(emulate_precision_casts=True).

WHAT THIS MEANS NOW: any import of ignition.components.bf16_bmm (line 34: from ignition.preparation.tuning import declare) — and, transitively, of ignition.components.linear (line 22) and therefore every GLM recipe — now applies runtime patches and mutates Torch Inductor's Triton libdevice selection at import time, i.e. in any process that merely imports a component, including CPU-only tooling. Previously this happened on first session construction / first declare().

Notes I was able to confirm:

UNRESOLVED (would need a test or b12x source to settle): whether anything in the repository imports a component module lazily after a Triton compile in a process where the libdevice switch has not yet happened — that is exactly the failure mode the PR describes, and the new ordering closes it for this repo's own imports. What I could not verify from this repo is whether the persistent Triton disk cache can still hold a program compiled against the bundled libdevice from an older Flare version without the identity changing; runtime_patches.identity() is part of the compiled-forward cache key (compilation.py:298-299) and the runtime-patch sources feed it, so bumping the patch files invalidates it — but _set_triton_libdevice_path itself lives in tuning.py, which is NOT part of runtime_patches.identity(), so a process that compiled before this PR and one after share the same identity tag. b12x's own program identity presumably includes the extern_libs hash; I could not confirm that from this repository.

Also worth noting for the report: CI on the head commit (0ba78eb) is failing, and the PR carries a repository-split triage comment (original-el8, 2026-11-24) asking for the BF16 batched-matmul files to move to the hyperflare-recipes repository and only the tuning.py change to remain here. That is a placement question, not a correctness one, but it means the two halves are being reviewed in different repositories.

#3 [medium] Nit: dead flare::bmm_out op, and caller check of the new preconditions

OBSERVATION (nit) — ignition/components/linear.py:89-96: _bmm_out custom op (flare::bmm_out) is now dead. search_code for _bmm_out|bmm_out shows only the definition plus its fake at linear.py:94-96; BatchedUnquantizedProjection.__call__ (line 84-86) and bf16_bmm.State.run (bf16_bmm.py:124-126) no longer reference it, and the cuBLAS path now calls torch.bmm directly. No test covers flare::bmm_out any more. Either delete it or the cuBLAS tactic should go through it (which is what the deleted code did).

CALLERS VERIFIED: the only production user of BatchedUnquantizedProjection is ignition/recipes/glm53/mla.py:244,252-257 (decode/TP1/2/4 with context=None), :321-329 (prefill slices), :340-344 (context-parallel slices), invoked at mla.py:410,423,433,437. In every case source/output are .transpose(0,1) views of scratch rows of width 256/512 BF16 (ignition/recipes/glm53/mla.py:92-99), so rows are 512/1024 bytes and data_ptr() % 16 == 0, and stride(2)==1 — the new query_from_call preconditions (bf16_bmm.py:142-153) hold. GLM's kv_b_proj views (values[:, :256], values[:, 256:], mla.py:242-243) keep a unit stride in weight.stride()[1:] after the k-major transpose, so the weight check holds too. I found no caller that the new stride/alignment rejection would break.