Simplicity report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/914c7d10-ec90-4f6c-a3dc-f03d1f8d113a.md

Review of PR #533 "Cap the per-request context target" — lens D (simplicity)

Head 02023eba (one commit on base f377dc85), 9 files, +84/−18. Lens D looks for what can be deleted: unneeded code, options, fallbacks, parallel paths, tests that do not prove a behaviour, bloated prose. Rules applied: AGENTS.md:188-199 (no speculative switches or fallbacks without a concrete requirement; "Tests must exercise the affected behavior or contract"), and the charter's small-runtime/single-owner principle (charter line 12, "Keep the runtime small and model-agnostic").

Key findings


Blocking

1. tests/cli/test_planning.py:238-240 — the page-multiple case cannot pass; the check it tests is gone

# Validation: non-page-multiple target rejected
with pytest.raises(UsageError, match="multiple of the"):
    planning.plan(recipe, recipe.checkpoints[0], gpus, context=100, **base)

The head has no page-multiple validation at all. A full read of Plan.__post_init__ (ignition/planning.py:224-296) and fit (:453-556) shows the only new context check is the positive-target guard at :467-468:

if context is not None and context <= 0:
    raise UsageError(f"--request-context {context}: a positive token count is required")

search_code for multiple in ignition/planning.py returns only the --prefill-chunk-size rule at :635-637; there is no % self.page_tokens context check anywhere. So for context=100 on the fixture (context=262144, page_tokens=64, prefill_chunk=4096; tests/cli/test_planning.py:37-42):

  1. plan() passes its own checks (:635 4096 % 64 == 0, 64 <= 4096 <= 262144; :467 100 > 0),
  2. builds a fitting Plan (weights 60 GiB / 2 ranks, 4 GiB graph, 95 GiB free per GPU),
  3. reaches :709-711 and raises UsageError("--prefill-chunk-size 4,096 exceeds the 100-token context this plan allows").

match="multiple of the" does not match that message → Failed: DID NOT MATCH. There are no CI checks on this head, so this has not been seen fail.

Why it matters beyond a red test. Helios rejects a core whose prepared extent or max_sequence_tokens is not a page multiple, at load time (helios/src/model/catalog.rs:49-57, is_multiple_of(page_tokens) → "invalid prepared model configuration"). With the check absent, export --request-context 1000 (1000 % 64 = 40) prepares successfully and then fails at flare run, long after export and after a full preparation run. That is precisely the class of failure the deleted check existed to prevent; the PR description's What Changed still lists "a page-multiple validation" and a chunk error that "distinguishes the default chunk from an explicit one" (the head has a single message, :710-711), so the description overstates the head in two places.

Smaller version (either one).

Restore one check on the value the core is told to serve, next to the existing positive guard:

if context is not None and context <= 0:
    raise UsageError(f"--request-context {context}: a positive token count is required")
if context is not None and min(recipe.context, context, tokens) % recipe.page_tokens:
    raise UsageError(f"--request-context {context:,}: the {recipe.page_tokens:,}-token page size requires a multiple")

100 % 64 = 36 is rejected, so :238-240 passes as written; 500000 resolves to the aligned 262144, so the clamp case at :229-232 stays valid. (Note tokens is not final at that point if the check lives in fit; putting it on recipe.context/context alone is sufficient — recipe.context and page_tokens are page-aligned by every recipe.)

Or, if the alignment rule is deliberately Helios's business: delete :238-240, delete the "a page-multiple validation" and two-arm-chunk-error clauses from the description, and state the alignment rule in docs/cli-design.md:446. What must not ship is the current combination — a test asserting a rule the code does not implement, and a docs row silent on the rule that will bite at load.


Should fix

2. ignition/planning.py:376-381 + :709 — the pool clamp is computed twice

@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)
...
effective_context = min(result.context, result.prepared_context)
if chunk > effective_context:
    raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {effective_context:,}-token context this plan allows")

self.context is min(self.recipe.context, self.tokens) (:371-374), so the second min at :709 is a no-op whenever it is not trivially equal. Behaviour-identical, six lines become three:

@property
def prepared_context(self) -> int:
    """The context the prepared core serves per request; the recipe max when no target is set."""
    return self.context if self.context_target is None else min(self.context, self.context_target)
