Architecture report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/0b7c9313-fd9d-40f2-946d-b86e511d5b6a.md

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

Head reviewed: de1b5b5 (9 files, +98/−18). Prior review of an earlier head (c36a6a02) raised three blockers; all three are now fixed and are not re-raised here. What follows is what is still wrong.

Key findings

Blocking — the page-multiple check validates the request, not the result

ignition/planning.py:289-290, in Plan.__post_init__:

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

The value the core actually receives is Plan.prepared_context (ignition/preparation/bootstrap.py:58 → "context": plan.prepared_context), which is min(recipe.context, context_target, tokens) (planning.py:371-375). Validating the raw target rejects inputs whose resolved value would be perfectly aligned.

Two consequences, both demonstrable from the code:

  1. The PR's own new test fails. tests/cli/test_planning.py:229-232:

    oversized = planning.plan(recipe, recipe.checkpoints[0], gpus, context=500000, **base)
    assert oversized.context_target == 500000
    assert oversized.prepared_context == min(recipe.context, oversized.tokens)
    

    The fixture (tests/cli/test_planning.py:37-38) has context=262144, page_tokens=64, and its RankCosts (:43) declares no page_tokens, so Plan.page_tokens == recipe.page_tokens == 64 (planning.py:328-332). 500000 % 64 == 32, so planning.plan raises UsageError before the assertions run. The test and the validation contradict each other; at least one is wrong, and the validation is the newer, more consequential one.

  2. The documented no-op path is unreachable for unaligned values. docs/cli-design.md:446 states the flag caps "at N tokens, below the recipe's maximum", with default "The recipe's maximum context", and the PR description says "a cap above the pool resolves to the pool capacity, as stock". With this check, --request-context 262145 on a 256K recipe fails outright rather than resolving to the recipe max. Rejecting a value that will be clamped away is user-hostile and inconsistent with how the rest of plan treats capacity (planning.py:538-544 clamps pages, :370-375 clamps context — neither rejects).

Why it matters: the alignment requirement is real (helios/src/model/catalog.rs:50-57 requires both prepared_sequence_tokens and limits.max_sequence_tokens to be multiples of page_tokens), so some check is needed — but it must apply to the value the core will be told to serve.

Fix: validate the resolved value. __post_init__ cannot do it, because the first Plan is built with pages=0 (planning.py:528-537) so tokens == 0 and prepared_context == 0; the memory-dependent half only exists after replace(..., pages=...) (:543-544). Put the check at the end of fit (planning.py:538-544) or in plan after attempt() (:694-701), where plan already computes effective_context = min(result.context, result.prepared_context) (:696) and raises chunk errors from it — the natural place. Validate min(recipe.context, context_target) % page_tokens if the check must be memory-independent, or prepared_context directly. Then the 500000 test case becomes the proof that an oversized target is a no-op, which is what its comment already claims.

Honesty note: I did not execute pytest (no runtime in this review); the failure is arithmetic over the fixture constants and is one command to confirm (pytest tests/cli/test_planning.py).

Should fix — prepared_context is clamped by the export host's free memory

ignition/planning.py:370-375:

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

self.tokens is pages * page_tokens (planning.py:362-363) and pages is sized from the exporting host's free supply (planning.py:538-544). This value becomes the exported core's max_sequence_tokens (ignition/preparation/bootstrap.py:58).

Three problems:

  1. Non-reproducible artifact. Two exports with byte-identical reproduction_args (ignition/preparation/rebuild_manifest.py:231-320, which now includes --request-context at :264-265) can declare different max_sequence_tokens depending on how much VRAM happened to be free at export. That is the opposite of AGENTS.md:452-456 ("the plan, its printed report, and its recorded measurements describe what was prepared") and of the pin-everything principle in the same section.
  2. Silent under-delivery. On a host whose pool is smaller than the requested cap, --request-context 131072 prepares, say, a 20000-token core with no warning; to_dict still prints context_target: 131072 alongside context: 20000 (planning.py:432, :440-441), so the report reads as if the cap was honoured while the core is smaller.
  3. Duplicated clamp. Helios already narrows the advertised ceiling to the physical pool: helios/src/model.rs:268-272 (fit_context: max_sequence_tokens = prepared_sequence_tokens.min(pages.saturating_sub(draft_pages) * page_tokens)), and helios/src/model/catalog.rs:49 only requires max_sequence_tokens <= prepared_sequence_tokens. Sizing the pool is the runtime's job (charter line 12: Helios "handles scheduling, caches, and requests"); ignition's job is to declare the model's ceiling.

Fix: drop the self.tokens term — return min(self.recipe.context, self.context_target). The no-target branch already returns recipe.context, which preserves stock behaviour exactly. Page alignment then follows from validating the target alone (and the resolved value is always aligned when the target is), which also removes the awkward interaction with the blocking finding above.

Nit — the served value is derivable but not printed

ignition/planning.py:432 adds context_target next to context (stock, pool-bound) and checkpoint_context (recipe max). The value the core will serve is min(context_target, checkpoint_context) — derivable, and tokens/page_tokens are printed (:440-441) — but not stated. A one-word prepared_context key in to_dict would let an operator read the prepared ceiling straight off the plan report instead of recomputing it. Not blocking; the current keys are sufficient to reconstruct it.

What is clean (verified in code, do not re-raise)

Open questions / not verified