Conventions-and-duplication review — PR #533 "Cap the per-request context target"
PR https://github.com/NVIDIA/hyperflare-inference/pull/533 · author roobyz · open, ready for review · base main · head 9118add · 6 files (+69/−5) · no reviews · no CI checks on the head. It supersedes the same author's closed #454.
Lens: every new construct compared with its closest in-repository precedent, and any existing helper or mechanism it duplicates. Every changed file was read in context and callers were followed: export, debug-serve, bench, multi-host _export_hosts, derive/fit/plan, bootstrap.common_preparation_kwargs, rebuild_manifest.from_plan/reproduction_arguments, and Helios load-time validation (helios/src/server/config.rs:131-226, helios/src/model.rs:261-273, helios/src/model/catalog.rs:44-70).
Head context that matters for this lens: #545 (compositional RecipeParameters and dynamic CLI) has merged, so --request-context is no longer a hand-written argparse entry in ignition/cli/__init__.py (not opened); it is a declared param(...) field on RecipeParameters (ignition/parameters.py:1309-1321). That strengthens the conventions lens: the declaration is now the single place where a flag's form, bounds, help, manifest key and repro behaviour are supposed to live, and two of the findings below are departures from that one-place rule.
Key findings
- Blocking — the declared upper bound makes the PR's own oversized-clamp behaviour unreachable; validation, test and docs contradict each other three ways.
- Blocking —
--request-contextis never emitted inreproduction_args, so a capped core cannot be reproduced from its recorded command, andrepro_always=Trueon the declaration is dead metadata. - Should fix — the page-alignment rule is hand-written in
PlanalthoughParamSpec.multiple_of, used by the closest precedent, already exists. - Should fix — the field declares no
status_label, so the cap is the only preparation setting absent from the printed plan line. - Should fix — the two closed enumerations of core universal fields were not updated.
- Three nits around naming and unconditional hints.
Verdict: blocking issues
Blocking 1 — the declared bound makes the PR's own oversized-clamp behaviour unreachable
Where: ignition/parameters.py:1309-1321 (declaration), :1268-1269 (_recipe_context_limit), :533-545 (enforcement); contradicted by ignition/planning.py:357-363, tests/cli/test_planning.py:310-313, docs/cli-design.md:468.
# ignition/parameters.py:1309-1321
context_target: int | None = param(
None,
flag="--request-context",
group="capacity and compression",
metavar="N",
value_type=int,
min_value=1,
max_fn=_recipe_context_limit, # recipe.context (262144 in the test fixture)
manifest_key="context_target",
scope=ParameterScope.DEPLOYMENT,
repro_always=True,
help="cap the prepared per-request context at N tokens; must be a multiple of the page token count",
)
_recipe_context_limit returns context.recipe.context (parameters.py:1268-1269). ParameterGroup.validate_fields enforces max_fn through the elif branch at :533-545 and raises f"{flag} for {alias} must be {min} through {max}". RecipeParameters.validate calls super().validate(ctx) (:1463); planning.plan calls params.validate(pre_context) before any candidate is fitted (planning.py:540) and fit calls it again (:456). Plan.__post_init__ also validates (:185).
So with a 262144-context fixture recipe (tests/cli/test_planning.py:139), context_target=500000 raises --request-context for X must be 1 through 262144 — yet:
# tests/cli/test_planning.py:310-313 — asserts the call SUCCEEDS and clamps
oversized_params = replace(base_params, context_target=500000)
oversized = planning.plan(recipe, recipe.checkpoints[0], gpus, selected=(0, 1), parameters=oversized_params)
assert oversized.parameters.context_target == 500000
assert oversized.prepared_context == recipe.context
Plan.prepared_context implements min(self.recipe.context, target) (planning.py:357-363), and docs/cli-design.md:468 says "resolves to the smaller of N and the recipe maximum".
Why it matters: the PR's headline contract — "a target above the recipe max simply resolves to the recipe max" — is enforced as a hard error instead, and the PR's only new test asserts the behaviour that validation forbids. Either the test fails, or (if it passes in some path I cannot see without running it) the help text and docs misdescribe the flag.
Fix (pick one, then align all three): drop max_fn=_recipe_context_limit and keep min_value=1, so an oversized target clamps as documented and as prepared_context implements; or keep the rejection and change tests/cli/test_planning.py:310-313, docs/cli-design.md:468 and the help string (parameters.py:1320) to say "at most the recipe maximum". The sibling prefill_chunk (parameters.py:1294-1308) uses max_fn=_recipe_context_limit because a chunk above the context is genuinely invalid; for a cap, clamping is the documented contract, so precedent points at dropping the bound here.
Verified fine: the min_value=1 path produces the --request-context must be a positive integer message (parameters.py:541-542), which tests/cli/test_planning.py:315-317 asserts.
Blocking 2 — --request-context never reaches reproduction_args, so a capped core is not reproducible
Where: ignition/parameters.py:1469-1528, especially :1483-1484, :1491, :1494, :1519; reached from ignition/preparation/rebuild_manifest.py:261.
# ignition/parameters.py:1483-1484 — the universal flags are emitted BY NAME
args.extend(["--max-concurrency", str(self.max_concurrency)])
args.extend(["--prefill-chunk-size", str(self.prefill_chunk)])
...
# :1491, :1494 — and every base field is then skipped by the generic loop
base_field_names = {f.name for f in fields(RecipeParameters)}
for dc_field, spec in self._param_fields():
if dc_field.name in base_field_names or not spec.cli or not _is_enabled(self, spec, ctx):
continue
context_target is declared on RecipeParameters itself (parameters.py:1309), so fields(RecipeParameters) contains it, the generic loop skips it, and no explicit line emits it. Its repro_always=True (:1319) is therefore dead metadata: that flag is only consulted inside the generic loop (:1519), which can never reach this field.
Why it matters: from_plan's reproduction_args (rebuild_manifest.py:331-333 → reproduction_arguments :261 → params.reproduction_args(context)) never contains --request-context, so the recorded command rebuilds at the full recipe context — a different core, and precisely what a reproduce-from-metadata record exists to prevent (AGENTS.md:452-456: the plan, its printed report and its recorded measurements must describe what was prepared). tests/cli/test_planning.py:324-325 asserts "--request-context" in manifest["reproduction_args"], so it fails here too.
Fix, following the precedent two lines above: after :1484 add
if self.context_target is not None:
args.extend(["--request-context", str(self.context_target)])
and drop the ineffective repro_always=True from the declaration. Emitting only when set keeps an unset flag byte-equivalent to stock, matching the guard already used for --autotune-effort/--lock-gpu-clocks/--no-compile (:1522-1527).
Should fix
S1 — the page-multiple rule is hand-written in Plan while ParamSpec.multiple_of already exists
ParamSpec.multiple_of (parameters.py:81) is enforced by validate_fields with one canonical message (:524-532), and the closest precedent for a tokened capacity flag uses it: prefill_chunk declares min_value=64, max_fn=..., multiple_of=64 (parameters.py:1294-1308).
The new field does not declare multiple_of, even though its own help promises it ("must be a multiple of the page token count", parameters.py:1320). The rule instead lives in Plan.__post_init__ with a different message shape:
# ignition/planning.py:186-190
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"
)
Why it matters: one flag's form now has two validation homes — generic spec bounds in parameters.py, bespoke page alignment in planning.py — whereas every other declared flag validates in exactly one place. The reason multiple_of cannot be used verbatim is that the page size is dynamic (Plan.page_tokens, planning.py:324-325, adjusted by adjust_page_tokens), which is exactly the shape max_fn already solves for bounds. Note also that Plan.__post_init__ re-runs on every replace() inside fit's sizing loop (planning.py:475-480), where page_tokens cannot change.
Fix: add a multiple_fn(group, context) beside max_fn (or carry the resolved page size in ParameterContext) so declared and enforced rules stay in one place; at minimum keep the message shape consistent with :524-532.
S2 — the cap is missing from the printed plan line because the field declares no status_label
ignition export MODEL --request-context 131072 prints a GPU line built from plan.parameters.status_parts(plan.parameter_context) (ignition/cli/serve.py:269), and status_parts renders a part only for specs declaring status_label (parameters.py:694-707). The new field declares none. The sibling base fields that change serving do:
# ignition/parameters.py:1368
status_label=lambda v: "experimental RoCE ring (native neighbor relays)" if v else None,
Why it matters: Plan.to_dict (planning.py:379-416) and the bench record (**plan.parameters.to_dict(...), bench.py:265) both carry the cap; only the printed report does not — and AGENTS.md:452-456 names the plan, its printed report and its recorded measurements together. A user who exports with a cap gets no confirmation in the progress output that the cap was applied.
Fix: add a guarded status_label=lambda v: f"request context {v:,}" if v is not None else None, so a stock export's line stays byte-identical.
S3 — the two closed enumerations of core universal fields were not updated
- docs/cli-design.md:448-451: "Core
ignitionowns the universalRecipeParametersfields (--max-concurrency,--prefill-chunk-size,--autotune-effort,--compile-workers,--lock-gpu-clocks,--no-compile,--roce-ring,--roce-chain)" — no--request-context. - docs/preparation-development.md:17-19: "Core
ignitiondefines the universal preparation fields (max_concurrency,prefill_chunk,autotune_effort,compile_workers,lock_gpu_clocks,compiled_forwards,roce_ring,roce_chain)" — nocontext_target.
Why it matters: both are closed lists of the same set, so the PR leaves two statements contradicting the code it adds; a reader of the preparation-development doc concludes the cap lives in an external recipe package. The PR did add the flag row (docs/cli-design.md:468) and the context-limit row (:1436), so this is an omission in one place rather than missing documentation overall.
Fix: add the field to both lists, or replace each list with a pointer to ignition/parameters.py so it cannot drift again.
Nits
N1 — context_hint names a cap the deployment may not have applied. ignition/cli/serve.py:68 unconditionally appends "and the --request-context cap". When the flag is unset — still the default, and the byte-equivalent path the PR claims — no cap exists. The same dict keys its optional entry on presence (**({"decode_weight_bytes": ...} if checkpoint.decode_weight_bytes > 0 else {}), serve.py:70). Guard the clause the same way.
N2 — three names for one served ceiling in to_dict. planning.py:392-397 spreads the parameter dict (which emits context_target) and then adds "context": self.context, "prepared_context", and "checkpoint_context": self.recipe.context (:395-396). With no target prepared_context == checkpoint_context; with a pool-bound plan context == prepared_context. A JSON consumer must know which is the served bound. Unlike pages/tokens/guaranteed_tokens these are restatements. Drop checkpoint_context, or document the three in one place.
N3 — two overlapping ceiling accessors. Plan.context (planning.py:352-355) and Plan.prepared_context (:357-363) differ by one term, and the test pins both meanings (tests/cli/test_planning.py:302-303). Defensible, but each docstring describes itself alone. State the relationship ("context is bounded by the prepared pool; prepared_context is the export-time ceiling").
Verified clean through this lens — do not re-raise
- Seam: ignition/preparation/bootstrap.py:132
"context": plan.prepared_contextremains the single plan→BasePreparationConfigfunnel (:33,common_preparation_kwargs:123-137). One field, one accessor, one consumer line; no new mechanism, no per-model branch (charter: "Keep the runtime small and model-agnostic"). - Declaration style: field-for-field the same as
prefill_chunk(parameters.py:1294-1321): same group, metavar, value_type, min_value, max_fn, manifest_key, DEPLOYMENT scope, help phrasing. - Generated, not duplicated, CLI and help:
ParameterGroup.add_arguments/_format_help/option_arities(parameters.py:388-430, :265-311) produce the flag, itsMODEL --helprow and the Stage-1 pre-scan arity. No hand-written argparse entry survives from the pre-#545 wiring, and there is no second help table to keep in sync. - No duplicate lever: nothing else in
ignition/caps a prepared context (grep forrequest-context|context_target|prepared_contextoverdocsyields only cli-design.md:468 and :1436; over code only the changed files plus serve.py:67-68). Runtime--kv-cache-limit(helios/src/runtime_core/limits.rs:25-36 (not opened)) bounds loaded history at serve time and cannot change the exportedmax_sequence_tokens, so this is not a second lever for the same job. - Manifest plumbing is generic and correct:
manifest_parameters(parameters.py:596-616) emits the base field withmanifest_key="context_target"and DEPLOYMENT scope;from_plan(rebuild_manifest.py:286-335) serializes it with no new code;omit_none=Truekeeps an unset flag out of the manifest. The manifest half of the new test (tests/cli/test_planning.py:326-329) is consistent with this path. - Bench coherence:
Plan.__post_init__comparesselection.required_context > self.prepared_context(planning.py:212) — the right quantity, replacing the stockself.contextcomparison in one line. - Helios contract is consistent: the exported extent really is
plan.prepared_context(→BasePreparationConfig.context→max_sequence_tokens, helios/src/server/config.rs:131-148), and Helios then appliesmin(prepared_sequence_tokens, pages * page_tokens)at load (helios/src/model.rs:261-273), so a cap above the pool shrinking only the artifact matches stock behaviour. The page alignment the catalog validates (helios/src/model/catalog.rs:48-57) is exactly why S1's rule must exist at export time. - Test idiom: the new test reuses the file's existing fixtures and round-trip pattern (
_recipe,_gpu,rebuild_manifest.from_plan+json_format.ParseDict,by_key[...].scope) rather than inventing new scaffolding.
Open questions
- Which is intended for a target above the recipe maximum — clamp (as
prepared_context, docs/cli-design.md:468 and tests/cli/test_planning.py:310-313 say) or reject (asmax_fnenforces)? Only the author can pick; the three surfaces must then agree. This is the single question that determines Blocking 1's fix. - Should
to_dict()["context"]stay pool-bound whileprepared_contextis the export ceiling? tests/cli/test_planning.py:303 pins the current meaning; external consumers are not visible in this tree. - The VRAM table in the description is untestable here — nothing in the tree pins it and no GPU was available. It also holds only under
--kv-cache-limit context|concurrency; whether the description says so is a description-mechanics question for another lens. - Nothing was executed. No CI checks ran on head
9118add; every behavioural claim above is a static read of the cited lines.pytest tests/cli/test_planning.py tests/cli/test_parameters.pysettles Blocking 1, Blocking 2 and S1 in one command.