Architecture report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/2dc5ef1f-1f9b-400a-a5e2-9308fee2e266.md

Review — PR #533 "Cap the per-request context target" (architecture & scope lens)

Key findings

The design is right and the wiring is nearly complete. Plan.prepared_context is a clean, small addition: it keeps Plan.context stock (ignition/planning.py:363-366), returns recipe.context when no target is set (:371-372), so omitting the flag is byte-equivalent to stock, and it reaches the core through exactly one line — ignition/preparation/bootstrap.py:58 — which flows into Helios as prepared_sequence_tokens / limits.max_sequence_tokens (helios/src/server/config.rs:131, :148) and is enforced at admission. That was the objection on the earlier attempt (#454) and it is genuinely fixed. The VRAM table answers the "hypothetical deployment" objection with measurements.

Two things block, both about the flag not being carried everywhere a preparation setting must be carried:

  1. One export path silently drops the flag. _export_hosts (ignition/cli/serve.py:193-206) builds its plan with its own planning.plan(...) call that omits context=args.request_context, although the flag is registered on every preparation command. A --ranks N export accepts the cap and prepares at the recipe maximum.
  2. The setting is invisible in every artifact the project requires to describe preparation. Plan.to_dict still reports only context/checkpoint_context; reproduction_arguments and from_plan record nothing about the target. The printed plan, the benchmark record and the rebuild manifest all describe a core that was not prepared.

Two should-fix items remain: no validation of the target against the page size (the resolved value becomes max_sequence_tokens, which Helios requires to be page-aligned), and no tests for a change in shared planning code that alters exported cores.


Blocking

1. --request-context is silently ignored on the multi-host export path

File: ignition/cli/serve.py:193-206

_export_hosts constructs the plan itself:

plan = planning.plan(model.recipe, model.checkpoint, gpus, selected=tuple(range(len(gpus))),
                     concurrency=concurrency.value, reserve_bytes=configuration.reserve_bytes,
                     ...
                     row_shard_prefill=args.row_shard_prefill)      # :206 — no context=

The keyword list ends at row_shard_prefill; there is no context=args.request_context. The flag is registered in _preparation_arguments (ignition/cli/init.py:167-170), which every preparation command shares, so ignition export MODEL --ranks 2 --request-context 131072 parses successfully, prints a plan, and prepares a core at the recipe maximum with no warning or error.

The other three paths do thread it: _prepare (ignition/cli/serve.py:289), debug_serve (ignition/cli/serve.py:472) and bench.run (ignition/cli/bench.py:177). The diff touched only the two serve.py call sites, not this one.

Why it matters: the entire benefit claimed in the description is a smaller max_sequence_tokens and a smaller KV pool. A multi-host deployment is a supported shape (AGENTS.md:157-163), and its export is exactly the case where the pool is largest. The user gets a full-context core, no error, and discovers the failure either as absent VRAM payoff or as a request ceiling that is not enforced — the same class of defect #454 was blocked on, confined now to one path. This also violates the project's explicit stance on not accepting a setting and then dropping it (charter line 13, "Don't silently ignore API fields"; AGENTS.md "Be explicit and pin everything", :165-169).

Fix: pass context=args.request_context in the _export_hosts call. A test that asserts every command path reaching planning.plan forwards the parsed target would prevent recurrence, since this is the third distinct caller.

2. The cap is absent from the plan report and the rebuild manifest

Files: ignition/planning.py:389-442; ignition/preparation/rebuild_manifest.py:231-318, :343-454

Three reporting surfaces omit the new setting:

Why it matters: AGENTS.md's Configuration rule states that a setting "is carried through the plan into the recipe's PreparationConfig, so the plan, its printed report, and its recorded measurements describe what was prepared." The prepared context is now a deployment-visible capacity (it sets the request ceiling and the pool size), and it is the one thing this PR changes — yet no artifact records it. This also makes the measured table in the description impossible to reproduce from a package: given two exported cores and their manifests, nothing says which one is the 128K one.

Fix: add context_target (and the resolved prepared_context) to Plan.to_dict; append --request-context in reproduction_arguments when the target is set; add the corresponding parameter entry in from_plan.


Should fix

3. The target is never validated against the page size, though the resolved value must be page-aligned

File: ignition/planning.py:368-373, :459-460

prepared_context is min(recipe.context, context_target, tokens); tokens is pages * page_tokens, and pages is sized from free memory (:536-542). That value becomes the core's max_sequence_tokens (ignition/preparation/bootstrap.py:58 → helios/src/server/config.rs:131, :148). Helios validates on load that both prepared_sequence_tokens and limits.max_sequence_tokens are multiples of page_tokens (helios/src/model/catalog.rs:44-57), returning "invalid prepared model configuration" otherwise.

fit validates only context > 0 (:459-460). recipe.context and tokens are page-aligned in practice, but a user target is arbitrary: --request-context 100000 with a 64-token page yields a non-aligned max_sequence_tokens, and the visible outcome would be a core that took a long preparation to produce and then fails to load. That the export path reaches this state, rather than clamping, is what the code shows; whether the failure surfaces at load or is rounded somewhere in preparation can only be settled by an export test on SM120.

Separately, prepared_context is clamped by tokens (total pool) rather than guaranteed_tokens (:376-378), so a target above the per-request share still admits one long request while slots are contended — unchanged stock behaviour, but the docs row should say so, since the flag reads like a hard per-request guarantee.

Fix: reject (or round down and report) a target that is not a multiple of the recipe's page size in fit, next to the existing positivity check; state the tokens-versus-guaranteed_tokens clamp in the docs row.

4. No tests for a shared planning change that changes exported cores

File: ignition/planning.py (whole change); tests/cli/test_planning.py

The diff adds no tests. This is core planning code consumed by export, serve, bench and the multi-host path, and it changes what a core declares about itself. AGENTS.md:194-199 requires tests for affected behaviour; tests/cli/test_planning.py (e.g. :71-120) already covers plan resolution and is the natural home for: prepared_context == recipe.context when unset; prepared_context == min(recipe.context, N, tokens) when set; the <= 0 rejection; and the below-chunk message.

That last branch (planning.py:694-700) is currently untested and selects its message on whether prefill_chunk is None, not on whether the user set the target. With the recipe's own chunk it correctly suggests --prefill-chunk-size ... or a larger --request-context; with an explicit --prefill-chunk-size above a low target it reports only the chunk mismatch, which is fine. The branch is only reachable when a target is set below the chunk, since context >= chunk already holds at :621-623 for the stock path — so it is new, reachable code with no coverage.


Nits


Verified clean

Open questions / not settled from code