Architecture report · NVIDIA/hyperflare-inference #483

Raw Markdown for agents: https://autobot.eidonix.com/p/0feeb6cd-fb59-4c13-bd64-696b8c4846bb.md

Review of PR #483 — Gemma 4 image preparation, Bracketed patch-width metadata, atomic spans

Lens: architecture and scope. Head: ab9a432, base: main 27716185, 36 files +2269/−240.

Verdict: should-fix issues only. No blocking findings.

Key findings

Prior findings: verified fixed at ab9a432

Should fix

S1 — No Gemma 4 core exists in the tree; the served path is unexercised

helios/tests/support/contracts/gemma4_frontend.json is the only Gemma 4-named contract fixture and declares "image_preparation": null (:16), "image_layout": null (:17), "image_tokens": null (:38) — it cannot load an image processor at all. No fixture under helios/tests/support/contracts/ uses Bracketed (9) or preparation 11; the layouts in use are 1, 2, 3, 7, 8, 10. Gemma 4 coverage is Rust-constructed only: helios/src/model/prompt.rs:1171-1284 (two 262-token spans, patch_features: 768, 64-aligned rejection) and helios/src/server/config.rs:935-1023 (bootstrap bounds); the Ignition side is ignition/preparation/frontend.py:114-174 with tests/preparation/test_frontend_gemma4.py.

Nothing takes a Gemma 4 core from Bootstrap::load (server/config.rs:290-298) through validate_loaded_image_processor to a served image request. AGENTS.md:155-169 asks a new format to "prove they export and serve cleanly from the PR branch, and support more than a single checkpoint"; the compatibility half (:182-186) is now tested, the export/serve half is deferred to the unlanded recipe PR and recorded open at docs/TODO.txt:330-337. CI on the head commit reports no checks at all, so even the author's unit evidence has not run in CI.

Fix (cheap): one contract fixture shaped like qwen38.json (not opened) with image_layout: 9, image_preparation: 11, a declared image_tokens.span, and vision { patches_per_feature: 9, patch_features: 768 }, loaded through the same helper the other fixtures use. Otherwise say plainly in the description that Gemma 4 serving is unqualified — the limitations paragraph covers missing timing/memory but not that the profile has never been served.

S2 — The Gemma 4 processor file is not where the default path looks

ignition/preparation/frontend.py:310: path = snapshot / "preprocessor_config.json (not opened)" if preprocessor is None else Path(preprocessor). The new gemma4 branch (:114-174) validates a Gemma4Processor dict read from that path, while the padded_grid doc at :100 already records that some families put the processor in processor_config.json (not opened). Gemma 4 snapshots ship processor_config.json (not opened) — the checked-in fixture is a processor dump, and every test passes the path explicitly (tests/preparation/test_frontend_gemma4.py:88 preprocessor=tmp_path/"processor_config.json (not opened)", :246 preprocessor=snapshot/"processor_config.json (not opened)").

So a recipe calling prepare_frontend(snapshot, image_profile="gemma4") — the documented shape used for the other profiles — raises FileNotFoundError; no test covers the default, so CI cannot catch it. Pre-existing for padded_grid, so this is consistency plus a missing test rather than a new defect.

Fix: resolve the processor path per profile (try processor_config.json (not opened) for gemma4/padded_grid, or accept whichever of the two exists), or make preprocessor required for those profiles and document it.

S3 — Two unreachable wire knobs and a duplicated allowlist

Gemma4ImageSettings.patch_size / pooling_kernel_size (helios/proto/runtime_core.proto:598-605, helios/src/frontend/images/mod.rs:332-341) travel proto → serde → Python, but the only producer fixes them at ignition/preparation/frontend.py:127-141, which makes the caps at gemma4.rs:27-40 unreachable. Their justification is precedent: PatchMergeImageSettings.patch_size is likewise fixed to 14 (patch_merge.rs:92 (not opened)), so the fields are acceptable if that precedent holds — but then the caps should be documented as belt-and-braces only, which they now are (:26).

The real problem is the duplicated gate: the soft-token allowlist exists twice, in Rust (gemma4.rs:13 SUPPORTED_SOFT_TOKENS) and Python (frontend.py:132), with no test tying them. AGENTS.md:188-193 forbids configuration switches and extension points without a concrete requirement, and a duplicated authority for the same invariant is exactly the kind of drift it aims at. Fix: tie them with a test (feed the Python list through the Rust loader), or reduce to one — preparation is the right home for the checkpoint gate, and Rust can accept any positive budget.

Nits

  1. atomic_spans: bool (helios/src/frontend/images/layouts/bracketed.rs:23, computed at helios/src/model/prompt.rs:52-65) is correct behaviour, but it should pass Option<&ImageSpan> — the prepared contract field — so the derivation sits with its use, as class_token receives its token.
  2. Envelope now lives in patch_merge.rs:10-17 (not opened), 84-136 but is shared by two profiles (gemma4.rs:8 imports it); move it to frontend/images/envelope.rs (not opened). The extraction itself is genuine de-duplication with no MiniMax behaviour change (token-uniqueness validation moved verbatim, expand_prompt delegates).
  3. gemma4.rs:384-402 repeats seven of nine fixture rows already pinned by SHA-256 at :315-381; only (100,3000)/(3000,100) are unique. pixels_interleave_rgb_and_positions_are_xy (:405-420) restates the 91×37 case. packing.rs:685-815 repeats patch_features: 0 ten times where three rows cover every distinct outcome.

Scope: does this belong here?

Yes. helios/src/frontend/images/ already owns ten preparation profiles; Gemma4 goes behind the existing ImageSettings enum (mod.rs:249-261, :287, :355), the established extension point rather than a new mechanism — consistent with the charter's "keep the runtime small and model-agnostic" (charter line 12), since the profile is a frontend profile, not a scheduling branch.

Compatibility surface, read at this head:

The one genuine narrowing: square_merge_side (packing.rs:16-22) runs inside tensor_layout, reached from Inputs::new (model/packing.rs:92-97), so a Bracketed core with a non-square nonzero patches_per_feature now fails to load (zero is already rejected at model.rs:88). The new test covers it (helios/src/model/tests.rs:1447-1451). The description already lists this narrowing; it should state that it is load-time for any Bracketed core, not only a MiniMax load-path change.

Checked and found clean

Overflow guards in gemma4.rs (checked_mul :48-51/61-64, try_fold :157-162, check_batch before and after geometry at :152/:163). bracketed() rejects grids not divisible by the derived merge side and any token/patch mismatch (packing.rs:491-497) — divisibility is not implied by tokens * patches_per_feature == patches, and the author is right to check it. layouts/bracketed.rs:89-93 cross-checks image and feature counters against processed geometry; flush_span validates both ends of every run against the expanded prompt (:59-65) rather than trusting the offset. validate_conditioned_inputs (prompt.rs:153-191) still enforces per-span feature ownership, so the new spans cannot smuggle cross-span features.

Open questions / could not establish

What to do next

  1. S1 — add one Bracketed+Gemma 4 contract fixture, or state in the description that Gemma 4 serving is unqualified.
  2. S2 — resolve the processor file per profile, with a test for the default argument.
  3. S3 — tie the two soft-token allowlists with a test, or delete one.
  4. Nits 1-3, batchable in a single pass.