Conventions-and-duplication review — PR #533 "Cap the per-request context target"
PR https://github.com/NVIDIA/hyperflare-inference/pull/533 · author roobyz · open · base main · head 02023eba · 9 files (+84/−18) · no reviews · no CI checks on the head. Follows the same author's closed #454.
Lens: each new construct compared with its closest in-repository precedent, and any existing helper/mechanism it duplicates. Every changed file was read in surrounding code, and the consumers whose behaviour changes were followed: export, debug-serve, bench, multi-host _export_hosts, derive/fit/plan, bootstrap.common_preparation_kwargs, rebuild_manifest, and Helios's load-time catalog validation.
Key findings
- Blocking: the page-multiple validation the description advertises, and the PR's own test asserts (
tests/cli/test_planning.py:238-240), does not exist anywhere in the code at this head.plan(context=100)succeeds, sopytest.raises(UsageError, match="multiple of the")fails, and nothing at export time protects the page-alignedmax_sequence_tokensHelios rejects at load. - Should fix: the one remaining validation (positivity) is placed in
fit(ignition/planning.py:467-468), whereas every sibling flag's form and range lives inplan()'s single pre-flight block (ignition/planning.py:615-637). No precedent for splitting one flag's rules this way, and it re-runs inside the world-size search loop. - Nits (4): a provably redundant
effective_contextmin;to_dict()naming one quantity three ways; a docs wording split ("checkpoint maximum" vs "recipe's maximum"); oneformat(x, ',')call that is the only one of its kind inignition/cli.
The mechanism itself follows the repository's shape well: one Plan field, one accessor, one plan→preparation funnel (ignition/preparation/bootstrap.py:58), threading style matching row_shard_prefill/online_mxfp8_scope, recorded in plan JSON and the manifest, and no duplicating helper anywhere in ignition/.
Blocking
B1 — The page-multiple validation is gone from the code while the PR's test and description still require it
Where: tests/cli/test_planning.py:238-240; missing rule in ignition/planning.py.
# tests/cli/test_planning.py:238-240
# Validation: non-page-multiple target rejected
with pytest.raises(UsageError, match="multiple of the"):
planning.plan(recipe, recipe.checkpoints[0], gpus, context=100, **base)
At head 02023eba there is no --request-context alignment rule anywhere:
grep "multiple of" ignition/planning.py→ only:636-637, the--prefill-chunk-sizerule ("must be a multiple of 64 from 64 through {recipe.context:,}").context_targetappears only atignition/planning.py:186(field),:379/:381(prepared_context),:438(to_dict),:549(fitconstructor keyword).Plan.__post_init__(ignition/planning.py:224-296) holds no such check, andplan()'s pre-flight (ignition/planning.py:615-637) holds none either.grep "request-context" ignition/→ only the argument definitionignition/cli/__init__.py:167, the error string infit(planning.py:468) and the manifest emission (rebuild_manifest.py:265).
So planning.plan(..., context=100) returns a plan and pytest.raises fails: description, test and code disagree at this head. The PR description still lists "a page-multiple validation" among the additions.
Why it matters beyond the failing test. The prepared quantity flows verbatim to the exported core: Plan.prepared_context (ignition/planning.py:377-381) → common_preparation_kwargs "context": plan.prepared_context (ignition/preparation/bootstrap.py:58) → BasePreparationConfig.context → max_sequence_tokens. Helios rejects a core whose prepared extent or limit is not page-aligned at load:
// helios/src/model/catalog.rs:50-57
|| !config.prepared_sequence_tokens.is_multiple_of(page_tokens.max(1)) // :50-52
|| !config.limits.max_sequence_tokens.is_multiple_of(page_tokens) // :54-57
{ return Err("invalid prepared model configuration".into()); } // :70
Without an export-time check, --request-context 100 exports cleanly and dies at serve start. The test is the only place that pins the rule, and it is exactly the rule that vanished.
Fix: add the check to plan()'s pre-flight block beside :635-637, validating the served quantity min(recipe.context, context_target) % page_tokens (so 100 % 64 = 36 is still rejected, while an oversized target that resolves to an aligned value stays accepted — consistent with docs/cli-design.md:446 "below the recipe's maximum" and the description's clamp claim). Settle by running pytest tests/cli/test_planning.py; no CI ran on this head.
Should fix
S1 — One flag, two validation homes; no precedent for it in this file
Where: ignition/planning.py:467-468 versus ignition/planning.py:615-637.
# ignition/planning.py:467-468 (inside fit)
if context is not None and context <= 0:
raise UsageError(f"--request-context {context}: a positive token count is required")
plan() owns every sibling flag's form and range in one pre-flight block:
:615-616mixed prefill vs dflash2:617-618--mixed-prefillsupport:619-624--online-mxfp8/ scope, including:621-622not in recipe.online_mxfp8_scopes:625-626--language-model-only:627-628--max-concurrencyrange:629-631--image-concurrencyrange:635-637--prefill-chunk-sizemultiples/range
Plan.__post_init__ (ignition/planning.py:224-296) is reserved for cross-field rules that need other plan fields (benchmark selection :242-265, force-moe-decode-a16 :266-275, shard-hyperconnections :276-280, row-shard-* :281-296). The positivity check is neither a plan-level cross-field rule nor a planning-search concern; it is a flag-form rule, and its natural home is plan()'s block beside :635-637. The PR splits --request-context the worst way: one rule in fit, the other rule (B1) nowhere.
Cost of the misplacement: fit is re-entered per candidate world size and per shortfall probe through fitted/automatic/candidates/attempt (ignition/planning.py:677-742), so a check that can never differ executes inside the GPU-size search loop. The new test drives both rules through planning.plan(...) (tests/cli/test_planning.py:234-240), so moving the check to plan() drops no coverage.
Fix: move the positivity check into plan()'s pre-flight block and put B1's page-multiple check there too, so both rules for one flag live in one function, once, before any fit call.
Nits
N1 — effective_context = min(result.context, result.prepared_context) (ignition/planning.py:709) is provably a no-op.
709 effective_context = min(result.context, result.prepared_context)
With a target, prepared_context = min(recipe.context, target, tokens) <= context = min(recipe.context, tokens) (:372-374, :377-381); without one, prepared_context = recipe.context >= context. The min therefore always returns prepared_context, and the chunk check at :710-711 could read result.prepared_context alone. (Do not fold prepared_context's None early return at :379-380 into self.context — it is load-bearing, reproducing the pre-PR recipe.context that bootstrap.py:58 passed; the capped arm could read min(self.context, self.context_target).) The PR replaced a one-name check (chunk > result.context) with two names and a reconciling min for the same number.
N2 — to_dict() (ignition/planning.py:438) names one quantity three ways. "context": self.context, "context_target": self.context_target, "prepared_context": self.prepared_context, "checkpoint_context": self.recipe.context — context_target plus prepared_context fully determine the served ceiling, and checkpoint_context equals prepared_context whenever no target is set. context staying pool-bound is now deliberate (tests/cli/test_planning.py:227), but a JSON consumer must know which of the remaining three is the served number.
N3 — docs wording split. docs/cli-design.md:1443 now reads "The checkpoint maximum, capped by --request-context at export", while the new flag row (docs/cli-design.md:446) says "below the recipe's maximum" and its neighbours use "The recipe's …". One term per thing; align :1443 with the row.
N4 — ignition/cli/serve.py:319 is the only format(x, ',') number rendering in ignition/cli (searching the package for format(…) number calls returns nothing else; neighbours use f-string : or planning.format_gpus). Cosmetic; the guard itself (if plan.context_target is not None) matches the sibling row_shard_attention line at :318.
Verified clean through this lens — do not re-raise
- Seam:
"context": plan.prepared_context(ignition/preparation/bootstrap.py:58) stays the single plan→BasePreparationConfigfunnel (bootstrap.py:47-65); one field, one accessor, one keyword, one consumer line. No new mechanism, no per-model branch (charter line 12). - Threading style:
derive(..., context=None)(ignition/cli/preparation.py:45-56) →planning.plan(..., context=context)(:69) →fit(..., context=...)(ignition/planning.py:461) →Plan(..., context_target=context)(:549) — keyword-only with aNonedefault, exactly likerow_shard_prefill/row_shard_attention/online_mxfp8_scope. - All four entry points forward the flag:
ignition/cli/serve.py:207(_export_hosts),:291(_prepare),:476(debug_serve),ignition/cli/bench.py:177. Earlier gaps here are fixed. - Recorded in all three artifacts:
to_dict(ignition/planning.py:438),reproduction_arguments(ignition/preparation/rebuild_manifest.py:264-265, guarded onNone), andfrom_planSCOPE_DEPLOYMENT(:389);add()skipsNone(:350-355), so an omitted flag stays byte-equivalent. - Printed report and bench record carry the cap:
ignition/cli/serve.py:319and the"context_target", "prepared_context"whitelist entry atignition/cli/bench.py:248(tuple at:243-249). Prior findings about these are fixed and withdrawn. - Bench coherence:
ignition/planning.py:260now comparesselection.required_contextagainstprepared_context, so an over-large--contextsfails at planning instead of surprising at run time. - Flag grouping and help:
ignition/cli/__init__.py:167-168sits in thecapacity and compressiongroup beside--prefill-chunk-size(:163-166), matching the group's stated scope ("capacity and compression"), with a(default: …)clause like its neighbours. The docs row (docs/cli-design.md:446) follows the--mixed-prefillrow's shape, including the "Command line only; … re-export" note. - No duplicated mechanism: nothing else in
ignition/caps a prepared context; onmainthe identifiersrequest_context/context_target/prepared_contextdo not exist (the only otherprepared_contextin the tree is unrelated, inhelios/src/frontend/jinja/tests.rs(not opened)). The nearest existing lever, runtime--kv-cache-limit, bounds loaded history at serve time and cannot change the exportedmax_sequence_tokens, so this flag is not a duplicate of it. Plancompatibility: frozen dataclass;context_target: int | None = None(ignition/planning.py:186) placed among defaulted fields, so existing constructions andreplace()calls keep working.- Test placement: the new
test_request_context_target_prepared_context_and_manifest(tests/cli/test_planning.py:211-254) follows the file's existing idioms (_recipe(_),_gpu,rebuild_manifest.from_plan+json_format.ParseDictround-trip,by_key[...].scopeassertion) rather than inventing new fixtures — but it does not pass, see B1.
Open questions
- Did B1 reproduce? Not executed here; it is a grep-level fact plus one pytest command, and no CI checks ran on this head.
- Intended rule for an unaligned target above the recipe maximum — reject, floor, or accept on the resolved value? Needs a decision, then a line in
docs/cli-design.md:446and the flag help. - Should
to_dict()["context"]stay pool-bound (astests/cli/test_planning.py:227pins) or become the served ceiling? Only a maintainer knows whether external consumers depend on the current meaning. - The VRAM table in the description is the author's measurement; nothing in this tree pins it and no test can.