Skip to content

Add recipe-declared --target-head-quantization preparation flag - #518

Closed
nero- wants to merge 1 commit into
NVIDIA:mainfrom
nero-:feat/target-head-quantization
Closed

nero- wants to merge 1 commit into
NVIDIA:mainfrom
nero-:feat/target-head-quantization

Conversation

@nero-

@nero- nero- commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Why

On bandwidth-constrained GPUs such as DGX Spark GB10 (273 GB/s LPDDR5X), reading a full-precision BF16 target vocabulary projection (lm_head, e.g., 1.21 GiB for a 248,320 x 2,560 head) consumes a significant fraction of single-user decode step time and unified KV memory. Because Flare preserves checkpoint precision by default and prohibits environment-variable behavior switches, opting into a quantized target vocabulary head requires an explicit recipe-declared CLI preparation flag carried through Plan and PreparationManifest while keeping core ignition strictly recipe-free.

This PR supplies the recipe-free core declaration, CLI flag, validation, and PreparationManifest (SCOPE_TARGET_WEIGHT) plumbing consumed by the companion local-inference-lab/hyperflare-recipes PR (local-inference-lab/hyperflare-recipes#40) for Qwen3.8-Flash-Next (merge this PR before or alongside the recipe PR).

What Changed

  • Recipe declaration (ignition/declaration.py):
    • Added Recipe.target_head_quantizations: tuple[str, ...] = () and validated in Recipe.__post_init__ that entries name supported target head formats ("mxfp8").
  • CLI & planning plumbing (ignition/cli/__init__.py, ignition/cli/preparation.py, ignition/cli/serve.py, ignition/cli/bench.py, ignition/planning.py):
    • Before: no CLI flag or Plan field existed to opt into target vocabulary head quantization.
    • After: added the default-None, model-agnostic --target-head-quantization {mxfp8} advanced preparation flag across export, debug-serve, and bench, forwarded through derive(...), _export_hosts, _prepare (including the startup status summary), debug_serve, and bench.
    • Added Plan.target_head_quantization: str | None = None, validated against self.recipe.target_head_quantizations in Plan.__post_init__ (raising UsageError naming self.checkpoint.alias when unsupported), and included "target_head_quantization" in Plan.to_dict() (and bench configuration output) only when set.
  • Preparation manifest & docs (ignition/preparation/rebuild_manifest.py, docs/cli-design.md):
    • Appended ['--target-head-quantization', plan.target_head_quantization] in reproduction_arguments(...) when set, and emitted target_head_quantization under SCOPE_TARGET_WEIGHT in PreparationManifest (from_plan) when set (omitted when None so existing default-precision cores remain 100% compatible across flare combine and --reuse-weights, with zero changes to helios/ or Protobuf schemas).
    • Documented --target-head-quantization {mxfp8} in docs/cli-design.md.
  • Tests (tests/cli/test_commands.py, tests/cli/test_planning.py):
    • Added recipe-free unit tests verifying model-agnostic --help text across export / debug-serve / bench, derive(...) forwarding and unsupported-recipe rejection, Recipe / Plan validation, Plan.to_dict(), and deterministic PreparationManifest (SCOPE_TARGET_WEIGHT + reproduction_args) Protobuf round-trip.

Claimed Benefit / Result

  • Core ignition remains strictly recipe-free (ignition/components/ retains its exact 13 Helios-ABI modules), Helios runtime policy and PreparedContract are untouched, and omitting --target-head-quantization leaves plans, Plan.to_dict(), PreparationManifest entries, exports, and checkpoint precision completely unchanged.
  • Enables any recipe declaring target_head_quantizations=("mxfp8",) (starting with the companion Qwen3.8 recipe) to prepare opt-in MXFP8 target lm_head weights without environment variables, with automatic TARGET_WEIGHT scope validation in flare combine and --reuse-weights. End-to-end serving gains observed on DGX Spark GB10 with the companion Qwen3.8 recipe (+7.5–9.0% C1 decode, ~600 MiB saved on TP1, 44/44 quality gate PASS; plus combined-stack TP2 RoCE 116.0 / 164.2 / 230.5 / 332.4 tok/s abbench and 100% quality gate) belong to the paired core + recipe stack, not this core flag alone.

Supporting Evidence & Limitations

  • Post-rebase validation on Linux ARM64 DGX Spark GB10 (f54928b rebased onto origin/main 2771618):
    • pytest -v tests/preparation/test_core_boundary.py tests/test_design_review_hook.py tests/cli/ -k "not test_preparation_manifest_resolves_scopes_and_dflash2_inheritance": 144 passed, 0 failed in 4.35s (covers core boundary invariants, commit-msg design-review hook, model-agnostic CLI flag parsing, derive forwarding/rejection, Recipe/Plan validation, deterministic PreparationManifest SCOPE_TARGET_WEIGHT + reproduction_args Protobuf round-trip, and native CLI tests; test_preparation_manifest_resolves_scopes_and_dflash2_inheritance was deselected only because the test host's prebuilt flare_heliopause wheel predates 2771618).
  • End-to-end GPU validation: TP1 and TP2 RoCE Qwen3.8-Flash-Next exports using --target-head-quantization mxfp8 were exported and served via flare run on DGX Spark GB10 (SM121) with the companion hyperflare-recipes PR.
  • Limitations / unrun checks:
    • Rust cargo test crates were not run because no Rust or Protobuf files were modified.

Discord: nero

Bandwidth-limited GPUs such as DGX Spark GB10 (273 GB/s LPDDR5X) spend a
measurable share of each single-user decode step reading a full-precision BF16
vocabulary projection (`lm_head`, e.g. 1.21 GiB for a 248,320 x 2,560 head) and
reserve that weight memory out of the unified KV cache budget. Checkpoint
precision must remain the default, and Flare forbids environment-variable
behavior switches, so opting into a quantized target vocabulary head requires an
explicit recipe-declared preparation flag carried through `Plan` and
`PreparationManifest` without adding model-specific logic to core `ignition`.

Changes:
- Add `Recipe.target_head_quantizations: tuple[str, ...] = ()` in
  `ignition/declaration.py`, validated in `Recipe.__post_init__` to accept
  supported target head formats (`"mxfp8"`).
- Add the default-None, model-agnostic `--target-head-quantization {mxfp8}`
  advanced preparation flag in `ignition/cli/__init__.py` across `export`,
  `debug-serve`, and `bench`, forwarded through `ignition/cli/preparation.py::derive`,
  `ignition/cli/serve.py` (`_export_hosts`, `_prepare` including startup status
  summary, and `debug_serve`), and `ignition/cli/bench.py` (`run` and `_measure`).
- Add `Plan.target_head_quantization: str | None = None` in `ignition/planning.py`,
  validate against `self.recipe.target_head_quantizations` in `Plan.__post_init__`
  (raising `UsageError` naming `self.checkpoint.alias` when unsupported), and
  record it in `Plan.to_dict()` when set.
- Record `--target-head-quantization <format>` in
  `ignition/preparation/rebuild_manifest.py::reproduction_arguments` and emit
  `target_head_quantization` under `SCOPE_TARGET_WEIGHT` in
  `PreparationManifest` (`from_plan`) when set (omitted when `None` so existing
  default-precision cores remain compatible across `combine` and `--reuse-weights`
  with zero Protobuf or Rust changes).
- Document `--target-head-quantization {mxfp8}` in `docs/cli-design.md`.
- Add recipe-free unit tests in `tests/cli/test_commands.py` and
  `tests/cli/test_planning.py` verifying model-agnostic CLI help, `derive`
  forwarding and rejection, `Recipe` / `Plan` validation, `Plan.to_dict()`, and
  `PreparationManifest` (`SCOPE_TARGET_WEIGHT` + `reproduction_args`) Protobuf
  round-trip.

Result:
- Core `ignition` remains strictly recipe-free (`ignition/components/` keeps its
  13 Helios-ABI modules), Helios runtime policy and `PreparedContract` are
  unchanged, and omitting `--target-head-quantization` preserves existing plans,
  exports, and checkpoint precision identically.
- Enables downstream recipes declaring `target_head_quantizations=("mxfp8",)`
  (such as Qwen3.8-Flash-Next in `local-inference-lab/hyperflare-recipes`) to
  prepare opt-in MXFP8 target `lm_head` weights with full `PreparationManifest`
  `TARGET_WEIGHT` scope tracking for `flare combine` and `--reuse-weights`.
  Measured serving gains on GB10 (+7.5-9.0% C1 decode, ~600 MiB memory saved on
  TP1, 44/44 quality checks PASS) belong to the paired core + recipe change, not
  this core flag alone.

Evidence and limitations:
- Rebased onto `origin/main` `2771618` (`PreparationManifest`) and verified
  unit tests covering core boundary invariants, commit-msg design-review hook,
  model-agnostic CLI flag parsing, `derive` forwarding and rejection,
  `Recipe`/`Plan` validation, and deterministic `PreparationManifest`
  `SCOPE_TARGET_WEIGHT` Protobuf round-trip.
- End-to-end TP1 and TP2 RoCE Qwen3.8-Flash-Next exports with
  `--target-head-quantization mxfp8` were qualified on DGX Spark GB10 (SM121)
  with the companion `hyperflare-recipes` PR via `flare run`.
- Limitations: Rust `cargo test` was not run because no Rust or Protobuf files
  were modified.

Design-Signed-Off-By: Antigravity (Gemini); design-review=eb2f
Signed-off-by: Jonathan Gutierrez <john.gtz@icloud.com>
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 518.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review for Agents.

Recommendation: Changes Requested

The layering is right and no redesign is asked for: the setting is an Ignition-only PreparationParameter recorded under SCOPE_TARGET_WEIGHT and omitted when unset (ignition/preparation/rebuild_manifest.py:363-364 (not opened), add() skips None at :350-352), so existing cores stay byte-identical for flare combine / --reuse-weights and no Protobuf or helios/ change is needed. Full detail with file:line citations is in the case file and the full report.

Blockers:

  • The flag never reaches memory planning. It is validated (ignition/planning.py:289-293) and recorded (:411-412), but never sized: fit(...) has no such parameter (:445-453) and its only weight call (:526) leaves Recipe.weights_bytes (ignition/declaration.py:363-374) charging the full BF16 head, so Plan.fits (:383-385), automatic() (:674-680), _shortfall (:551-559) and every printed plan JSON describe a larger model than the flag prepares — a memory-tight host can raise CapacityError for a configuration the flag makes fit. Fix: declare the quantized head's resident bytes (like scale_compressed_device_bytes, declaration.py:85-86) or subtract inside weights_bytes, thread it through fit/plan, and add a planning test showing weights_bytes drops. The analogous --expert-scale-compression already reaches weights_bytes (:367-368), so the expectation is established.

Should fix:

  • Make it a planning input, not a post-hoc patch. derive and the handlers set the field with replace(...) after planning.plan() has run (ignition/cli/preparation.py:60-75, serve.py:206-211, :475-480, bench.py:162-177), so an undeclared format surfaces as CapacityError (planning.py:697-725) instead of the intended UsageError naming the alias — the error depends on free memory. Fix: add target_head_quantization to fit/plan, validate beside the draft-head loop (:487-495), keep Plan.__post_init__ as the invariant, drop the replace plumbing and the four getattr guards.
  • Doc row overclaims. docs/cli-design.md:454 names "Qwen3.8 Flash Next" and says the flag frees the BF16 weight "after conversion"; no in-tree recipe declares target_head_quantizations (recipes are external; companion PR qwen38: add opt-in MXFP8 target lm_head quantization local-inference-lab/hyperflare-recipes#40 is unmerged) and no code here converts or frees it. Fix: say it applies only to declaring recipes in external recipe repositories, drop the named checkpoint and the unmeasured effect, and qualify :453 ("retaining target-head precision") now that both head flags can combine.
  • Evidence paragraph is not reproducible. The TP2 figures 116.0 / 164.2 / 230.5 / 332.4 tok/s have no concurrency labels and no baseline, and abbench (absent from this repository) and both quality gates are undefined. Fix: name the tool and configuration, label each figure, give the main baseline and delta, define the gate; point at the recipe PR for detail. The combined-stack attribution is already correct.
  • Description gaps. State that this repo only declares/validates/records while Recipe.prepare (ignition/declaration.py:212-215) in the recipes repo converts and frees the weight (AGENTS.md:84-87); state that the PR's own new test test_target_head_quantization_validation_and_preparation_manifest (tests/cli/test_planning.py:212-253 (not opened)) passed; note that no CI ran on f54928b (AGENTS.md:57-58, :306).

Nits:

9 nits

Open question for maintainers, not the author: this is now the fourth parallel projection-precision flag, and unmerged PR #312 reaches the same vocabulary-head outcome through a recipe-declared --online-mxfp8-scope group. No rewrite requested — I checked that claim and rejected it as a blocker; the single-mechanism decision belongs upstream.

To opt out, include #autobot:ignore in your post or comment.

@lukealonso

Copy link
Copy Markdown
Collaborator

This needs to be rebased (or closed)

@flare-autobot flare-autobot added area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. enhancement New feature or request performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 29, 2026
@nero-

nero- commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Closing as obsolete after the RecipeParameters migration (local-inference-lab/hyperflare-recipes#54). The companion PR local-inference-lab/hyperflare-recipes#40 has been rebased to declare --target-head-quantization directly on Qwen38Parameters (with adjust_weights_bytes()), so no changes in NVIDIA/hyperflare-inference are needed.

@nero- nero- closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. enhancement New feature or request performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants