Subtractive scratchpad · NVIDIA/hyperflare-inference #231

Raw Markdown for agents: https://autobot.eidonix.com/p/23fedf74-256e-425a-b77b-a0a8c48ee3c6.md

#1 [high] Blocking: PR body of work belongs in hyperflare-recipes, not this repo (≈350 lines)

The repository moved after this PR's base (91cfb369). On main today:

So of the 6 files, four are recipe-owned and should leave this repo entirely:

≈349 added lines leave; the PR in this repo reduces to the ~9-line ignition/preparation/tuning.py change plus its 6-line tests/preparation/test_toolchain.py addition. Also: the description's justification for the tuning.py change is explicitly "The new component's CUDA tests compile per-tactic kernels before their race test in one process and need this ordering" — once those tests move out, the stated reason for the runtime change does not rest on anything in this repository (though docs/TODO.txt:185-187 on main does record the same libdevice/program-key problem generally, so the change is not unmotivated).

#2 [high] Should fix: dead flare::bmm_out custom_op left behind (8 lines)

ignition/components/linear.py:89-96 — the change deletes the only caller of flare::bmm_out:

Verified no other consumer anywhere: search_code "_bmm_out|bmm_out" returns only linear.py:89-95 and the unrelated sm103_bmm_out (linear.py:452,463-470, still used by BatchedQuantizedProjection). bmm_out in tests/ → no matches; in helios/ → no matches; in docs/ → no matches. Nothing registers or calls flare.bmm_out.

Smaller version: delete lines 89-96 entirely (8 lines), including @_bmm_out.register_fake. Nothing is lost: BatchedUnquantizedProjection no longer calls it, and torch.bmm is still reachable inside bf16_bmm.State.run (bf16_bmm.py:125) for the cuBLAS tactic.

Note this deletion belongs in this change either way: if the component moves to hyperflare-recipes, linear.py moves whole; if the component stays here, the op is dead code left behind by the diff.

#6 [high] Research summary

Reviewed PR #231 with a subtraction lens: read the diff, all six changed files in context, the only caller (ignition/recipes/glm53/mla.py), the helpers it could reuse, and the repository rules (AGENTS.md, docs/design-review.md, docs/core-design.md, docs/TODO.txt, tests/preparation/test_core_boundary.py) both at the PR head and on main.

The dominant finding is that most of this PR no longer belongs in this repository at all. main has moved to a split layout: AGENTS.md:385-392 limits ignition/components/ to an explicit set of 13 Helios-ABI modules, tests/preparation/test_core_boundary.py:62-64 enforces that set exactly, and ignition/recipes no longer exists. Four of the six changed files (bf16_bmm.py, linear.py, and both new test files, ≈349 added lines) are recipe-owned model execution, and the maintainer's own 2026-11-24 triage on the PR says the same thing and asks for only the ignition/preparation/tuning.py change to remain here.

Below that, I recorded four code-level subtractions worth ≈20 lines: the diff leaves flare::bmm_out (linear.py:89-96) with no remaining caller anywhere in the repo; State.run re-validates shapes and strides that query_from_call already fixed when the plan was declared; declare_bmm re-implements fixtures/bf16_gemv.benchmark_call; and two of the new assertions prove nothing (a tautological tile-width test and a redundant ULP-fraction threshold). Details, line counts, smaller versions and citations are in the scratchpad.

Not counted as savings: the CUDA kernel itself, the _TILES table and the _NATIVE_JITS registration are GPU kernel code, where the charter permits only concrete defects — I found none to report and proposed no redesign.

#7 [high] Totals, ranking, and what I examined and did NOT cut

Diff arithmetic (from pr_files / pr_diff)

6 files, +373 / −16.

Additions total 373; removed 16. New test lines total 166; new component lines 184.

Ranking by lines saved

  1. Blocking — ≈349 added lines. Scope-to-other-repo (scratchpad entry 1): bf16_bmm.py (184) + linear.py changes (17) + both test files (166) = 367 gross; counted as ≈349 net additions after the 17-line linear.py churn (8 added are reworked, 9 genuinely removed). In this repo the PR shrinks to +9 −5 (tuning.py) and +6 −2 (test_toolchain.py).
  2. Should fix — 8 lines. Dead flare::bmm_out (entry 2).
  3. Should fix — 5 lines. State.run revalidation (entry 3).
  4. Nit — 5 lines. declare_bmm duplicates fixtures/bf16_gemv.benchmark_call (entry 4).
  5. Nit — 4 lines. Tautological test + redundant assertion (entry 5).

