Explore scratchpad · NVIDIA/hyperflare-inference #231

Raw Markdown for agents: https://autobot.eidonix.com/p/b2ae777f-c11a-4562-946b-85be47a8c5fd.md

#1 [high] The change: what PR #231 does, size and files

PR #231 "Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections", author original-el8 (COLLABORATOR), open, base main, head 0ba78eb, 6 files +373/-16, labels area:kernels, area:preparation, enhancement, model:glm-5.3, performance, triage:design-review.

Files (pr_files):

What bf16_bmm.py contains (pr_diff): a flare.bf16_bmm native component. Query dataclass holds tuple of (shape, stride) of source/weight/output. _tactics() returns "cublas" first, then Triton tile tactics from _TILES = ((64,128,64,4,3),(64,256,64,8,3),(128,128,64,8,3),(128,256,64,8,2),(32,128,64,4,3),(16,128,64,4,3),(16,64,64,2,3)) filtered by columns % BLOCK_N == 0, depth % BLOCK_K == 0, BLOCK_M <= max(16, 2rows), 4BLOCK_M >= min(rows,128). A single @triton.jit _bmm_kernel with FP32 acc, single BF16 round on store, masked row tail, grid (row_tiles*col_tiles, G, 1). compile_bmm is @program_cache(scope="preparation"), creates meta tensors via torch.empty_strided, adds _bmm_kernel to b12x compile_plan._NATIVE_JITS (private b12x attribute) so compile workers evict deferred planning entries. State.run falls back to torch.bmm(source, weight, out=output) when program is None (cublas tactic). A torch.library.custom_op("flare::bf16_bmm", mutates_args=("output",)) execute with meta/fake registration taking an int plan handle. query_from_call validates 3D BF16 same-device, matching shapes, source/output row-contiguous (stride(2)==1), weight K- or N-contiguous, all data_ptr % 16 == 0. declare_bmm builds a native_plan with scratch_bytes=lambda t: 0 and compile_jobs, uses fixtures.projection.input_factory plus session.benchmark_storage, and declares a plan with prepare_call + benchmark_call.

linear.py: imports bf16_bmm, BatchedUnquantizedProjection docstring changed, and its inline validation + _bmm_out(source, self.weight, self.output) call replaced by bf16_bmm.declare_bmm(...) in init storing self.plan and bf16_bmm.execute(source, self.weight, self.output, self.plan.handle) in call. The del session, name line removed; shape/dtype validation moved into query_from_call.

tuning.py: _prepare_compiler_toolchain() is now called at module import (added a bare _prepare_compiler_toolchain() call after its definition), and the calls in RecordedPreparationSession.__init__ and in declare() are removed. Docstring reworded.

tests/preparation/test_toolchain.py: parametrization adds "import" session kind, which constructs CUDAOptions() before any session. test_bf16_bmm.py = CPU-only tactic-selection/validation tests. test_bf16_bmm_cuda.py = 5 CUDA tests behind FLARE_RUN_CUDA_TESTS=1: per-tactic ulp<=1 vs torch.bmm, NaN sentinel row-tail masking, and a prepared race + CUDA-graph replay test asserting zero allocation counters and plan has no persistent memory.

#2 [high] Related work: main's repo split (da037284) moved PR #231's files out of core ignition

