Subtraction & Simplicity Audit — PR #732 (FP8_E4M3_GLOBAL single-plane engram)
Bottom line
The format/production code is genuinely lean — I am not asking for deletions there. The PR adds one enum tag, one validation branch, one decode arm, and zero lines of FP8-specific export code (it rides #664's schema::engram_scales seam). That is the right shape.
Three of the four changed areas still carry copy-paste that the new encoding made visible. The net recoverable size is small (~60–80 lines out of +565/−145), but two of the duplications are the exact kind that produce divergent validation messages, so they are worth fixing now rather than in a follow-up.
One honesty note on method: pr_diff on this PR diffs against a stale pre-#664 base (it renders #664's and #711's merged work as if #732 added it), and search_history errors out on a missing object (c513e46a). I therefore read the real delta from ref: pr/732 and attributed BF16 branches to #664 (merged) rather than to this PR.
1. Collapse the two single-plane decode arms — helios/src/runtime_core/engram.rs:150-167
The two arms differ in exactly three respects: a *2, a different overflow message, and which half of the global_scale contract is enforced.
wire::engram_table::Encoding::Bf16
if table.embedding_width > 0 && table.global_scale.to_bits() == 0 =>
{
let row_bytes = usize::try_from(table.embedding_width)
.ok()
.and_then(|width| width.checked_mul(2))
.ok_or_else(|| invalid("BF16 embedding row width overflow"))?;
(table.embedding_width, 0, row_bytes, None)
}
wire::engram_table::Encoding::Fp8E4m3Global
if table.embedding_width > 0
&& table.global_scale.is_finite()
&& table.global_scale > 0.0 =>
{
let row_bytes = usize::try_from(table.embedding_width)
.map_err(|_| invalid("FP8 global embedding row width overflow"))?;
(table.embedding_width, 0, row_bytes, None)
}
Both produce (width, 0, row_bytes, None). Collapsing to Fp8E4m3Global | Bf16 with bytes_per_element = 1 | 2 is ~9 lines instead of 18, and the guard becomes data (Ok(bytes) | Err(_)) instead of a duplicated if. Note also that both overflow guards are unreachable on any 64-bit target (u32::MAX * 2 < 2^33), so the two distinct messages "BF16 embedding row width overflow" / "FP8 global embedding row width overflow" are two unreachable strings defending the same non-event — a single usize::try_from(width).ok().and_then(...) covers both 32- and 64-bit.
2. The Python three-way quant_mode dispatch is duplicated verbatim — ignition/components/ngram_delivery.py:106-114 vs 137-144
This PR adds the second copy of the fp8_e4m3_per_tensor branch. The two copies must stay in lockstep or the pre-declared plan (line 145) will disagree with what run_lookup is actually called with at execution time:
# _lookup (106-114) # PreparedPLELookup.__init__ (137-144)
if mode == "bf16": if mode == "bf16":
... .view(torch.bfloat16), None, None lookup_weight, lookup_scale, lookup_scale_2 = self.weights.view(torch.bfloat16), None, None
elif mode == "fp8_e4m3_per_tensor": elif mode == "fp8_e4m3_per_tensor":
... .view(torch.float8_e4m3fn), scale, None ... .view(torch.float8_e4m3fn), table.scale, None
else: else:
... scales.view(...), scale lookup_scale = self.scales.view(torch.float8_e4m3fn) ...
Extract one module-level helper — _lookup_views(mode, weights, scales, scale) -> (weight, weight_scale, weight_scale_2) — and call it from both. That is ~8 lines removed, one fewer invalid state, and the two call sites become impossible to drift.
Related, adjacent to this PR's growth: the file now reads quant_mode from two different objects — caps.quant_mode (line 136) in __init__ and state.query.quant_mode (line 105) in _lookup. If those caps came from the same plan they could not disagree; worth a one-line confirmation from the author in review rather than a code change I can justify from the diff alone.
3. The new test is three assertions where one would do — tests/components/test_ngram_delivery.py:29-35, 80, 86, 104-131
135 lines for one behavioural claim. Concretely droppable:
has_scalesandscale_dtypeare dead parameters. They are passed at29-35and used only at80/86to build the fixture — andscale_dtype is Noneis true exactly whenmode == "bf16". So two of six columns are restatements of the first. The other three columns (row_bytes,expected_weight_dtype) are likewise constant per mode and could live inside a mode→fixture dict.- The
(weight, weight_scale, weight_scale_2)triple is asserted three times: the prepare-path run closure is never checked (only its plan arguments at108-115), then120-131re-checks the same triple fromseen_lookups[0]. Dropping the last block (if expect_scale_2: ... elif mode == "fp8_e4m3_per_tensor": ... else:) removes ~11 lines and loses no coverage, sincew_dtype == expected_weight_dtypeandtok_countare the only facts there not already asserted upstream. w_scaleis unpacked but unused (121,_), a tell that the block is redundant.
4. The new Rust tests clone their siblings instead of extending them — helios/src/core/schema.rs:2068-2167, helios/src/runtime_core/engram.rs:1162-1235
validates_single_plane_fp8_global_engram_table (2068) is the BF16 test that ends at 2065 with encoding/global_scale swapped. Verbatim duplication:
- the
assert_errclosure —2068's is character-identical to1991-1994; - the two-shard partitioned fixture —
2144-2161is2024-2041withnbytesre-derived; - a literally duplicate assertion:
2128-2130(scale_block = 16→"cannot carry scale metadata") re-tests what2008-2010(scale_buffer→ same message) already covers, sinceschema.rs:504ORs the two conditions into one error. That assertion can never fail independently and should go.
Same pattern in engram.rs: fp8_global_single_plane_tables_decode_shared_and_partitioned (1162) rebuilds a make(|global_scale, width, partitioned|) closure whose body is a near-copy of the existing make(|width, row_bytes, scale_bytes|) at 1113-1146, including the three buffer-geometry lines at 1212-1214 vs 1135-1137. Including the encoding in the existing make and adding a global_scale argument would merge both tests at roughly net-negative line count.
5. engram_scales already collapses the pair; validate_engram should match it — helios/src/core/schema.rs:504-512, 561-571
This PR puts the new encoding in the good group at 443-457 (engram_encoding_has_scales), which lets engram_scales (460-471) express plane present ⟺ encoding needs it in one expression. But validate_engram still hand-inlines the same predicate twice, and the two adjacent branches now need the same message:
} else if !table.scale_buffer.is_empty() || table.scale_block != 0 {
return Err(invalid("single-plane engram table cannot carry scale metadata"));
} else if table.encoding == wire::engram_table::Encoding::Bf16 as i32 {
if table.global_scale.to_bits() != 0 {
return Err(invalid("single-plane engram table cannot carry scale metadata"));
}
Folding the BF16 global_scale.to_bits() != 0 test into the preceding || collapses two branches and one duplicate string into one condition. Separately, single_plane_row_bytes (561-571) is a 4-branch if/else if/else over a minted Option<u64> whose Some-side overflow guard (566) is unreachable as noted in §1; the guard reduces to u64::from(table.embedding_width) * u64::from(stride) once the arm is chosen.
6. One predicate, two copies — schema.rs:504-505 vs engram.rs:204-206
The same rule is stated twice with different words for the same user-visible failure:
helios/src/core/schema.rs:505—"single-plane engram table cannot carry scale metadata"helios/src/runtime_core/engram.rs:205—"single-plane Engram table cannot carry scale bindings"
engram_encoding_has_scales/engram_scales already live in schema.rs and are already imported by engram.rs:35,45,59, so a schema::single_plane_bindings(table, &scales) -> Result<()> next to them would be a drop-in for both. Note the decoder copy (204) is dead for any core that passed validate_engram — it is defence in depth, which is fine, but it does not need its own wording.
7. What is already lean — do not touch
heliopause/src/export/core.rsadds no FP8 code path at all. The +74/−7 iswire::EngramTablefixture data (4560-4596), six filename entries (4609-4611), andinstalled.len()12(4636). The production routing at108/131/421/436/1556/1598is #664's and unchanged. Nothing to subtract — this is the seam working as designed.- Docs:
docs/core-format-design.md:94-95andhelios/manifest.md:526-528(not opened) are two-line, in-place edits. Correct, minimal. - Protos:
helios/proto/core.proto:269andruntime_core.proto:665are additive tag appends;runtime_core_pb2.py(not opened) (+112/−112) is generated descriptor churn, not hand-written. No knobs, flags, config keys or defaults are added anywhere in the PR — verified againstignition/components/ngram_delivery.pyandhelios/src/core/schema.rs, which gain no new public entry points beyond the enum value. - No dead/unreachable feature branches:
Unspecifiedstill has one live path (engram.rs:29-34legacy-fixture normalisation), untouched here.
One maintainability note rather than a deduction: the new encoding's contract is now stated in prose in three places — core.proto:267-268, runtime_core.proto:663-664, and helios/manifest.md:526-528 (not opened). That triplication is pre-existing, but it is exactly what let the PR body's tag numbers drift to FP8_E4M3_GLOBAL = 3 … BF16 = 2 when the code has = 4 … = 3. Single-sourcing the comment (cite manifest.md (not opened) from the protos) would have caught it.
Recommended asks, in priority order
| # | Where | Ask | Est. saving |
|---|---|---|---|
| 1 | ngram_delivery.py:106-114 + 137-144 |
One _lookup_views(mode, …) helper |
~8 lines, removes a drift class |
| 2 | engram.rs:150-167 |
Merge the two single-plane arms | ~9 lines |
| 3 | schema.rs:504-512 |
Fold BF16 global_scale guard into the ` |
|
| 4 | test_ngram_delivery.py |
Drop has_scales/scale_dtype columns and the 120-131 re-assert |
~15–20 lines |
| 5 | schema.rs:2068 / engram.rs:1162 |
Extend the BF16 tests' existing fixtures rather than cloning them | ~40–50 lines |
| 6 | schema.rs:505 vs engram.rs:205 |
One shared predicate + one message | consistency |
None of these is a correctness bug, and #732 should not be blocked on them — but #1 and #2 are cheap enough that they belong in this PR while the seam is fresh, and #6 prevents the decoder and the validator from describing the same rejection differently to operators.
Overall: the diff is lean where it counts (format, export, docs) and repetitive where it does not (tests, the mode dispatch, the second single-plane arm). Ship-able; polishable in an hour.