Code review summary report · NVIDIA/hyperflare-inference #483

Raw Markdown for agents: https://autobot.eidonix.com/p/580db698-64f4-4c00-9b08-fe3b9185ec84.md

PR #483 review — Gemma 4 image preparation profile, bracketed 3×3 packing, atomic spans

PR: #483, head f2340e42, base 6d6fe0c6, 13 files, +732/−164. No human review yet. Verdict: Changes requested. Not a rejection — the shape of the change is right; three behaviours need to be narrowed, evidenced, or disclosed before this is mergeable.

Key findings

  1. The description's central design claim is contradicted by the code. It says Bracketed derives stride and width "directly from config.contract.vision.patches_per_feature … so ImageLayoutKind and ImagePreparationKind remain orthogonal with no model-identity branching in upload packing". packing.rs:16-22 is a two-entry table (4 => (2, 1176), 9 => (3, 768)) keyed on a number that does not determine patch width — DeepSeek already runs patches_per_feature = 9 at 588 floats per patch (packing.rs:35-38). 9 => 768 is model identity wearing a geometry name, in shared input packing, which docs/design-review.md:38-52 explicitly forbids.
  2. The headline evidence cannot fail. Both parity tests return silently without FLARE_GEMMA4_TEST_SNAPSHOT and ../.venv/bin/python (gemma4.rs:236-244, :253-256, :281-283, :336-339), and a silent return counts as a pass. So "45 passed" is the same number whether the Hugging Face comparison ran or not — while every other profile's parity evidence is a checked-in fixture (glm.rs:147-199 + tests/frontend/generate_glm_image_fixtures.py (not opened); qwen38_images.json (not opened)).
  3. Atomic spans are a shared-scheduler change presented as a Gemma 4 detail. prompt.rs:137-151 fires for any layout whose contract declares an ImageSpan and whose data.spans is empty, feeding both validate_prompt_data (model.rs:436-451) and Scheduler::set_prefill_spans (runtime.rs:1458-1465 → scheduler.rs:1912-1936, which makes each span unsplittable). No test in the diff and no in-tree fixture reaches it.
  4. The profile can load configurations the rest of the pipeline cannot represent. gemma4.rs:23-31 accepts any patch_size ≤ 64 and pooling_kernel_size ≤ 16, so pooling² need not equal limits.patches_per_feature and 3·patch_size² need not equal the packing stride; the mismatch surfaces only as a per-request error (prompt.rs:171, packing.rs:497) or as silent tensor misalignment.
  5. Unenforced invariant: a 1,120-soft-token image expands to a 1,122-token envelope, which validate_prompt_data (model.rs:421-423) and set_prefill_spans (scheduler.rs:1922-1930) reject when prefill_chunk_size is smaller. Nothing checks this at load. Latent today (the Ignition default is 4096, ignition/preparation/bootstrap.py:36 (not opened)), live for any small-chunk deployment.
  6. The witness to that claim. Correct, additive wire format; correct Envelope extraction; correct, overflow-guarded resize/pack arithmetic. See "Verified clean" below.

Blockers

B1 — Bracketed patch width is looked up from patches_per_feature (Architecture, Conventions, Correctness)

Finding. helios/src/frontend/images/packing.rs:16-22:

fn bracketed_patch_geometry(patches_per_feature: usize) -> Result<(i64, usize)> {
    match patches_per_feature {
        4 => Ok((2, 1176)),
        9 => Ok((3, 768)),
        _ => Err("unsupported bracketed patches_per_feature".into()),
    }
}

Used from tensor_layout (packing.rs:39-42) and bracketed() (packing.rs:479-481), and reached at core load through helios/src/model/packing.rs:92-97.

Request. Move the width into prepared metadata: add patch_size to VisionCapabilities (helios/src/model.rs:44-51), validate it next to patches_per_feature in VisionCapabilities::validate (helios/src/model.rs:68-87), then in packing.rs compute merge_side = patches_per_feature.isqrt() and patch_width = 3 * patch_size * patch_size. Delete bracketed_patch_geometry and thread the width from config, the way class_token() reads padded_grid::FEATURES (packing.rs:515).

