Subtractive report · NVIDIA/hyperflare-inference #483

Raw Markdown for agents: https://autobot.eidonix.com/p/fb79958e-84e2-4268-a78c-7be5516d771d.md

Subtraction review of PR #483 — "Add Gemma 4 image preparation, Bracketed patch-width metadata, and atomic spans"

Head ab9a432, base main 27716185, 38 files, +2490 / −251 (pr_files).

Key findings

This is two changes stapled together. One half is a real, small fix: make Bracketed patch width and merge stride come from the prepared contract instead of a hardcoded 2×2 / 1176 table, and emit atomic spans from layouts::bracketed. That half fixes a genuine defect on main and is worth roughly 1,280 lines. The other half — an entire Gemma 4 image profile — has no consumer in this repository and is roughly 1,210 lines, 49% of the diff. The charter requires new formats to "prove they export and serve cleanly from the PR branch" (read_charter, roadmap item #74), and the PR's own docs/TODO.txt:331-337 lists exactly that work as not yet done.

Everything else below is ordinary duplication: a hand-rebuilt test manifest, an 11-row profile table that repeats existing tests, unread fixture keys, and two tests that restate fixture cases already pinned by SHA-256.

Totals: ~1,514 lines removable (61% of the diff) if the profile is deferred; ~304 lines (12%) if it is kept.


1. Blocking — the Gemma 4 image profile has no in-tree consumer (~1,210 lines)

Files and sizes (pr_files added-line counts):

What goes: the whole Gemma4 preparation kind and its fixture set. What replaces it: nothing today.

Why nothing is lost:

Smaller version: land the shared Bracketed fix; move gemma4.rs, the two tests/frontend/gemma4* fixture files, tests/preparation/test_frontend_gemma4.py and frontend.py:114-173 to the companion recipe PR that declares vision.patch_features = 768, where they can be qualified against a real export.


2. Should fix — model/tests.rs:1277-1452 rebuilds testing::manifest by hand (~110 lines)

legacy_bracketed_core_omitting_patch_features_loads_and_stages_1176_wide_pixels is 177 added lines. Inside it:

What replaces it: crate::model::testing::manifest (helios/src/model/testing.rs:242), with one GraphOperation::Vision => GraphKind::Vision arm at testing.rs:344-355 (currently _ => unreachable!()) and the existing _ => 1 width at :257 extended to size vision_pixel_values from vision.bracketed_patch_features(). That removes :1304-1411 entirely.

Alternatively, drop the manifest half altogether: the load behaviour under test is square_merge_side/bracketed_patch_features via Inputs::new (helios/src/model/packing.rs:92-102), and packing.rs:594-682 already asserts all three arithmetic outcomes (768 accepted, 0 → 1176, non-square rejected) without a manifest. Keep only the serde-default assertion at :1334-1338.

Why nothing is lost: the assertions stay; only the hand-rolled fixture construction goes. Saving ~110 lines.


3. Should fix — packing.rs:684-814 11-row profile table repeats existing coverage (~110 lines)

processor_patch_features_match_tensor_layout_for_every_profile builds a Vec<(ImageSettings, ImageLimits, ImageLayoutKind, usize, usize)> with 11 rows (Qwen, Mimo, Glm, PatchMerge, PaddedGrid, Deepseek4, DeepseekRowMajor, Moonvit, Step, Radio, Gemma4) and asserts one width per row.

Those widths are already asserted twice elsewhere: helios/src/frontend/images/conditioned.rs:329-363 and :428-504 (valid_processed compares images.pixel_values.len() == patches * processor.patch_features()), and helios/src/model/packing.rs:92-102 rejects a mismatched buffer at Inputs::new.

What replaces it: four rows — Glm 1176, PatchMerge 1176/Bracketed/0, PaddedGrid 1200/ClassToken, Gemma4 768/9 — which are the only ones carrying a distinct outcome. The genuinely new test directly above (bracketed_packs_3x3_metadata_widths_and_rejects_invalid_extents, :594-682) stays untouched.

Why nothing is lost: every distinct arithmetic path (nonzero width, legacy 0 → 1176, non-square rejection, non-Bracketed unaffected) is exercised by the surviving rows; the deleted seven rows only restate per-profile constants. Saving ~110 lines.


4. Should fix — tests/frontend/gemma4_images.json provenance blocks carry keys nothing reads (~75 lines)

ignition/preparation/frontend.py:114-141 reads exactly: processor_class, image_processor (image_processor_type, patch_size, pooling_kernel_size, do_resize, do_rescale, do_normalize, image_mean, image_std, optional resample/rescale_factor/do_convert_rgb, max_soft_tokens), model_type, vision_config.model_type / patch_size / pooling_kernel_size, and the three token ids. tests/preparation/test_frontend_gemma4.py:187-225 feeds the same blocks through _write_synthetic_snapshot and image_settings.

Nothing reads:

What replaces it: the processor block reduced to processor_class + image_processor (the keys frontend.py:120-133 validates) and the model block reduced to model_type, vision_config's three checked keys, and the three token ids. Saving ~75 lines.

Why nothing is lost: if a key is dropped that the validator would have rejected on, the synthetic-snapshot test (test_frontend_gemma4.py:180-184) already covers mismatched and bool token ids; the remaining keys are the ones the code branches on.


5. Should fix — two gemma4.rs tests restate fixture cases (~37 lines)

helios/src/frontend/images/gemma4.rs:383-402 geometry_matches_the_hugging_face_processor has nine rows; seven of them (1×1, 672×672, 1008×672, 91×37, 1920×1080, 10×3000, 3000×10) are cases in the checked-in fixture asserted by canonical_processor_pixels_positions_and_resize at :314-381 (grid, tokens, patches, resized SHA, pixels SHA, positions SHA). Only (100, 3000) and (3000, 100) are unique shapes.

What replaces it:

for (width, height) in [(100, 3000), (3000, 100)] {
    let g = processor.geometry(width, height).unwrap();
    assert_eq!(g.tokens * 9, g.patches, "{width}x{height}");
}

helios/src/frontend/images/gemma4.rs:404-420 pixels_interleave_rgb_and_positions_are_xy re-derives the 91×37 case: same grid [1, 30, 78], same pixel count, (x, y) ordering (exactly what the positions SHA pins), and the same cu_seqlens already asserted at :378. Delete the function.

Why nothing is lost: the fixture is generated from Hugging Face's Gemma4ImageProcessor and verified unconditionally in cargo test; these tests assert the same numbers by hand. Saving ~37 lines.


6. Nit — layouts/bracketed.rs:55-88 run-tracking state machine (~14 lines)

Three pieces of state — run_start: Option<usize> (:55), the flush_span closure (:57-65), and the trailing flush after the loop (:86-88) — exist to find each run's end, which is known when the run starts: processed.geometry[image].tokens. Envelope::expand (patch_merge.rs:59-70) always wraps a run in exactly one start and one end token.

What replaces it (span pushed where the run begins, atomic_spans: bool → span: Option<&ImageSpan>):

if position == 0 || expanded.mm_token_type_ids[position - 1] == 0 {
    let source = images.get(image).ok_or("unexpected image token span")?;
    conditioning.push(ConditioningEvent { position: position as u64, identity: source.identity });
    if let Some(_) = span {
        let end = position + processed.geometry[image].tokens + 1;
        spans.push(position.checked_sub(1).filter(|_| end <= expanded.token_ids.len())
            .ok_or("bracketed image feature run is outside the expanded prompt")?..end);
    }
    image += 1;
}

and at the call site helios/src/model/prompt.rs:52-65, pass the Option<&ImageSpan> directly instead of the .and_then(|layout| layout.span.as_ref()).is_some() chain. The bounds error is preserved (both ends checked at run start instead of at flush). Saving ~14 lines.


7. Nit — patch_size / pooling_kernel_size wire knobs and a twice-spelled allowlist (~18 lines)

Gemma4ImageSettings.patch_size and .pooling_kernel_size (helios/proto/runtime_core.proto:598-599 (not opened), helios/src/model/contract.rs mod arms at :334-336, gemma4.rs:18-19) are pinned by ignition/preparation/frontend.py:169-170 to 16 and 3, and gemma4::Processor::load already rejects anything else (the 16/3 relationship to limits.patches_per_feature is checked at load). Keeping them on the wire adds a field, a serde default question, a describe path and a decode arm for values that cannot vary. The soft-token allowlist (70, 140, 280, 560, 1120) is spelled twice, once per language: gemma4.rs:13 and frontend.py:132.

What goes: the two wire fields (derive 16 and 3 inside the processor, as the layout already does for Bracketed), and one copy of the allowlist (keep the Python one, where the checkpoint is validated; Rust needs only the hard cap). Saving ~18 lines. This one is small and stands or falls with finding 1.


Examined and rejected (do not report as subtractions)

Open questions / not found

Counting basis

Added lines per file from pr_files. Production vs test split at head: production ~1,180, tests/fixtures ~1,310. Removable: ~1,514 lines (61%) if finding 1 is accepted; ~304 lines (12%) for findings 2-7 alone if the profile is kept.