Sum of the code-level savings inside the component: ≈22 lines (8+5+5+4). Against 373 added lines that is ~6% — the component is compact for what it does; the size problem is location, not padding.

Examined and NOT cut (so the report can say what is already minimal)

Dropped candidates (could not show from the code)

#3 [medium] Should fix: State.run revalidates strides query_from_call already enforced (5 lines)

ignition/components/bf16_bmm.py:119-123 — State.run re-validates shapes and strides on every call:

def run(self, source, weight, output):
    tensors = (source, weight, output)
    if any((tuple(t.shape), tuple(t.stride())) != declared
           for t, declared in zip(tensors, self.query.operands, strict=True)):
        raise ValueError("batched projection operands differ from the declared stacks")

Every caller already guarantees this by construction:

Smaller version: drop the check, leaving

def run(self, source, weight, output):
    if self.program is None:
        torch.bmm(source, weight, out=output)
        return
    args, options, _, grid = _launch((source, weight, output), self.tactic)
    self.program[grid](*args, *options.values())

Saves 5 lines and one tuple-of-tuples comparison per launch, which sits in the captured hot path (the graph replays this per layer). Nothing lost: a mismatched call already cannot be declared, and the compiled program is specialized to the declared strides anyway.

#4 [medium] Nit: declare_bmm duplicates fixtures/bf16_gemv.benchmark_call (5 lines)

ignition/components/bf16_bmm.py:176-179 repeats an existing helper almost line for line.

The repo already has ignition/preparation/fixtures/bf16_gemv.py:10-16:

def benchmark_call(state, *, inputs, weight, bias):
    operands = inputs()
    return PreparedCall(
        run=lambda: state.run(operands.source, weight, out=operands.output, bias=bias),
        produce=operands.produce, output=operands.output,
        owners=(operands, weight, bias),
    )

and ignition/components/linear.py:139-145 already consumes it that way (partial(bf16_fixtures.benchmark_call, inputs=input_factory(...), weight=weight, bias=bias)).

This PR instead writes a private closure in declare_bmm with the same body:

def benchmark(state):
    operands = inputs()
    return PreparedCall(run=lambda: state.run(operands.source, weight, operands.output),
                        produce=operands.produce, output=operands.output, owners=(operands, weight))

Smaller version: give State.run the shared keyword signature (def run(self, source, weight, *, out, bias=None)), then

declare(session, (plan.request(name=name,
    prepare_call=lambda state: PreparedCall(run=lambda: state.run(source, weight, out=output)),
    benchmark_call=partial(bf16_gemv.benchmark_call, inputs=inputs, weight=weight, bias=None)),))

Saves the 4-line closure plus one local lambda per call site (~5 lines) and uses the helper the rest of linear.py uses. Behaviour identical — bf16_bmm takes no bias, so bias=None matches today's 2-tuple owners (the extra None owner is what UnquantizedProjection already passes).

#5 [low] Nit: one tautological test and one redundant assertion (4 lines)

Two small dead/duplicate test assertions in the new files:

  1. tests/components/test_bf16_bmm.py:31-33, test_expansion_stacks_exclude_column_tiles_wider_than_the_output, is tautological: the only filter _tactics applies to columns is columns % tile[1] == 0 (bf16_bmm.py:55), and for the "k" stacks the output width is 256, so tiles of 512 columns are excluded by arithmetic. The assertion can never fail while _tactics is columns % tile[1] == 0. The name also says "expansion" but nothing distinguishes major="k" there except the caller's fixture widths. Deleting the test saves 3 lines (32-33 plus its blank line); the columns % tile[1] == 0 rule is already covered by the parametrized test at line 27.

  2. tests/components/test_bf16_bmm_cuda.py:63, assert (distance > 0).float().mean() <= 1e-3, is a third numerical check on the same comparison. Line 62 already bounds distance.max() <= 1 and line 64 bounds the error against the FP64 reference by cuBLAS's own error; a fraction threshold adds a statistic, not a behaviour, and the PR description states the tiles are bitwise equal at the probed shapes (i.e. the fraction is 0). The sentinel/isfinite checks (lines 59-60) are the distinct row-tail behaviour and stay. Deleting line 63 saves 1 line.

Keep: lines 59-60 (row-tail masking via NaN sentinels), 62 and 64 (contract: one BF16 ulp, and no worse than cuBLAS against FP64).