Subtractive scratchpad · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/96975319-6b25-4d8b-ae81-6bdf1a933dc4.md

#1 [high] Blocking: the flag re-implements runtime --kv-cache-limit, and the stated memory payoff comes from the runtime flag

PR 533 adds --request-context N on export/debug-serve/bench, threaded derive()→plan()→fit()→Plan.context_target, plus Plan.prepared_context, used only by ignition/preparation/bootstrap.py:58.

What already exists:

Only delta the flag adds over --kv-cache-limit: it lowers the exported max_sequence_tokens so a single request longer than N is rejected. That is one datum (ignition/preparation/bootstrap.py:58 "context": plan.prepared_context → BasePreparationConfig.context, bootstrap.py:33) and is the entire payload of the PR.

Cost of the present shape (diff +35/−15):

Charter/AGENTS hooks: AGENTS.md:165-169 "Every contribution must address ... a demonstrated defect, a measured performance or memory problem"; charter "Look for the smallest footprint in shared code, or a way to solve it without new code at all."

#2 [high] Should fix: prepared_context duplicates Plan.context; smaller version is one line

ignition/planning.py:368-373 (new):

@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)

Plan.context (planning.py:363-366) is min(self.recipe.context, self.tokens). So min(recipe.context, N, tokens) == min(self.context, N) exactly. Smaller version (2 lines saved):

@property
def prepared_context(self) -> int:
    """The context the prepared core serves per request."""
    return self.context if self.context_target is None else min(self.context, self.context_target)

And the call site at planning.py:694 effective_context = min(result.context, result.prepared_context) is then redundant: with no target it is result.context, with a target it is already ≤ result.context. It can read effective_context = result.prepared_context if result.context_target is not None else result.context (same length, so no direct saving) — but with the shortened property the whole second property could be dropped and the two users (bootstrap.py:58 and planning.py:694) could read min(result.context, result.context_target or result.context); net ~4 lines.

#6 [high] Research summary

Reviewed PR #533 ("Cap the per-request context target", +35/−15 across 7 files) through the subtraction lens, against AGENTS.md, docs/design-review.md, the charter, and the maintainer's earlier review of the same change in closed PR #454.

Findings, ranked by lines saved:

  1. Blocking (~15 of the 35 added lines, plus the doc prose). The flag is a re-implementation of a runtime setting the PR's own evidence is measured with. flare run --kv-cache-limit concurrency|context|memory (docs/cli-design.md:738, :828-833; docs/model-preparation.md:396-402; page_ceiling, helios/src/runtime_core/memory.rs:284-331) already bounds the shared KV pool to one prepared context per active request, at core load, without re-export. The description's table is explicitly produced with --kv-cache-limit concurrency, so the measured pool = concurrency × prepared-context VRAM scaling is the pre-existing flag's documented behaviour. The one genuine delta is a lower exported max_sequence_tokens, i.e. one datum reaching one consumer (ignition/preparation/bootstrap.py:58). Maintainer yatesdr asked in #454 for "a concrete workload that --max-concurrency and --kv-cache-limit cannot serve"; this resubmission keeps the same shape and the same memory argument.

  2. Should fix (~6 lines). ignition/planning.py:692-701 turns the stock 3-line --prefill-chunk-size check into a 9-line branch with two messages; the generic message already names both numbers, so one message carrying the effective context replaces it. No test asserts either new string.

  3. Should fix (~4 lines). Plan.prepared_context (planning.py:368-373) duplicates Plan.context: min(recipe.context, N, tokens) is exactly min(self.context, N), so the five-line body collapses to two, and the extra min(...) at planning.py:694 disappears.

  4. Should fix (~2 doc lines + half of one row). docs/cli-design.md:446 repeats what the PR's own other two doc edits (:1443, :1493) already state, and repeats the runtime KV-limit semantics; it also advertises a "memory-constrained multi-model deployment", which AGENTS.md:171-175 lists as unapproved scope.

  5. Nit (~2 lines). derive()'s new context parameter (ignition/cli/preparation.py:56, :68) is a pure pass-through — all three callers pass the flag or nothing. Separately, Plan.to_dict() never records the new setting, so the printed plan and bench configuration cannot show what was prepared (AGENTS.md:452-456), and no test covers any of the new behaviour.

Smallest version: a single Plan field, one plan()/fit() keyword, one line in bootstrap.py and one docs row — roughly 15 of the 35 added lines removable, and the VM point that the flag's memory argument is already served by --kv-cache-limit.

#3 [medium] Should fix: the two-message prefill-chunk branch adds 6 lines to say what the existing 3-line error says

ignition/planning.py:692-701 (PR adds the branch):

result = attempt()
if result is not None:
    effective_context = min(result.context, result.prepared_context)
    if chunk > effective_context:
        if prefill_chunk is None:
            raise UsageError(f"the {effective_context:,}-token request context is below the {chunk:,}-token "
                             f"default prefill chunk; pass --prefill-chunk-size (a multiple of 64) below "
                             f"{effective_context:,} or a larger --request-context")
        raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {effective_context:,}-token context this plan allows")

Stock (single message, 3 lines): if chunk > result.context: raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {result.context:,}-token context this plan allows")

The PR turns 3 lines into 9 and adds a two-message branch to say the same thing: the chunk is larger than the context this plan allows. The special case exists only because a recipe default chunk (4096) can now exceed a small --request-context, and the generic message already names both numbers, which is all a user needs to pick either remedy. The branch costs 6 lines plus a second error string that no test asserts (grep for "request-context"/"positive token count" in tests/ → no matches).

Smaller: keep one message, replace result.context with the prepared context: if chunk > min(result.context, result.prepared_context): raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {min(result.context, result.prepared_context):,}-token context this plan allows") or bind it once in a local. Saves 6 lines of the 7 the hunk adds.

Note the sibling validation at planning.py:459-460 (if context is not None and context <= 0: raise UsageError(... --request-context ...)): it is a caller-guaranteed check. fit() also validates mla_compute_mode, speculation, etc., so per-argument validation is the house style, and it costs 2 lines; it is not worth a separate finding except as part of the total. However it is the only place --request-context 0 is caught, so it must stay if the flag stays.

#4 [medium] Should fix: the docs say the same thing three times, and advertise out-of-scope multi-model hosting

docs/cli-design.md:446 row, trimmed. Present row is 1 very long line that repeats three things the document already says:

  1. "a request that would exceed N is rejected by the engine's standard context ceiling" — already specified at docs/cli-design.md:1443 ("Context limit | The checkpoint maximum, capped by --request-context at export") and :1493 ("Context limit | The smaller of the prepared context ceiling, capped by --request-context, ..."). Those two table rows are the PR's other two doc edits (:1443, :1493) and say the same thing a third time.
  2. "since the per-request cache allocation is sized from the prepared context" — already true for every core and documented at :828-833.
  3. "Command line only; a core's catalog is fixed at export, so changing it requires re-export" — the same trailing sentence is already carried by --mixed-prefill (:447) and by --kv-cache-limit's note that the runtime flags need no re-export (:874-876).

Smaller, one row:

| --request-context N | Cap the prepared per-request context and max_sequence_tokens at N tokens; shorter contexts need less KV per active request. Command line only; changing it requires re-export. | The recipe's maximum context |

and drop the :1443 and :1493 edits (the flag then appears once, in the flag table). ~2 doc lines + roughly half the 446 row's prose. Note the prose also contradicts the change's own rationale: it advertises "a memory-constrained multi-model deployment", which AGENTS.md:171-175 lists as unapproved scope ("multi-model hosting and routing ... require an explicit maintainer decision").

#5 [medium] Nit: the new setting is invisible in the plan report, and derive()'s new parameter is a pure pass-through

  1. Plan.to_dict() (ignition/planning.py:389-442) does not include prepared_context or context_target, although every other plan setting is recorded there (context, checkpoint_context, prefill_chunk, mixed_prefill, ...). AGENTS.md:452-456 requires the plan, its printed report, and recorded measurements to describe what was prepared; the flag changes max_sequence_tokens yet the printed plan and the bench details["configuration"] = plan.to_dict() (ignition/cli/bench.py:237) cannot show it. Fixing this is an addition, so as a subtraction: if the flag is kept, drop the field and derive the value at the single consumer.

  2. Dead/one-sided flag surface: --request-context is added to _preparation_arguments (ignition/cli/init.py:136-170), which serves export, bench and debug-serve — but NOT flare run (docstring of _server_options at ignition/cli/serve.py:60-72 comments "Derive native server settings independently of preparation's physical KV backing", max_body_bytes still uses recipe.context, not the prepared context). So the docs' claim that a request beyond N "is rejected by the engine's standard context ceiling" holds only because the value reaches BasePreparationConfig.context; nothing in ignition's own debug-serve path re-reads it, and the benchmark's --contexts check at planning.py:248 (selection.required_context > self.context) still compares against the recipe max, not the prepared context. That is a behavioural gap, but for the subtraction lens: the flag is worth nothing without the reject path, so the smaller shape is one value on the plan plus the two consumers, not a new flag family threaded through bench.

  3. ignition/cli/preparation.py:56 adds context: int | None = None to derive() and forwards it at :68 — a pure pass-through parameter of the kind the file otherwise avoids only when one command differs (it does not here: all three callers pass args.request_context or nothing). If the flag goes, this parameter goes entirely (2 lines).

  4. No test asserts any of the new behaviour: grep of tests/ for request_context/prepared_context/context_target/--context → no matches (tests/cli/test_commands.py:80's old --context usage-error assertion the maintainer flagged in #454 is gone from main too). The historical #454 review asked for tests that fail without the change; the diff adds none, so as a subtraction there is nothing to trim here, but it means none of the new branches (the positive check, the two-message chunk branch) is protected.

#7 [medium] Per-file examination record: what each changed file contributes and where nothing can be cut

Diff is +35/−15 over 7 files (pr_files). Hunk inventory:

Net: 34 of 35 added lines exist to carry one integer to one consumer; ~15 can go without losing the behaviour the PR claims.