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

Raw Markdown for agents: https://autobot.eidonix.com/p/4685c77c-dce6-442a-b32c-1f83a065846f.md

Full report — PR #533 "Cap the per-request context target"

Head 02023eba (base main, 9 files, +84/−18, no CI checks on the head). Reviewed against AGENTS.md (not opened), the charter, docs/cli-design.md, and the maintainer's earlier review of the closed PR #454.

Key findings

The shape of the change is right and should be kept: one optional frozen Plan field (ignition/planning.py:186), one accessor (:377-381), one keyword through fit()/plan(), one consumer line (ignition/preparation/bootstrap.py:58), one flag registered in the shared "capacity and compression" group (ignition/cli/__init__.py:167-168) that reaches all three subcommands — no Helios change, no per-model branch, no env toggle, no duplicated mechanism. Omitting the flag is byte-equivalent to main, and every reporting gap raised in earlier rounds (plan JSON, printed serve line, bench record, manifest reproduction arg, multi-host export, docs owner rows) is fixed at this head.

Three defects still stop it:

  1. derive() lost its context parameter while still passing it on (ignition/cli/preparation.py:45-56 vs :69), so every preparation entry point raises, with or without the flag.
  2. The advertised page-multiple validation is absent, while the PR's own test asserts it and Helios rejects an unaligned core at load.
  3. The new test reads a proto field that does not exist (.value.int64_value), so the test cannot pass even after the validation is restored.

Method note: nothing was executed and the head has no CI checks; every claim below is a static read, grep or arithmetic at 02023eba. pytest tests/cli/test_planning.py tests/cli/test_commands.py settles all three blockers in one command.


Blockers

B1 — derive() has no context parameter; every preparation command fails

ignition/cli/preparation.py:45-56 ends ..., row_shard_prefill: bool = False, row_shard_attention: bool = False, force_moe_decode_a16: bool | None = None) -> planning.Plan: — there is no context keyword, and no module-level context exists (a full-file search finds only context_parallel/context_parallel_size in the signature and call, the offending :69, and the context_parallel() helper at :124-132). Yet :69 ends the planning.plan(...) call with row_shard_attention=row_shard_attention, context=context).

Consequences by caller:

(Which exception fires first is argument-binding order; either way no preparation runs.) This directly falsifies the description's "omitting the flag is a no-op" guarantee: the omitted flag is now a crash, and AGENTS.md:74-80 (not opened) requires the change to work as described. The new test does not catch it because it calls planning.plan(...) directly (tests/cli/test_planning.py:218-240) and never enters derive().

Requested change: add context: int | None = None to the derive signature (ignition/cli/preparation.py:55, before force_moe_decode_a16), keeping the wire-up at :69. Cover the funnel with one assertion inside the existing test_derive_forwards_row_shard_prefill (tests/cli/test_commands.py:88) — pass context=131072, assert plan.context_target == 131072 — rather than with a new test: that one line covers both this regression and the seam.

B2 — The page-multiple validation does not exist; the PR's own test fails and an unaligned target exports an unloadable core

The description states ignition/planning.py gains "a page-multiple validation", and tests/cli/test_planning.py:238-240 asserts it:

with pytest.raises(UsageError, match="multiple of the"):
    planning.plan(recipe, recipe.checkpoints[0], gpus, context=100, **base)

There is no such check. Plan.__post_init__ (ignition/planning.py:224-296) never inspects context_target; a repository-wide search for "multiple of" under ignition/ returns only the prefill-chunk rule (planning.py:636-637), its help text (cli/__init__.py:165, cli/help.py:38) and unrelated component validators. fit() validates only context <= 0 (planning.py:467-468); context_target appears only at :186 (field), :379/:381 (accessor), :438 (to_dict) and :549 (constructor keyword).

So plan(context=100) succeeds there and falls through to the effective-context chunk check at planning.py:709-711, raising UsageError("--prefill-chunk-size 4,096 exceeds the 100-token context this plan allows") — the test fails with DID NOT MATCH, not DID NOT RAISE (fixture: context=262144, page_tokens=64, prefill_chunk=4096, tests/cli/test_planning.py:37-42).

This is a real load-time defect, not just a test mismatch. bootstrap.py:58 makes prepared_context the prepared catalog's context, which becomes max_sequence_tokens (helios/src/server/config.rs:131 (not opened),148), and helios/src/model/catalog.rs:50-57 rejects any core whose prepared_sequence_tokens / max_sequence_tokens is not a multiple of page_tokens.max(1) with "invalid prepared model configuration". Reachable path: --request-context 1000 --prefill-chunk-size 64 passes planning.py:635 (64 is a valid chunk) and :709-711 (64 ≤ 1000), exports a full core, and the core will not load — the user sees a successful export and a stock Helios error at flare run, long after a full preparation.

