Subtraction & Simplicity Audit — PR #732 (helios,heliopause,ignition: add FP8_E4M3_GLOBAL single-plane engram table support, head 02ba762)
Verdict: the wire additions are lean — one enum value, one match arm per layer, no new CLI flags, no new exporter path, no native-reader change (Fp8E4m3Global appears in exactly two non-test production sites: helios/src/core/schema.rs:453,567 and helios/src/runtime_core/engram.rs:159). But the change ships a duplicated mode→tensor-shape map in Python, duplicated encoding→row-bytes arithmetic across two crates, and ~170 lines of test code that re-derive fixtures already present in the same files. Concrete, high-signal reductions below.
1. HIGH — the same mode→(weight, scale, scale₂) mapping is written twice, and the extraction the description claims is missing
ignition/components/ngram_delivery.py:105-114 (in _lookup) and :136-144 (in PreparedPLELookup.__init__) are the same three-way branch:
105 mode = state.query.quant_mode
106 if mode == "bf16":
107 state.run_lookup(weight.view(torch.bfloat16), None, None, ids, count, out,
...
109 elif mode == "fp8_e4m3_per_tensor":
110 state.run_lookup(weight.view(torch.float8_e4m3fn), scale, None, ids, count, out,
...
112 else:
113 state.run_lookup(weight, scales.view(torch.float8_e4m3fn), scale, ids, count, out,
136 mode = caps.quant_mode
137 if mode == "bf16":
138 lookup_weight, lookup_scale, lookup_scale_2 = self.weights.view(torch.bfloat16), None, None
139 elif mode == "fp8_e4m3_per_tensor":
140 lookup_weight, lookup_scale, lookup_scale_2 = self.weights.view(torch.float8_e4m3fn), table.scale, None
141 else:
142 lookup_weight = self.weights
143 lookup_scale = self.scales.view(torch.float8_e4m3fn)
144 lookup_scale_2 = table.scale
search_code over the PR head for _ple_lookup_planes returns zero matches, so the description's "Extracts _ple_lookup_planes(mode, weight, scales, scale) shared by PreparedPLELookup and flare::staged_ple" is not in the tree — the duplication the bullet says it removed is still present, now as two copies of a three-mode switch instead of one NVFP4 path.
Subtraction — one helper used by both sites:
def _ple_lookup_planes(mode, weight, scales, scale):
if mode == "bf16": return weight.view(torch.bfloat16), None, None
if mode == "fp8_e4m3_per_tensor": return weight.view(torch.float8_e4m3fn), scale, None
if mode == "nvfp4_group16": return weight, scales.view(torch.float8_e4m3fn), scale
raise ValueError(f"unsupported PLE quant mode {mode!r}")
This also fixes, at one site instead of two, the defect that the last branch is a bare else (:112, :141): an unknown quant_mode silently takes the NVFP4 path and dereferences scales at :113/:143, which is None for single-plane tables (:132 sets self.scales = None if table.scales is None else ...). Making "nvfp4_group16" explicit is fewer lines than the current else and removes the crash. _lookup and __init__ then differ only in which tensor triple they pass; the run= lambda at :155 and the _lookup(...) call at :190 stay unchanged. The module already has a precedent for a named validating helper: _validate_staged_heads at ignition/components/engram.py:90.
2. HIGH — encoding→row-byte geometry is now computed twice, in two different crates
helios/src/core/schema.rs:561-571:
let single_plane_row_bytes = if table.encoding == wire::engram_table::Encoding::Bf16 as i32 {
Some(
u64::from(table.embedding_width)
.checked_mul(2)
.ok_or_else(|| invalid("BF16 engram row width overflow"))?,
)
} else if table.encoding == wire::engram_table::Encoding::Fp8E4m3Global as i32 {
Some(u64::from(table.embedding_width))
} else {
None
};
helios/src/runtime_core/engram.rs:150-167 (same PR, same commit) re-derives the identical quantity with the identical ×2 vs ×1 rule:
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)
}
The FP8 arm is the BF16 arm minus checked_mul(2); and the two crates now encode the same elements-per-row→bytes-per-row table. The description claims it "consolidates single-plane row-byte geometry in runtime_core::engram" — no shared helper exists (single_plane occurs only at schema.rs:561,578,622).
Subtraction: add one pub fn engram_plane_row_bytes(encoding: i32, width: u32) -> Result<Option<u64>> beside engram_encoding_has_scales (schema.rs:445) and engram_scales (:460) — helpers the sibling crate already imports across the boundary (heliopause/src/export/core.rs:108,131,1556,1598), and runtime_core/engram.rs already imports from crate::core::schema (:35,:45,:59), so both call sites become two-liners. That also folds the two duplicated guards (is_finite() && > 0.0 here, to_bits() == 0 there) into one place, and lets the two single-plane match arms collapse into one parameterised by element bytes (~12 lines).
3. MEDIUM — schema.rs:504-512: three-branch chain, duplicated error string, as i32 instead of the enum
} 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"));
}
} else if !(table.global_scale.is_finite() && table.global_scale > 0.0) {
return Err(invalid("FP8 global engram table requires a finite positive global scale"));
}
Same message at :505 and :508; the shape exists only because Bf16 rejects any nonzero scale while FP8 requires a finite positive one. The body claims it "exhaustively matches the decoded Encoding enum once in validate_engram" — the code actually compares table.encoding == ... as i32 three times (:506, :561, :567). One match Encoding::try_from(table.encoding) returning NoPlane | GlobalScale(f32) | BlockScale expresses all three cases in one place and removes every as i32 comparison.
4. MEDIUM — the new schema test re-implements the BF16 test 100 lines above it
helios/src/core/schema.rs:2068-2167 (validates_single_plane_fp8_global_engram_table) duplicates :1945-2065 (bf16_identity_single_plane_engram_validation): same catalog.insert(&descriptor(1..4)) (:2074-2077 vs :1951-1954), same use_ closure (:2078-2085 vs :1955-1962), same assert_err closure (:2117-2120 vs :1991-1994), same with_scales / with_scale_buf / bad_size / partitioned / bad_shard_bytes cases. The only genuinely new assertions are the four-value loop for bad_scale in [0.0f32, -0.25, f32::NAN, f32::INFINITY] (:2122-2126) and the byte factor (rows * u64::from(width) vs * 2, :2072-2073).
Subtraction: one table-driven test over [(Encoding::Bf16, 2, 0.0), (Encoding::Fp8E4m3Global, 1, 0.25)], running the negative-scale loop only for the case that can fail — ~25 net lines instead of ~100, and the two encodings' contracts become visibly identical in one place.
5. MEDIUM — runtime_core/engram.rs:1162-1235 builds a second bespoke fixture next to one 40 lines up
fp8_global_single_plane_tables_decode_shared_and_partitioned carries an inline make(global_scale, width, partitioned) closure that mutates a decoded fixture field-by-field (:1173-1214): sets encoding/width/scale_block/global_scale, clears scale buffer, rebuilds hash arrays, hand-builds two shards, then hand-patches the engram_1_weights buffer's shape/strides/nbytes and retains away engram_1_scales. The immediately preceding nvfp4_tables_accept_width_128_and_160_and_reject_unaligned_widths (:1111-1159) already has a make(width, row_bytes, scale_bytes) closure doing exactly that buffer patching, and bf16_identity_single_plane_decodes_and_enforces_strict_contract (:868) already covers the no-scales path. make is also called three times (:1218, :1223, :1229) rebuilding identical fixtures just to vary one scalar — a for (global_scale, partitioned) in [...] loop is ~8 lines instead of ~20.
6. LOW — heliopause/src/export/core.rs test additions are positional and hand-offset
:3910—for (partitioned, bf16) in [(false, false), (true, false), (false, true), (true, true)]is a hand-enumerated product of two bools; nested loops give the same coverage with no table to keep in sync. (And the PR does not extend this loop to FP8, so the FP8 hardlink-reuse gap stays untested — a subtraction the PR leaves on the table.):4641-4648—if bad_idx % 2 == 0 { .tables[bad_idx].scales = ... } else { .tables[bad_idx].shards[0].scales = ... }encodes "even index = shared, odd = partitioned" as index arithmetic. Listing pairs directly ([(2, false), (3, true), (4, false), (5, true)]) removes an invariant the reader must reconstruct from the fixture order at:4555-4595.:4557-4595, :4606-4611— three new hardcoded payload offsets (13064,13080,13088) with eachnbyteswritten twice (once in theSpan, once in the(offset, name, nbytes)list). This shape is inherited from the BF16 case, so the PR doubles existing debt rather than fixing it; one[(name, bytes)]slice walked to build both the file writes and the spans removes the coinciding-constant coupling.
Confirmed lean — no subtraction warranted
- No new CLI flags, config knobs, or env vars.
--embedding-table-storage disk|ramalready existed (docs/cli-design.md:767(not opened)); this PR adds none. - No new exporter path and no native reader change.
heliopause/src/export/core.rsproduction code is untouched — onlypayload_export_testschanged — precisely becauseengram_scales(core.rs:108,131) already handles the single-plane case generically. - No dead or unreachable branches introduced; every new arm is reachable and exercised.
ignition/preparation/runtime_core_pb2.py+112/−112 is purely regenerated descriptor bytes plus the protoc bump at:5(7.35.1 → 7.36.2); nothing hand-edited, nothing to simplify.tests/components/test_ngram_delivery.pyis one parametrised test over three modes (:29-35) — appropriate sizing for its coverage, though (per finding 1) it never exercises an unsupported-mode rejection, and the description's "10 passed" cannot come from this single file.
Summary table
| # | Site | Kind | Est. lines saved |
|---|---|---|---|
| 1 | ignition/components/ngram_delivery.py:105-114, 136-144 |
duplicated map + bare-else crash path |
~10 (and fixes a real defect) |
| 2 | helios/src/core/schema.rs:561-571 ↔ helios/src/runtime_core/engram.rs:150-167 |
duplicated encoding→row-bytes arithmetic across crates | ~15 |
| 3 | helios/src/core/schema.rs:504-512 |
three-branch chain, duplicated error string, as i32 vs enum match |
~6 |
| 4 | helios/src/core/schema.rs:2068-2167 |
test copies :1945-2065 |
~75 |
| 5 | helios/src/runtime_core/engram.rs:1162-1216 |
second bespoke fixture builder beside :1113 |
~30 |
| 6 | heliopause/src/export/core.rs:3910, 4641-4648, 4557-4611 |
positional bool/index coupling, doubled hardcoded offsets | ~10 |
Two of these (#1, #2) are cases where the PR description asserts a consolidation was done and the tree shows it was not; #1 additionally leaves an unguarded else that dereferences a possibly-None scales tensor. None of the requested functional behaviour is lost by any reduction above.