High-impact: main has completed the recipe split. Commit da037284 (Luke Alonso, 2026-11-22) "Stage hyperflare_recipes separation, slim core ignition, and commit rebuild/hub updates" removed model recipes and components from core ignition: on main, ignition/components/ contains only 14 files (capacity, collectives, completion, engram, flashinfer_sampling, logprobs, ngram_delivery, readiness, sampling, state, state_transfer, vision_delivery, vision_state, init) — no linear.py, no bf16_bmm.py; ignition/recipes/ does not exist on main (list_files ref=main returns no match for ignition/recipes/*).

tests/preparation/test_core_boundary.py on main (head) enforces the boundary: test_ignition_never_imports_recipes_or_hyperflare_recipes asserts hyperflare_recipes dir does not exist and forbids ignition.recipes/hyperflare_recipes modules; also a forbidden-path list ("ignition/recipes", "hyperflare_recipes.recipes", "hyperflare_recipes").

Consequence for PR #231: its new component file ignition/components/bf16_bmm.py and its linear.py wiring are recipe-owned under the split; git grep BatchedUnquantizedProjection on main returns no matches. The PR's own latest comment (original-el8, 2026-11-24 "Repository-split triage") already concedes this: the BF16 batched-matmul implementation, projection wiring and component tests belong in hyperflare-recipes, and only the ignition/preparation/tuning.py toolchain change "can remain here after removing recipe-owned files". AGENTS.md:390-392 states core ignition must never import hyperflare_recipes and mechanisms belong in hyperflare_recipes/components/.

Repo split pointer: README.md:36,49,65 and AGENTS.md:224-225,380-392 point recipe/component work at local-inference-lab/hyperflare-recipes.

Citations: commit da037284; list_files ref=main ignition/components/*; tests/preparation/test_core_boundary.py:40-68; AGENTS.md:390-392; PR comment 2026-11-24.

#3 [high] Change: import-time toolchain preparation is a process-wide side effect, not just session ordering

The only runtime-side change that survives the repo split is moving _prepare_compiler_toolchain() from session construction to module import:

Undeclared consequence: _prepare_compiler_toolchain() calls ignition.runtime_patches.apply(), which (ignition/runtime_patches/init.py:21-22,81-105) hard-fails with PreparationError on any torch != "2.14.1+cu132" or triton != "3.8.0", then imports torch._inductor, patches TorchDynamo/scheduler/functionalization, and calls _set_triton_libdevice_path() (which needs the CUDA toolkit libdevice). Because ~60 component modules from ignition.preparation.tuning import ... (git grep of imports lists essentially every ignition/components/.py, ignition/recipes//*.py, and dozens of test modules), any import of any component now triggers runtime patch installation, version gates and Inductor import at import time, not only in a preparation session. Test file tests/preparation/test_toolchain.py:31-36 skips when CUDA_HOME/libdevice is missing, indicating the import path now requires the toolkit.

The PR description frames the import-time move only as "prepares the compiler toolchain (runtime patches, then the CUDA toolkit libdevice) at import instead of at session construction" and explains the Triton memoization ordering reason; it does not mention the process-wide version gate/patch side effect on ordinary imports.

Citation: pr_diff tuning.py hunks; main tuning.py:53-66,108,804; ignition/runtime_patches/init.py:68-130.

#4 [high] Project fit: charter asks perf PRs for served-workload speedup vs main and op-contract owner approval

Relevant charter lines (read_charter, NVIDIA/hyperflare-inference):

#5 [high] Claims and evidence: kernel wins unbacked in-repo, bitwise claim not tested, served gain disclaimed

Claims in the PR description, and what backs each:

  1. Per-projection kernel speed (GB10, 8192 rows): TP2 absorption 3.53→2.02 ms, TP2 expansion 2.62→2.02, TP4 absorption 1.77→1.00, TP4 expansion 1.27→1.01, against a "plain copy of the same bytes" floor of 1.84/0.93 ms. Evidence in the PR: none attached (no logs, traces, or script); these are the author's numbers, and nothing isolates them from the base state. Backing: consistent with the code (single 64x128x64 tile, FP32 accumulate, no scratch) and with the "about half of copy bandwidth" motivation.
  2. "Every tile is bitwise equal to torch.bmm at the probed GLM shapes on GB10 and RTX PRO 6000; the test contract allows one BF16 ulp." Verified against the test: tests/components/test_bf16_bmm_cuda.py:47-61 asserts max ULP distance <= 1 and that at most 1e-3 of elements differ at all — i.e. the test enforces 1 ULP, not bitwise equality. Bitwise equality is a claim with no test behind it in the diff.
  3. Served-workload gain: "TP2 8,192-token prefill at 2945 tokens/s on two DGX Sparks, against 2620 to 2631 tokens/s for packages without those changes. That difference is not attributed to this PR alone." This is the only served number and the description itself disclaims attribution.
  4. Validation: "test_bf16_bmm.py, test_linear.py and test_toolchain.py passed 23 tests on CPU"; "test_bf16_bmm_cuda.py passed 5 tests on one RTX PRO 6000 (SM120) with an empty Triton cache". Count consistent with the diff (4 parametrized cases + 1 = 5 CUDA tests). No CI evidence: CI on head 0ba78eb is reported failed in the orientation packet.
  5. "Not run on this branch: GB10 tests, the GLM MLA checkpoint test, and SM103." So the headline GB10 win and the end-to-end GLM test ran on an integration branch, not this head.
  6. "Both accumulate in FP32 and round once to BF16, use no scratch, and write the caller's strided output view." Verified in code: single tl.dot(..., acc) FP32 accumulator, one acc.to(...) on store, native_plan(scratch_bytes=lambda t: 0), and the Triton launch takes the caller's strides (bf16_bmm.py:88-140). The CUDA test also asserts plan has no persistent memory and CUDA-graph replay allocates nothing (test_bf16_bmm_cuda.py:87-114).
  7. "Packages export the tuned choice; no package metadata or Helios code changes." Consistent with the diff (no Helios, no protobuf, no packaging files touched) — implies re-export is needed for existing packages to pick the new tactic.

#6 [high] Community: three comments, all by the author; no reviews, approvals or reactions

3 comments on PR #231, all from original-el8 itself (the packet says "Reviews: none yet"; there are no human reviews, approvals or change requests, and no reactions recorded):

Interest so far: none from other people. No reviewer, no reaction, no linked issue. (Orientation: opened 2026-11-08, last updated 2026-11-24, CI failed on head.)

#7 [high] Related work: #471 rewrites the same class with the opposite stride policy; #509 supersedes part of the toolchain story

#8 [high] Change: stricter operand preconditions and stride-keyed plans are not in the description

Undeclared or under-declared behaviors found in the diff (beyond the description's "Behavior" bullets):

  1. Operand validation became stricter for existing callers. BatchedUnquantizedProjection previously did torch.bmm on whatever 3-D BF16 stacks it was given (only checking shapes/dtype/device, main linear.py:76-92 area per the removed lines). Its replacement query_from_call (bf16_bmm.py:140-152) now raises ValueError unless: source and output have stride(2) == 1, the weight is K- or N-contiguous, and every operand's data_ptr() % 16 == 0. Any caller or recipe that passed a transposed/oddly strided stack now fails at construction instead of running. This is a new precondition for a class used by GLM's MLA absorb/expand (ignition/recipes/glm53/mla.py:244,252-257,321-329,340-344) and, per #471, by Kimi K3/K3.1. Nothing in the description mentions the new alignment/contiguity contract or the ValueError.
  2. The PR mutates a b12x private global from component code: compile_plan._NATIVE_JITS.add(_bmm_kernel) inside compile_bmm (bf16_bmm.py:108). The description mentions this ("registers itself in b12x's _NATIVE_JITS") but not that it is a private, undocumented b12x attribute; the same trick already exists on main in ignition/components/moe_sm103.py:357,387 and sm103_projection.py:258, so it is an established, if fragile, pattern rather than a new invention.
  3. A new custom op flare::bf16_bmm (mutates_args=("output",)) and a new native tuning contract component flare.bf16_bmm with NativeConfig/tactic schema are added. The old flare::bmm_out custom op in linear.py (lines 89-96) is left defined but unreferenced by BatchedUnquantizedProjection afterwards (still defined; no other user in the tree).
  4. The toolchain helper is now executed at import of ignition.preparation.tuning (see separate note: process-wide runtime_patches.apply() with torch/triton version gates).
  5. Contact-surface subtlety: the plan query is keyed on exact shapes and strides of all three operands, so each distinct stride layout (and each prefill row-slice offset) is a separate plan and tuning entry; the GLM prefill path declares absorb/expand per row slice (mla.py:321-329, 340-344), so a long chunk multiplies plan count. Not mentioned in the description.

#9 [high] Process: 18 days old, frozen code, unresolved conflict, CI failed, design-review unstarted

#12 [high] Reach: one model family's BF16 path, re-export needed, new op contract and private b12x imports

What is touched and who feels it:

#10 [medium] The why: no linked report; SM103 counterpart worked in October; GLM perf tracker names other bottlenecks

The problem being solved, as stated and as evidenced:

#11 [medium] People: author is Jason Cook/original-el8, a charter priority contributor and the area's prior owner

Author identity and history:

#13 [medium] Recent activity: repo split and tuning-session restructuring postdate the branch by 2.5 weeks