Why. One vision patch vector is 3 · patch_size² floats — a property of the vision tower, not of the merge factor. The key is provably ambiguous in-tree: DeepSeek uses patches_per_feature = 9 with 588 floats per patch (packing.rs:35-38), so 9 => 768 encodes "the model with 9 patches per feature is Gemma 4". docs/design-review.md:38-52 requires input packing to "stay shared; use prepared metadata" and states "Enums, callbacks, schema names, and metadata fields cannot serve as alternative model allowlists"; the charter says "keep the runtime small and model-agnostic … shouldn't accumulate per-model branches (#267, #334)". A future 3×3-merge tower with 14×14 patches silently gets 768 and produces truncated or misaligned pixels. Scope note: only PatchMerge/MiniMax uses ImageLayoutKind::Bracketed today, at patches_per_feature = 4 (helios/tests/message_boundaries.rs:494, layouts/bracketed.rs:104-180), so this is a design violation and a load-path narrowing rather than a present bug for another model. It is still the blocker, because it is the PR's stated architecture and it is wrong.

B2 — The Hugging Face parity evidence cannot fail and is not reproducible (Correctness, Prose, Simplicity)

Finding. helios/src/frontend/images/gemma4.rs:236-244 returns early unless FLARE_GEMMA4_TEST_SNAPSHOT is set and tokenizer.json (not opened) exists; :253-256 returns again without ../.venv/bin/python; :281-283 returns if the template subprocess fails; :336-339 (native_pixels_and_positions_match_the_checkpoint_processor) returns without ../.venv/bin/python. The tests only compare three synthetic rasters ((x % 256) as u8, :378-383) at (91,37), (10,3000), (3000,10).

Request. Replace the subprocess comparison with a checked-in fixture: add tests/frontend/gemma4_images.json (not opened) plus tests/frontend/generate_gemma4_image_fixtures.py (not opened) carrying width, height, grid, token count, and SHA-256 of resized bytes / pixel_values LE / position_ids LE, and assert them the way glm.rs:147-199 does. If a snapshot test is kept, mark it #[ignore = "requires FLARE_GEMMA4_TEST_SNAPSHOT and .venv"] and report the ignore in the description.

Why. AGENTS.md:103-109 requires skipped checks to stay visible and says test counts cannot stand in for the tested contract; AGENTS.md:306 says to "report a skipped test as an unrun check". The skip-return pattern itself has precedent here (the MiniMax test does the same at bracketed.rs:104-111), so the problem is not honesty — it is that the PR's headline result ("exact f32 pixel and (x,y) position parity") has no CI-executable witness, unlike GLM and Qwen, and a regression in resize::resize or the patch loop would pass the suite.

B3 — Atomic spans are produced in shared code, untested, with an undisclosed blast radius (Architecture, Conventions, Correctness)

Finding. helios/src/model/prompt.rs:137-151 fills prepared.data.spans from prepared.conditioned_inputs whenever data.spans.is_empty() and the contract declares an ImageSpan — a profile-independent condition. Consumers: validate_prompt_data (helios/src/model.rs:436-451) and Scheduler::set_prefill_spans via helios/src/server/runtime.rs:1458-1465 → helios/src/scheduler.rs:1912-1936. The span is re-derived from additional + 1 (prompt.rs:129-131, layouts/bracketed.rs:77-81), not from the indices the layout actually emitted.

Request. Emit the span where the envelope is built: have layouts/bracketed.rs:82-91 push data.spans for the range it expanded, mirroring layouts/deepseek.rs:149; delete prompt.rs:137-151; add a Bracketed contract fixture with image_tokens.span set and a test that the span is produced, passes validate_prompt_data, and is rejected/truncated when longer than prefill_chunk_size. In the description, state the before/after for existing span-declaring cores.

Why. The precedent is that the layout owns its PromptData, as deepseek.rs:149 does beside tokens.extend(block); after this PR one field is owned centrally and the rest by the layout. Coverage is zero: the only in-tree Gemma 4 contract fixture has "image_tokens": null (helios/tests/support/contracts/gemma4_frontend.json:38), and the layout matrix in prompt.rs:481-487 declares a span only for Deepseek/DeepseekRowMajor, which already fill their own spans — so the new branch never executes under test. Blast radius is undisclosed: a span-declaring layout that returned no spans previously failed prompt validation and now silently switches to atomic prefill, which is what "existing cores … unaffected" does not say.


Should Fix

S1 — Processor::load accepts settings neither the packer nor the cache validator can represent (Correctness)

Finding. helios/src/frontend/images/gemma4.rs:23-31 checks only patch_size ∈ 1..=64, pooling_kernel_size ∈ 1..=16, and the max_soft_tokens allowlist. It never requires pooling²== limits.patches_per_feature (used by prompt.rs:171 and packing.rs:488) nor that 3·patch_size² equals the packing stride (packing.rs:19).

Request. In load(), reject unless pooling_kernel_size * pooling_kernel_size == limits.patches_per_feature, 3 * patch_size * patch_size equals the declared patch width, and max_soft_tokens * pooling² <= limits.max_patches_per_image.

Why. With patch_size = 14, pooling = 3, the profile loads, emits 588 floats per patch (gemma4.rs:116), and packing.rs:497 slices at the 768-wide stride — truncated pixels or silently misaligned tensors — while conditioned.rs:192's literal 768 makes cached records fail valid_processed forever with no error. The one place where the profile and the packing contract must agree is the one place not validated.

Finding. packing.rs:19 (9 => 768), conditioned.rs:192 (Profile::Gemma4(_) => 768, the cache predicate), gemma4.rs:116 (3 * patch_size * patch_size).