...
if chunk > result.prepared_context:
    raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {result.prepared_context:,}-token context this plan allows")

This deletes the effective_context local and, more importantly, makes the PR's own claim — "the prepared context never exceeds the pool capacity" — true by construction rather than by a second clamp every future caller must remember to re-derive. (The context_target is None early return must stay: it returns recipe.context, which can exceed the pool-bound context; verified, not dead. benchmark_selection at :260 and bootstrap.py:58 both read the accessor and are unaffected.)

3. tests/cli/test_planning.py:219-232, :243-244 — the test restates the accessor and never asserts the seam it exists for

assert stock_plan.prepared_context == recipe.context                            # :220
assert capped.prepared_context == min(recipe.context, 131072, capped.tokens)    # :226
assert capped.context == min(recipe.context, capped.tokens)                     # :227
assert oversized.prepared_context == min(recipe.context, oversized.tokens)      # :232
assert d["context_target"] == 131072                                            # :244

Lines :220, :226, :227, :232 are transcriptions of ignition/planning.py:374 and :381; :225 and :244 re-assert the field the test just set. None of them would fail if ignition/preparation/bootstrap.py:58 stopped reading plan.prepared_context — and that single line is the only thing that carries the cap into the prepared max_sequence_tokens. A reviewer reading a green test named ..._prepared_context_and_manifest would conclude the cap reaches the core; the test does not show that. AGENTS.md:194-199: "Tests must exercise the affected behavior or contract"; the description claims the test covers "the bootstrap value" and it does not.

Smaller version, using the pattern already in the repo (tests/cli/test_commands.py:94-97) — two assertions replace four mirrored min(...) calls and pin both paths:

kwargs = common_preparation_kwargs(capped, compile_forwards=True, kernel_cache=None, retain_graphs=False)
assert BasePreparationConfig(**kwargs).context == 131072

kwargs = common_preparation_kwargs(stock_plan, compile_forwards=True, kernel_cache=None, retain_graphs=False)
assert BasePreparationConfig(**kwargs).context == recipe.context

Keep :229-232 (the 500000 clamp) — it is the only proof of the documented clamp — and keep the manifest block :246-254.


Nits

  1. ignition/planning.py:467-468 — the positive check lives in fit, which plan() re-enters once per candidate world size (:699-705) and once per shortfall probe (:714-731); every sibling CLI range check is evaluated once in plan() (:627-637, :615-626). With finding 1 restored, both context checks belong in one place — plan() at :634-637, beside the chunk range. Smaller: one branch instead of one per candidate.
  2. ignition/cli/serve.py:319 — f"{' · request context ' + format(plan.prepared_context, ',') if plan.context_target is not None else ''}" is the only format(x, ',') call in ignition/; all ten neighbouring lines use f-string formatting (e.g. f" · concurrency {plan.concurrency}"). Use f"{f' · request context {plan.prepared_context:,}' if plan.context_target is not None else ''}".
  3. tests/cli/test_planning.py:255-257 — three consecutive blank lines before def test_row_shard_attention_accounting_sizing_and_preparation_manifest; the rest of the file separates by two.
  4. ignition/planning.py:461, :549, :605 — the parameter is context at both public signatures, stored as context_target, so fit ends with the translation context_target=context. Naming the parameter context_target in fit/plan (the CLI already reads args.request_context, and the field/to_dict/manifest keys are all context_target) deletes the translation and the reader's doubt about which bound context= means.
  5. docs/cli-design.md:446 — "Cap … at N tokens, below the recipe's maximum" reads as a rejection rule, but the code clamps a larger N (ignition/planning.py:381, and the test at :229-232 relies on it). Say it resolves to the smaller of N, the recipe maximum, and the KV pool capacity. Related, same row set: docs/cli-design.md:1443 says "The checkpoint maximum" where the new row says "the recipe's maximum" (one term for one thing), and ignition/cli/help.py:38 (not opened) advertises --prefill-chunk-size: 64..{recipe.context}, a range that extends above the prepared context once a cap is set.

Already resolved at this head — do not re-raise

Earlier passes of this review raised these; all are fixed and should not be asked for again:

Verified load-bearing (do not cut in the name of simplicity)

Not verifiable in this review