Requested change: validate the served value in plan() where the other flag rules live: reject min(recipe.context, context_target) % self.page_tokens != 0 with a message containing "multiple of the" and naming --request-context, the value and the page size. Plan.page_tokens (planning.py:335-338) is world-size dependent, so use the property rather than recipe.page_tokens. With that check, context=100 (100 % 64 = 36) is rejected as the test expects, and an oversize target that resolves to an aligned value still clamps.

B3 — The new test asserts a proto field that does not exist

tests/cli/test_planning.py:254:

assert by_key["context_target"].value.int64_value == 131072

helios/proto/runtime_core.proto:124-133 declares PreparationValue{bool_value, int_value, uint_value, float_value, string_value, list_value} — there is no int64_value, so this raises AttributeError. Even renamed to int_value it would read 0: _preparation_value writes non-negative ints as uint_value and only negative ints as int_value (ignition/preparation/rebuild_manifest.py:329-333), and 131072 >= 0.

Requested change: assert by_key["context_target"].value.uint_value == 131072 — or delete the line and keep the scope assertion at :253, which is the part the sibling manifest test (tests/cli/test_planning.py:92-106) does not already prove.


Should fix

S1 — prepared_context is clamped by export-host free memory, so the recorded flags do not reproduce the core

ignition/planning.py:377-381:

if self.context_target is None:
    return self.recipe.context
return min(self.recipe.context, self.context_target, self.tokens)

self.tokens is self.pages * self.page_tokens (:368-369), and pages comes from available // costs.page_bytes (:550-556), where available derives from free_bytes on the export host (:360-361). The untargeted path deliberately returns recipe.context and lets the pool bind at serve time; the targeted path instead bakes the export host's free VRAM into the artifact's max_sequence_tokens, while reproduction_args record only --request-context N (ignition/preparation/rebuild_manifest.py:264-265). The same recorded flags therefore reproduce a different core on a host with a different free-memory reading, contradicting AGENTS.md:452-456 (not opened) ("The setting, its printed report, and its recorded measurements describe what was prepared").

It is also redundant: Helios applies exactly this clamp at serve time — helios/src/model.rs:268: self.limits.max_sequence_tokens = self.prepared_sequence_tokens.min(...) (fit_context).

Requested change (subtraction): return min(self.recipe.context, self.context_target); keep the None arm as is. Helios's fit_context then applies the pool bound, matching the untargeted path's split of responsibilities. This also makes the description's "a cap above the pool is a no-op, matching stock" true by construction rather than a coincidence of the export host's memory, and it makes the effective_context = min(result.context, result.prepared_context) guard at :709 genuinely load-bearing (with the tokens term gone, prepared_context can exceed the pool-bound context). Update the assertions at tests/cli/test_planning.py:226 (min(recipe.context, 131072)) and :232 (recipe.context), which currently pin the export-time memory dependence.

S2 — Three evidence claims need adjusting (description + docs/cli-design.md:446)

  1. The VRAM table holds only under a non-default --kv-cache-limit. helios/src/runtime_core/memory.rs:290-291 returns Ok(None) for KvCacheLimit::Memory, the default (docs/cli-design.md:738); only the Context/Concurrency modes derive a ceiling from the prepared context (memory.rs:298-320). The headline ("capping … shrinks the KV pool and frees VRAM", "at concurrency 4 the 131072 cap frees 16 GB") and the docs row attach no condition, although the author's own command line passes --kv-cache-limit concurrency. Attach the condition to the claim, not just to the command (AGENTS.md:95-102 (not opened)).
  2. "A cap above the pool is a no-op, matching stock" is false at this head. Stock passed recipe.context unclipped (bootstrap.py:58 before this PR); the capped path returns min(recipe.context, target, tokens), i.e. a strictly lower max_sequence_tokens — the PR's own test asserts it (tests/cli/test_planning.py:229-232). Applying S1 makes the sentence true; otherwise state it as a compatibility change.
  3. Name the workload --kv-cache-limit / --max-concurrency cannot serve. That is exactly what the maintainer asked for on #454: a single request longer than N is now rejected at admission before it loads pages, which no runtime pool setting can express. Neither the description nor the table answers it.

S3 — Two user-visible bounds still describe the uncapped world

S4 — Description mechanics (one item, prose only)


Subtract / Simplify

Could remove ~10 of the +84 added lines (~7 in the test hunk, ~3 in docs), plus about half the new docs row. Subtraction is also the fix for S1.

  1. tests/cli/test_planning.py — ~7 lines of restatement (:211-254, +47):
    • :227 assert capped.context == min(recipe.context, capped.tokens) restates :221 (~1 line).
    • :242-244 d = capped.to_dict(); assert d["context_target"] == 131072 restates :225; the to_dict key is visible at planning.py:438 (~2 lines).
    • :250-253 the four-line proto encode/decode round-trip re-proves from_plan's generic value/scope plumbing already exercised by the sibling manifest test at tests/cli/test_planning.py:92-106; keep :248-249 (both strings in reproduction_args, the genuinely new part) plus one scope assertion (~3-4 lines).
    • Keep the clamp case :229-232: once B2's check is on the resolved value, it is the only proof of the documented clamp.
  2. docs/cli-design.md — ~3 lines: the cap is stated three times. :446 is the authoritative flag row; :1443 and :1493 are this PR's own two owner-row rewrites of the same fact — revert one. And :446's trailing "a core's catalog is fixed at export, so changing it requires re-export" copies the clause --mixed-prefill already carries at :447; one clause is enough.
  3. ignition/planning.py:381 — the third term is S1: deleting it saves no lines but removes an export-host free-memory dependency from the artifact and lets the code and prose agree by construction.
  4. Do not cut (verified load-bearing):
    • prepared_context's context_target is None early return (:379-380): it returns recipe.context, which can exceed the pool-bound context (:372-374); deleting it would silently cap every stock export.
    • derive(context=...): the single funnel all four commands share.
    • The bench check against prepared_context (planning.py:260): a capped plan must reject a benchmark workload above the cap.
    • effective_context = min(result.context, result.prepared_context) at :709 — once S1 removes the tokens term this min is load-bearing, so it must stay.
  5. Not asked: dropping the flag in favour of the runtime --kv-cache-limit. Considered and rejected — the runtime flag bounds loaded KV at serve time and cannot lower the exported max_sequence_tokens, which is the datum this PR exists to produce.

Nits (6)

  1. One flag, two validation homes. context <= 0 sits in fit() (ignition/planning.py:467-468), which plan() re-enters per candidate world size and per shortfall probe (:677-742), while every sibling flag's form and range is checked once in plan() (:615-637) and cross-field rules live in __post_init__ (:224-296). Put both context rules beside the --prefill-chunk-size check (:634-637); B2's check goes there too.
  2. Rename the parameter to context_target through derive/plan/fit (:461, :549, :605, :689): the field, the to_dict key and the manifest key are all context_target, so the context_target=context translation at :549 disappears and a reader stops wondering which bound context= means.
  3. ignition/planning.py:438 now packs four context keys on one very long line; split context_target/prepared_context onto their own lines like the neighbouring keys.
  4. Docs wording, two things. docs/cli-design.md:1443 says "The checkpoint maximum" while :446 and :1493 say "the recipe's maximum" — one term for one thing. And :446 says the cap is "below the recipe's maximum", which reads as a rejection rule, but the code silently clamps an oversize target (planning.py:381, pinned by tests/cli/test_planning.py:229-232); say it resolves to the smaller of N and the recipe maximum.
  5. ignition/cli/serve.py:319 is the only format(x, ',') number rendering in ignition/cli; neighbours use f-string : notation (f" · concurrency {plan.concurrency}"). Use f" · request context {plan.prepared_context:,}".
  6. "stock" is an undefined referent in the test comments (tests/cli/test_planning.py:217, :227, :247); say "with the flag omitted, as at main". Also three consecutive blank lines before test_row_shard_attention_accounting_sizing_and_preparation_manifest (:255-257) where the file uses two.

Verified clean — do not re-raise


Open questions / what could not be found

  1. Did the three blockers reproduce? Not executed here; the head has no CI checks. B1 and B3 are read-level facts, B2 is a read plus 100 % 64 = 36 arithmetic. pytest tests/cli/test_planning.py::test_request_context_target_prepared_context_and_manifest tests/cli/test_commands.py settles all three.
  2. The rule for an unaligned target above the recipe maximum — reject, floor, or accept on the resolved value — is the author's decision; whatever is chosen needs a line in docs/cli-design.md:446 and in the flag help.
  3. Should to_dict()["context"] stay pool-bound (as tests/cli/test_planning.py:227 pins) or become the served ceiling? Only a maintainer knows whether external consumers depend on the current meaning.
  4. Whether external recipes re-round config.context. Recipes live in the external hyperflare_recipes repository, so B2's load failure is stated as a mechanism, not a reproduction; a Plan.prepared_context alignment unit test plus one export/flare run round-trip would settle it definitively.
  5. The VRAM table itself cannot be bound by anything in this tree; only its --kv-cache-limit scoping is checkable (S2.1).