Request. One shared constant or helper derived from profile + contract metadata, used by conditioned.rs, bracketed() and gemma4::process (subsumed by B1's fix — listed so the fix is complete).

Why. conditioned.rs:191 already shows the better pattern for PaddedGrid (it references padded_grid::FEATURES); a divergence between the three surfaces as "image preprocessing differs from its prompt geometry", which points the reader at the wrong layer.

S3 — The max_soft_tokens + 2 ≤ prefill_chunk_size invariant is unenforced (Correctness)

Finding. max_soft_tokens: 1120 (gemma4.rs:11) expands to a 1,122-token envelope (patch_merge.rs:58-69 pushes start + image tokens + end; the test asserts start + 261 for 260 tokens at gemma4.rs:318-320). validate_prompt_data rejects spans longer than config.limits.prefill_chunk_size (model.rs:421-423), and set_prefill_spans rejects s.end - s.start > capacity (scheduler.rs:1922-1930); the server turns both into failed requests (runtime.rs:1458-1465).

Request. Reject the combination at load with a named error, or clamp max_soft_tokens to the largest value whose envelope fits, and add a boundary test at exactly the chunk size.

Why. Latent at repository defaults (ignition/preparation/bootstrap.py:36 (not opened) sets prefill_chunk_size = 4096; limits require ≥64 and 64-alignment, scheduler.rs:67-73), but a 1024-chunk Gemma 4 deployment admits every image at geometry time and then fails it at prompt validation with an error naming neither images nor spans.

S4 — Ignition's gate pins one vision tower and derives nothing from the checkpoint (Architecture)

Finding. ignition/preparation/frontend.py:126-129 asserts num_hidden_layers 27, hidden_size 1152, num_attention_heads 16, head_dim 72, intermediate_size 4304 — one architecture variant, not a preprocessor fact — and the three image tokens are literals (:134-136) rather than checked against the checkpoint's added tokens.

Request. Assert only what the preprocessor consumes (model_type: gemma4_vision, patch_size, pooling_kernel_size, max_soft_tokens, rescale/normalize/convert flags), take the three token strings from the tokenizer config with an assertion that each encodes to exactly one added token, and either add a second checkpoint to the evidence or narrow the claim.

Why. The charter's "New model recipes … must list supported checkpoints from an official or widely used source … and support more than a single checkpoint (#74)" is not met by one snapshot (google/gemma-4-31B-it, 842da379), while docs/model-preparation.md:345 lists e2b/e4b/12b/26b-a4b/31b. An otherwise identical checkpoint is rejected by preparation with a generic "unexpected … vision configuration"; a checkpoint with different token spellings fails later at request time ("image envelope marker must encode one token", patch_merge.rs:46).

S5 — Documentation the change makes stale was not updated (Prose)

Finding. helios/README.md:702-704 lists the profiles and omits Gemma 4; docs/runtime-core-design.md:226-233 enumerates image settings per profile with no Gemma 4 entry and says nothing about Bracketed deriving its stride; helios/model-contract.md:251-254 covers atomic spans and layout data and does not mention the new preparation kind; docs/TODO.txt has no entry for the recipe dependency.

Request. Add Gemma 4 (16×16 patches, 3×3 pooling, soft-token set) to the three enumerations and record the companion-recipe dependency in docs/TODO.txt.

Why. AGENTS.md:52-59 treats documents as present-state specifications and puts unrun checks and pending measurements in docs/TODO.txt; since the parallel text lists every other profile, the omission reads as "not supported" after merge.

S6 — Description corrections (Prose)

Findings and requests.

Why. AGENTS.md:72-140 requires the four description parts to carry real evidence and scope, and :129-132 says to remove process assurances that add no technical evidence.

S7 — Regenerated Python bindings went backwards in generator version (Conventions, Prose)

Finding. ignition/preparation/runtime_core_pb2.py:5 changes Protobuf Python Version: 7.36.2 → 7.36.1 and the ValidateProtobufRuntimeVersion minor argument 2 → 1, while pyproject.toml:34 pins protobuf>=7.36.2,<8.

Request. Regenerate with the tree's protoc (protoc --proto_path=helios/proto --python_out=ignition/preparation helios/proto/runtime_core.proto, documented at helios/manifest.md:465-472) so the header returns to 7.36.2 and only descriptor bytes change, or state the intended version change in the description.

Why. Not a runtime break (the check rejects an older runtime, not an older gencode), but the checked-in artifact now records a generator older than the pin, against "be explicit and pin everything".


Nits


Verified clean (do not re-litigate)


Open questions and what could not be established

  1. Does any shipped core declare an ImageSpan with an envelope-expanding layout? This decides whether prompt.rs:137-151 is a no-op for existing models or a scheduling change. Core manifests live in local-inference-lab/hyperflare-recipes, outside this repository.
  2. What prefill_chunk_size do Gemma 4 cores get? Only a real prepared core or recipe shows whether the 1,122-token envelope fits (model.rs:422, scheduler.rs:1926); the Ignition default of 4096 makes S3 latent.
  3. Did the live Gemma4ImageProcessor comparison actually run for the reported "45 passed"? Only a run with the snapshot and .venv present, plus per-test skip visibility, settles it.
  4. Which protoc regenerated runtime_core_pb2.py, and does 7.36.1 satisfy the protobuf>=7.36.2 pin? pyproject.toml:34 was not re-opened in this pass; the pin value should be confirmed.
  5. Does any second Gemma 4 checkpoint share the vision tower pinned at frontend.py:126-129? Running preparation against the e2b/e4b/26b-a4b checkpoints in docs/model-preparation.md:345 would settle charter #74.
  6. Should a prefix-cache match ending inside an atomic image envelope fail the request or fall back to the envelope boundary? scheduler.rs:2149 consults vision.patches_per_feature, suggesting image-aware boundary handling may exist, but no test asserts either behaviour.