Skip to content

config: record resolution writes in a declaration stash - #35905

Merged
ch-wan merged 6 commits into
mainfrom
cheng/gc-pr1-declarations
Aug 23, 2026
Merged

ch-wan merged 6 commits into
mainfrom
cheng/gc-pr1-declarations

Conversation

@ch-wan

@ch-wan ch-wan commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stack

Part of a series that moves ServerArgs from "mutate the record at construction" to "resolve once, publish into config bags". Each PR stands alone (builds, passes its own tests); review bottom-up.

# PR base
0 #35904 main
1 #35905 #35904
2 #35906 #35905
3 #35907 #35906
4 #35908 #35907
5 #35909 #35908
6 #35910 #35909

Whole-series CI vehicle (not for merge): #35917

Motivation

Resolution used to write ServerArgs fields with bare assignments, so what a handler decided was indistinguishable from what the caller passed in. To project configuration bags from resolution output (later in this stack), every resolution write must be recorded, not just applied.

Modifications

  • Every in-pipeline scalar write goes through a declaration (self._declare(...) on handlers, declare_resolution(...) in the hooks): the write is appended to a declaration stash on the record and applied to the field immediately, so successors that read the field directly see the same value as before.
  • The model-override registry entries and post-process passes declare through the same channel.
  • declare_resolution's docstring states what routing a write through the stash changes: a declaration is replayed last, so an immediate writer that declares a field a deferred writer also decides now beats it. A resolver gating on such a field must read the resolving view, not the raw field.
  • Guards (all derivation-based, each verified by injection):
    • no converted field is assigned bare anywhere in the pipeline;
    • the stash agrees with the fields it declared;
    • the stash accounts for every change resolution made (resolve, diff against the raw snapshot, require a declaration for every changed leaf);
    • an immediate writer must not silently override a deferred writer's different value — the fixture matrix includes a shape that actually reaches that branch (--enable-waterfill --moe-a2a-backend ascend_tp).

Verification

  • Declaration guard suite green at this commit; each guard reddens when its protected property is broken (verified by injecting the corresponding bug).
  • A/B: fully-resolved records across an 11-configuration matrix are field-for-field identical to the base revision.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #32627932977
Latest PR Test (Extra): ❌ Run #32627932879
Latest PR Test (AMD ROCm 7.2): ❌ Run #32627932946

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5f37b0b85

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +184 to +189
for target in targets:
if (
isinstance(target, ast.Attribute)
and isinstance(target.value, ast.Name)
and target.value.id in names
and target.attr in _RESOLVED_FIELDS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Traverse destructured assignment targets

When EAGLE-family speculative decoding auto-selects its parameters, _handle_eagle_family still assigns speculative_num_steps, speculative_eagle_topk, and speculative_num_draft_tokens through a tuple target, but this guard only recognizes a top-level ast.Attribute. Consequently the test passes while those defaults never enter _resolved_overrides; a declaration-based projection therefore retains the unresolved values when the user omits these three options. Walk nested tuple/list targets or convert that assignment to declarations.

Useful? React with 👍 / 👎.

def _bare_assignments():
"""Assignments to a converted field that never reach the stash."""
found = []
for path in sorted(_SRT.rglob("*.py")):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record defaults from out-of-tree platform hooks

For an out-of-tree platform implementing the documented apply_server_args_defaults(server_args) lifecycle hook with ordinary field assignments, this scan cannot inspect the plugin because it only traverses the in-repository _SRT tree. Such defaults are consequently absent from the declaration stash; a stash-based projection loses them, and final declaration replay can also restore an earlier declared value over a later plugin assignment. The platform hook needs a declaration-aware contract or its writes must be captured around invocation rather than relying solely on this local source scan.

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch from 9c39970 to 7b31471 Compare August 22, 2026 07:28
@ch-wan
ch-wan force-pushed the cheng/gc-pr0-publish-once branch 2 times, most recently from 42ffb79 to aa84ade Compare August 22, 2026 07:32
@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch from 7b31471 to ddd6ae6 Compare August 22, 2026 07:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ddd6ae6c6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

server_args.speculative_draft_model_path,
trust_remote_code=server_args.trust_remote_code,
kwargs=kwargs,
declare_resolution(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Capture custom speculative hook writes

When an algorithm registered through SpeculativeAlgorithm.register overrides CustomSpecAlgo.handle_server_args, its field writes still bypass the declaration stash. This is a supported path—the existing TestServerArgsHook explicitly has the callback assign speculative_num_draft_tokens = 7—so a declaration-based projection will retain the unresolved caller/default value instead of the plugin-selected value. Capture mutations around algo.handle_server_args(server_args) or provide the callback with a declaration-aware contract.

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch 2 times, most recently from d2a1198 to 19b2403 Compare August 22, 2026 18:25
@ch-wan
ch-wan force-pushed the cheng/gc-pr0-publish-once branch from aa84ade to 552e109 Compare August 22, 2026 18:25
@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch from 19b2403 to 5243760 Compare August 23, 2026 03:11
@ch-wan
ch-wan force-pushed the cheng/gc-pr0-publish-once branch from 552e109 to a876f2b Compare August 23, 2026 03:23
@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch 2 times, most recently from b185128 to 5b5893b Compare August 23, 2026 03:30
@ch-wan
ch-wan force-pushed the cheng/gc-pr0-publish-once branch from a876f2b to 054794f Compare August 23, 2026 03:30
@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch from 5b5893b to b0cc49e Compare August 23, 2026 08:16
@ch-wan
ch-wan force-pushed the cheng/gc-pr0-publish-once branch from 054794f to 526f7b6 Compare August 23, 2026 08:16
Base automatically changed from cheng/gc-pr0-publish-once to main August 23, 2026 08:16
@ch-wan
ch-wan requested a review from liusy58 as a code owner August 23, 2026 08:16
ch-wan and others added 6 commits August 23, 2026 08:17
The declaration stash is what the config projection reads, so a handler
that only assigns its field leaves that write invisible to it. Route the
handler writes no later reader takes back off the field through
`_declare(source, **fields)`, which records the write and applies it.

The stash has to survive the whole pipeline for that to mean anything,
and it did not: the model-override pass replaced it wholesale, discarding
every declaration made ahead of it. That was invisible while the only
declarations came from pass slots, which all sit at or after the pass;
handlers declare from the first step. It now appends, and an instance
connector -- no hf_config to key overrides on -- keeps what the stash
already holds instead of emptying it.

A guard pins both halves. No converted field is assigned bare anywhere a
ServerArgs instance is in reach: handlers write through `self`, and a
helper elsewhere in the tree writes through a `ServerArgs` parameter --
`set_default_server_args` is called from the pipeline and writes one of
these fields, which is why that field is not converted here. After
resolution, every declared field agrees with its stash entry, across
shapes chosen to reach as many of them as a CPU fixture can.

The exposure census counted assignments only, so converting a handler to
a declaration read as its field having stopped being written, retiring
every pinned pair that reads it. It counts both spellings now.

Co-Authored-By: Claude Opus 5 <[email protected]>
The topology and expert-routing handlers -- DWDP, the a2a MoE backends,
elastic EP, EPLB dispatch, the legacy context-parallel arguments, the
diffusion-LM defaults, and the model capability adjustments -- write their
resolved values straight onto the fields, where the projection that
replaces field materialization cannot see them. They declare now.

Fields with a writer outside the class are left alone: the `arg_groups`
hooks and the NPU default helper assign several of these, and a
declaration whose value materializes at the end of resolution would
overwrite what such a writer had put there. Those writers get an entry
point of their own before their fields convert.

Co-Authored-By: Claude Opus 5 <[email protected]>
The rest of the handlers whose fields nothing outside the class writes:
the model and tokenizer path resolution (ModelScope, GGUF), the load
format, the missing-value defaults, the deprecated-argument
normalization, the GPU memory fractions and CUDA-graph configuration, the
deterministic-inference forcing, and the remaining per-backend defaults.

`adjust_mem_fraction_for_vlm` is included: it reads as a public method but
runs inside the memory handler, so its write is resolution like the rest.
The alias loop in the deprecated-argument handler still assigns through a
name tuple; converting a write whose field name is computed needs the
declaration to name it, so it waits for its own change.

Co-Authored-By: Claude Opus 5 <[email protected]>
The `arg_groups` hooks and the NPU default helper are the resolution
pipeline's extension points, and they wrote their resolved values straight
onto the instance they were handed. `declare_resolution(server_args,
source, **fields)` is the entry point they share with the record's own
handlers -- `ServerArgs._declare` is now a thin call into it -- so a hook's
write reaches the declaration stash the projection reads.

With those writers converted, nothing outside the class assigns a resolved
field any more, and the fields the earlier steps had to leave alone -- the
attention backends, the chunked prefill size, the radix cache and hicache
layout switches, the speculative parameters -- convert too. The whole
resolution write surface is declarations now, so the guard's source scan
covers every field the pipeline resolves.

A resolver that is not a real ServerArgs -- the registry tests hand the
speculative hook a namespace -- declares fields no dataclass knows, so the
field-name check skips it the way the model-override validation already
does.

The hook census counted assignments only, so a hook converting to a
declaration read as its fields having stopped being written. It counts
both spellings now, and covers the NPU helper, which writes through a
`ServerArgs` parameter exactly like the hooks but had never been scanned.

Co-Authored-By: Claude Opus 5 <[email protected]>
The deprecated attention-backend alias was the last writer that reached a
field without the stash: it wrote through a name tuple, so it could not be
converted by naming the field, and it now collects the renames and declares
them in one call.

With that the guard states the whole property instead of tracking the
fields converted so far. Its scan covers every field of the record, so a
resolution write that assigns instead of declaring fails the day it is
written rather than when someone remembers to extend a list. A parameter
named `server_args` counts as a writer whether or not it carries the
annotation, so the scan does not rest on a convention it cannot enforce.

The alias declaration expands a dict, which hides the field names from the
keyword scan the same way the assignment loop hid them; the exposure census
keeps pinning that set, with its drift guard keyed on the handler rather
than on the loop's old shape.

Destructured targets count as writes. The EAGLE auto-sizing assigned three
fields through a tuple target -- `(sa.steps, sa.topk, sa.draft_tokens) =
_auto_choose_speculative_params(...)` -- which is not an `ast.Attribute` at the
top level, so the scan walked past it and the three never reached the stash.
Measured on `--speculative-algorithm EAGLE` without explicit sizing: the record
held 5/4/8 while the bags published `None`, and `tp_worker` calls `range()` on
one of them. The assignment is a declaration now, and the scan flattens
tuple/list targets.

Co-Authored-By: Claude Opus 5 <[email protected]>
The source scan states that no assignment escapes the declaration stash,
which is a statement about the spellings a scan can see. A computed field
name, or a write through a helper the scan does not recognize as holding
the record, would still move a field silently -- and the projection would
then answer with the unresolved value.

So this asks the other question: resolve each shape, compare every field
against what the caller supplied or the field's default, and require the
stash to account for each difference. It is the property the projection
depends on, checked at runtime rather than inferred from the source.

Co-Authored-By: Claude Opus 5 <[email protected]>
@ch-wan
ch-wan force-pushed the cheng/gc-pr1-declarations branch from b0cc49e to f6db340 Compare August 23, 2026 08:17
@ch-wan
ch-wan merged commit 0e22777 into main Aug 23, 2026
2 checks passed
@ch-wan
ch-wan deleted the cheng/gc-pr1-declarations branch August 23, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek ready-to-merge The PR is ready to merge after the CI is green. speculative-decoding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant