Architecture report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/c4c9b7b9-7dda-477c-8b32-8f462efa3248.md

Architecture & scope review — PR #533 "Cap the per-request context target" (head 9118add, 6 files, +69/−5)

Key findings

The shape of this change is right and should be kept: one optional field declared once on the universal RecipeParameters base, which the dynamic CLI, manifest and reproduction-arg plumbing generate without per-model code; one Plan.prepared_context accessor; one consumer line in common_preparation_kwargs(); no Helios change; and omission of the flag is byte-equivalent to main. It fits the charter's "smallest footprint in shared code" and "no per-model branches" rules, and the description carries measured evidence.

Two reachable behaviours are wrong at this head, and four things are misleading or missing. Nothing was executed; the head has no CI checks, so the first blocker is asserted from the code and is settled by pytest tests/cli/test_planning.py.


Blocking

B1. The page-multiple check validates the raw target, so the clamp is unreachable and the PR's own test fails

ignition/planning.py:186-190, in Plan.__post_init__:

target = self.parameters.context_target
if target is not None and target % self.page_tokens != 0:
    raise UsageError(f"--request-context {target:,} is not a multiple of the {self.page_tokens:,}-token page size")

ignition/planning.py:357-363:

@property
def prepared_context(self) -> int:
    """The context the prepared core serves per request; the recipe max when no target is set."""
    target = self.parameters.context_target
    if target is None:
        return self.recipe.context
    return min(self.recipe.context, target)

The clamp branch cannot run for any target that needs clamping in the page-alignment sense, and for the range sense it is pre-empted one line earlier by self.parameters.validate(context) (planning.py:185): context_target declares max_fn=_recipe_context_limit (ignition/parameters.py:1309-1321; helper :1268-1269 returns context.recipe.context), and validate_fields (parameters.py:505-545, bound branch :533-545) raises --request-context for <alias> must be 1 through 262,144.

Consequences, all visible:

  1. tests/cli/test_planning.py:310-313 builds context_target=500000 and asserts oversized.prepared_context == recipe.context. The fixture has context=262144 and page_tokens=64 (tests/cli/test_planning.py:139-140), so 500000 fails the max bound, and even without that bound 500000 % 64 = 32 trips the alignment check. Either way line 311 fails: the PR's test is red at this head.
  2. The behaviour documented in three places is unreachable: docs/cli-design.md:468 ("resolves to the smaller of N and the recipe maximum"), the accessor docstring (planning.py:359), and the PR description ("min(recipe.context, N)"). A user who passes a large value gets a usage error where the docs promise a reduction.
  3. Dead branch plus a doubled validation is exactly the "unnecessary special case" the charter warns about: two mechanisms (bound rejection and clamping) for the same input.

Fix (pick one, consistently): either validate the served value — run the multiple check on min(self.recipe.context, target), drop the max_fn for this field (keeping min_value=1), and warn when the target is clamped — or keep hard rejection and delete the clamp branch, its test case, and the "smaller of" wording from docs/cli-design.md:468 and the description. The first matches the documented intent and the measured use case (which never exercises an oversize target).

B2. A cap can export a core Helios rejects at load: the prefill-chunk check still compares against Plan.context

ignition/planning.py:594-596:

if params.prefill_chunk > result.context:
    raise UsageError(f"--prefill-chunk-size {params.prefill_chunk:,} exceeds the {result.context:,}-token context this plan allows")

result.context is min(self.recipe.context, self.tokens) (planning.py:352-355) — the recipe and pool bound — not prepared_context. Nothing else constrains the chunk against the cap: ignition/parameters.py:1294-1307 bounds prefill_chunk with max_fn=_recipe_context_limit (recipe context) and multiple_of=64 only, and ignition/preparation/bootstrap.py:45-46 forwards parameters.prefill_chunk unchanged as prefill_chunk_size while bootstrap.py:132 forwards plan.prepared_context as the core context.

So on a fixture-shaped deployment (recipe context 262144, page_tokens 64), --request-context 1024 --prefill-chunk-size 4096 passes every export-side check and writes a core with max_sequence_tokens=1024, prefill_chunk_size=4096. Helios rejects that at load: helios/src/scheduler.rs:66-73 (validate_prefill: "prefill_chunk_size must be divisible by 64 and within 64..=context" where context is max_sequence_tokens), surfaced through helios/src/model/catalog.rs:42,48-57. This is the same class of load-time defect the new page-multiple check was added to prevent, and it is one flag away from the PR's headline scenario — a small cap next to the default 4096-token chunk.

Fix: compare the chunk against the served context, e.g. effective = min(result.context, result.prepared_context), in planning.py:594-596 (and, if the bound should appear in MODEL --help, in the parameter path via a ParameterContext that exposes the prepared extent). Same asymmetry, lower severity: Plan.demand_pages (planning.py:320-321) still sizes the reported demand from recipe.context, so the printed plan does not describe the prepared ceiling.


Should fix

S1. Help and the chunk bound still describe the uncapped world

ignition/cli/help.py:46 prints Context: {recipe.context:,} tokens (page size: {recipe.page_tokens}) in MODEL --help, and --prefill-chunk-size is bounded by recipe.context with help text at parameters.py:1458-1462. After a cap, the help advertises a context and a chunk ceiling that the plan rejects (B2) or that the exported core cannot serve, and the new help string for --request-context (parameters.py:1320) gives no hint that the recipe number is now an upper bound. Fix: have model_epilog take the plan (or accept an optional prepared context) and print the effective value with a note, and derive the chunk maximum from the plan's prepared context where a plan exists.

S2. context_hint names the cap even when no cap is set

ignition/cli/serve.py:68 unconditionally emits "context is limited by the checkpoint, cache capacity, and --request-context cap". For every deployment that does not pass the flag — i.e. all existing ones — the hint names a flag that is not in use, which is the kind of noise the "don't advertise settings that aren't in play" style in this codebase avoids (compare the conditional decode_weight_bytes on the next lines). The plan is in scope at _server_options (serve.py:59-71), so making it conditional on plan.prepared_context < recipe.context is a one-line change.

S3. The cap never appears in the printed plan report

context_target has no status_label (parameters.py:1309-1321), and the plan line is built only from status_labels (parameters.py:1554-1559, called from serve.py:268-272) plus the fixed prefix. Other DEPLOYMENT flags in the same group do supply one (parameters.py:1368, :1377). The practical consequence: the Select GPUs. report a user reads after export does not say the core was built for a reduced context — the single most consequential fact about that artifact, since changing it requires a re-export (docs/cli-design.md:468). This is the AGENTS.md:452-456 (not opened) expectation that a setting's printed report describe what was prepared. Fix: status_label=lambda v: f"request context {v:,} tokens" if v else None.

S4. The VRAM evidence only holds under a non-default --kv-cache-limit

The measured table is real, but its condition is buried in the command line rather than the claim. helios/src/runtime_core/memory.rs:284-292 returns Ok(None) for KvCacheLimit::Memory, which is the default (docs/cli-design.md:740), and only the Context/Concurrency modes derive a page ceiling from max_sequence_tokens (memory.rs:298-330). Export-side sizing does not follow the cap: fit sizes pages from available memory (ignition/planning.py:471-480) and demand_pages still uses recipe.context (:320-321). So the "expected pool = concurrency × prepared-context behaviour" sentence is true for --kv-cache-limit concurrency and not yet demonstrated for the default mode. Fix: state the condition on the headline claim, and say explicitly what the default mode gains (fewer pages reserved per request only insofar as fit_context clamps to the pool at serve time).


Nits

  1. docs/cli-design.md:468 is the only place the clamp wording lives in prose; if B1 is fixed by rejecting instead of clamping, this row and the accessor docstring must change with it. (Its "Command line only" phrasing is consistent with neighbouring rows and is not wrong, since the catalog is fixed at export.)
  2. prepared_context short-circuits the None case (planning.py:360-362) where min(self.recipe.context, target or self.recipe.context) would do; harmless, but two paths for one value is what let B1's dead branch go unnoticed.

What is confirmed clean (do not re-raise)

Open questions / not verified