Skip to content

config: constructing a config no longer resolves it - #35907

Merged
ch-wan merged 2 commits into
mainfrom
cheng/gc-pr3-resolution-gate
Aug 23, 2026
Merged

ch-wan merged 2 commits into
mainfrom
cheng/gc-pr3-resolution-gate

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

__post_init__ ran the whole resolution pipeline, so every construction produced a resolved record — a fixture inspecting defaults, a config being validated, a record on its way to a subprocess that would resolve it again. That is the reason the record could not stay at what the caller asked for.

Resolution is deterministic on the raw input but not repeatable on its own output: the DP-attention step derives the chunked prefill size from the chunked prefill size, so a second pass halves it again (8192 → 4096 → 2048, measured), and the schedule conservativeness is scaled again (0.3 → 0.09).

This is the only behavioral change in the stack; everything before it is record-keeping and everything after is read redirection.

Modifications

  • Construction is inert. resolve_once() is the single gate: it runs the pipeline unless the record has been through it, and marks the record on every exit (the mark also arms a read-only __setattr__ — post-resolution changes go to the bags via get_context().override).
  • The launcher resolves the engine's record once; publish asks the gate on the way in and finds nothing left to do for a record that arrived resolved (e.g. by pickle, which carries the declarations).
  • Programs that build their own record resolve it before reading what resolution decides. Seven entries across the repository (the model gateway's launcher, benchmarks, examples) did not — e.g. the gateway sized its worker plan from a raw dp_size, so --tp-size 4 --dwdp-size 4 launched one server instead of four, and a speculative benchmark forwarded --mem-fraction-static None to the server it spawns. All seven resolve now, and the census that found them is a test whose universe is the repository, not the package — keyed on the record's import source, because the diffusion runtime has a same-spelled ServerArgs with no resolution step.
  • A copy of a resolved record stays resolved: ServerArgs.replace_resolved(source, **changes) carries everything resolution left on the instance (raw snapshot, declaration stash, memoized ModelConfig, flags — enumerated from the instance, not listed) and appends the change as a declaration so the projection sees it. The Ray paths and the gateway's per-worker copy use it; a bare dataclasses.replace re-entered resolution on already-resolved values (measured on a 2-GPU Ray run: both scheduler actors ran with chunked_prefill_size=2048 while the engine reported 4096). A derived pin forbids bare dataclasses.replace of a record outside the helper, with the helper's own call as the positive control.

Verification

  • Gate refusal and reproducibility suites; the seam has exactly one pipeline caller and the gate's callers are pinned together with the rule they stand for (a non-mechanism caller must resolve a record it built itself from argv).
  • Ray smoke run (dp=2, tp=2, DP attention, 2 GPUs, real weights): generation OK, the DP-attention adjustment logged exactly once, zero read-only violations.
  • Blast radius of the read-only flag measured by flipping it early and running the unit suite; every affected fixture fixed to pass both before and after.
  • A/B: resolved end-state identical to base across the 11-configuration matrix.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): 🚫 Run #32627929745
Latest PR Test (Extra): 🚫 Run #32627929702
Latest PR Test (AMD ROCm 7.2): 🚫 Run #32627929875

@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: a8b669a451

ℹ️ 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".

# ModelScope rewrite: under SGLANG_USE_MODELSCOPE resolution also
# rewrites the path to a local snapshot, which this legacy entry
# never did.
self.server_args.tokenizer_path or self.server_args.model_path,

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 Resolve the parent before loading its tokenizer

When Runtime is created with a model source that resolution rewrites, this fallback does not reproduce the resolved path. For example, owner/repo/model.gguf is downloaded to a local file by _resolve_hf_gguf_model_path, and a ModelScope model is rewritten by _handle_modelscope_paths; however, only the spawned server's copy is now resolved, while Runtime.get_tokenizer() passes the parent's raw identifier to the Hugging Face tokenizer loader. Such runtimes can serve successfully but then fail when get_tokenizer() is called. Resolve the parent before spawning (the child's gate will then be a no-op), or otherwise retain the resolved tokenizer path in the parent.

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from 0ee73df to 3ae81a7 Compare August 22, 2026 09:38
@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch 2 times, most recently from 2ceb518 to 48b2540 Compare August 22, 2026 10:48
@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from 3ae81a7 to 9d7c404 Compare August 22, 2026 17:43
@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch 2 times, most recently from 50a4032 to 206c8a1 Compare August 22, 2026 18:25
@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from 9d7c404 to d06e1c6 Compare August 22, 2026 18:25

@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: 206c8a1f68

ℹ️ 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".

# Runtime builds its own record, so hand it the raw input: rebuilding
# from resolved field values runs the pipeline over its own output (DP
# attention halves chunked_prefill_size a second time).
backend = Runtime(**dict(server_args._raw_input))

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 Resolve programmatic throughput inputs before reading the snapshot

When throughput_test() is called directly with a newly constructed ServerArgs and bench_args.backend == "runtime", this raises AttributeError because construction is now inert and _raw_input is only created by resolve_once(). The CLI path masks the regression by resolving before calling this function, but programmatic callers previously worked; the Ray branch has the same problem when _create_ray_engine_backend() reads _raw_input. Resolve at the start of throughput_test() before selecting either backend.

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch 3 times, most recently from da6799e to fad16e3 Compare August 23, 2026 03:11
@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from d06e1c6 to 8560f28 Compare August 23, 2026 03:11
@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch from fad16e3 to f6fc482 Compare August 23, 2026 03:23
@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from 8560f28 to ef10029 Compare August 23, 2026 03:23
@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch from f6fc482 to 4cc9b5b Compare August 23, 2026 03:30
@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from ef10029 to 1f4985d Compare August 23, 2026 03:30
@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch from 4cc9b5b to 895e318 Compare August 23, 2026 03:40

@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: 895e318070

ℹ️ 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 3645 to +3652
def __post_init__(self):
self._run_resolution_pipeline()
"""Construction leaves the record at what the caller asked for.

Resolution is a separate act, entered through ``resolve_once``: the
launcher runs it once per engine, and every publishing process asks the
gate on the way in. A record that is only constructed -- a fixture, a
config being inspected, one being handed to a subprocess that will
resolve it itself -- stays raw.

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 Resolve records installed directly into the runtime context

When callers use the documented get_context().set_server_args(ServerArgs(...)) path, construction now leaves the record raw and set_server_args() immediately projects those raw fields into the config bags without calling resolve_once(). For example, ServerArgs(model_path="dummy") is supposed to resolve hicache_ratio to 2.0, but a direct install now publishes None, so downstream consumers observe an invalid configuration. Either resolve real ServerArgs instances in set_server_args() (while preserving mock/sentinel support) or remove direct installation as a publishing path and migrate all callers to publish().

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-pr3-resolution-gate branch from 895e318 to 8332e80 Compare August 23, 2026 06:37
@ch-wan
ch-wan force-pushed the cheng/gc-pr2-readers-and-projection branch from 1f4985d to 7462e2f Compare August 23, 2026 08:16
ch-wan and others added 2 commits August 23, 2026 08:18
Resolution is a deterministic function of the raw arguments -- two records
built from the same input declare the same things, which the reproducibility
suite already pins. What it is not is repeatable on its own output: the
DP-attention step derives the chunked prefill size *from* the chunked prefill
size, so a second pass halves it again.

That matters because the pipeline is about to move to publish time, and
publish runs in the parent and again in every child that receives the record.
A child's record arrived by pickle carrying its declarations, so there is
nothing left for it to derive.

`resolve_once` is where that is decided, and it is now the pipeline's only
caller -- construction goes through it too, so the gate cannot be bypassed by
either entry. Publish calls it before projecting, which is a no-op today and
becomes the resolution point once construction stops resolving.

The seam guard moves with it: the pipeline still has exactly one caller, now
the gate, and the gate's own callers are pinned to the two entries.

Co-Authored-By: Claude Opus 5 <[email protected]>
`__post_init__` ran the whole pipeline, so every construction produced a
resolved record -- a fixture inspecting defaults, a config being validated, a
record on its way to a subprocess that would resolve it again. That is the
reason the record cannot stay at what the caller asked for.

Construction is inert now. The launcher resolves the engine's record once,
before anything below it reads a resolved value, and every publishing process
asks the gate on the way in and finds nothing left to do.

Why the launcher and not `publish`: the auto-parser detection is resolution
too, it needs the resolved model path (a ModelScope path is rewritten during
resolution), and it has to run before anything publishes. So the call sits at
the top of the launcher until late resolution has a home of its own, and then
`publish` becomes the only resolution point.

The programs that build their own record resolve it themselves. `launch_server`
dispatches on flags resolution decides, `compile_deep_gemm` subscripts the graph
config, and the one-batch benchmark reads the graph config, the parallel sizes
and the tokenizer path -- all `None` on a record that has only been constructed,
and the benchmark is what `run_bench_one_batch` shells out to. Each asks the
gate; the launcher and `publish` below them get a no-op. `sgl.Runtime`'s
`get_tokenizer()` falls back to the model path instead, because the record it
holds belongs to the caller and stays raw.

The gate's callers are pinned with the rule they stand for rather than as a bare
list: a caller that is not the mechanism has to be a module you can run as a
program. Anything else has a published record to read, or publishes -- which
asks the gate itself, and that is what the multimodal GPU worker's placeholder
does now.

A copy of a resolved record has to stay resolved. `dataclasses.replace` builds
a new instance, so the copy carries no raw snapshot, no declarations and no
materialization flag -- and the publish that follows finds an unmaterialized
record and runs the pipeline over values it already decided. The Ray paths do
exactly that to set `dist_init_addr`: measured, the actor's record came out with
`chunked_prefill_size` halved a second time (4096 -> 2048) and
`schedule_conservativeness` scaled again (0.3 -> 0.09). The same drift is on
main, where `__post_init__` re-resolved at replace time instead.

Measured on a two-GPU Ray run (dp_size=2, tp_size=2, DP attention): both
scheduler actors logged the adjustment a second time, so they scheduled with
`chunked_prefill_size=2048` while the engine reported 4096.

`replace_resolved` is the copy that keeps the parent's resolution and appends
the change to the stash -- appended rather than left on the field, because the
projection reads the raw snapshot plus the declarations, so a field the copy set
on its own would publish the parent's raw value. What it carries is enumerated
from the instance, not listed: `get_model_config()` memoizes on the record and
that cache is filled during resolution, so a copy marked resolved without it
cannot fill it -- the read-only guard refuses the write -- and the schedulers die
on the first `get_model_config()`. Same run, after: one adjustment, and the
actors come up.

Two entries outside the package shipped past the earlier censuses, which are
rooted at `sglang/`. The model gateway's launcher sized its worker plan from a
raw `dp_size`, and `_handle_dwdp` is what turns `--dwdp-size 4` into
`dp_size == 4`: measured, `--tp-size 4 --dwdp-size 4` launched one server
instead of four. A speculative benchmark forwarded resolution's output to the
server it spawns, so with default arguments it built
`--mem-fraction-static None`, which the spawned CLI rejects. Both resolve now,
and the gateway's per-worker copy goes through `replace_resolved`: a deep copy
of a resolved parent carries the read-only flag, so the three field writes it
makes per worker would be refused.

Five more entries read a resolution-written field off a record they built
(mostly a `model_path` that resolution can rewrite for ModelScope). All seven
resolve now, and the census that found them is a test whose universe is the
repository rather than the package. Two spellings the census had to learn the
hard way: `server_args: ServerArgs = ...` is an `AnnAssign`, and keying on
`Assign` alone missed one benchmark; and the diffusion runtime has its own
`ServerArgs` with the same spelling and no resolution -- keying builders on the
spelling rather than the import source put `resolve_once()` on two diffusion
entries once, an `AttributeError` at startup, so the census now follows the
import back to `sglang.srt.server_args` before it counts a builder.

The read-only guard stops exempting underscore names that are real fields:
`_speculative_draft_quantization_explicitly_set` is resolved configuration,
and exempting it by spelling left exactly one leaf writable on a read-only
record.

The pin is derived: no `dataclasses.replace` of a record outside that helper,
with the helper's own call as the positive control.

The diffusion GPU worker's placeholder publish names its own role rather than
borrowing `scheduler`, which would be a lie the moment enforcement narrows the
scheduler's namespace set.

Two consequences worth naming:

Validation moves with resolution. `check_server_args` still runs at launch,
after the resolve, so it still sees a resolved config; a test that asserted an
invalid value is rejected by the constructor now asserts resolution rejects it.

Fixtures that read resolved values say so. The reproducibility suite, the
declaration guard, the exposure census, the golden overrides, the CLI
migration cases and two encoder-mode cases resolve explicitly; the config-bag
contract resolves its reference sibling, which is the whole point of the
sibling. Two suites that installed a record through the roleless
`set_server_args` publish properly instead.

The gateway binding does not call the new copy helper. Its own test suite runs
against an installed sglang wheel, so anything newer than that release is an
`AttributeError` there; it deep-copies and writes the three per-worker values
through `_late_resolution` when the record it was handed is resolved, and by
assignment when it is not.

Whoever forks a child to run the record resolves it first. The pipeline probes
the device -- the default attention backend reads the CUDA capability -- and a
forked child cannot initialize CUDA once its parent has. Construction used to
resolve, so that probe always happened in whoever built the record; with the
gate it happens later, and the benchmark harness hit exactly that
(`RuntimeError: Cannot re-initialize CUDA in forked subprocess`, in a child
running `_launch_subprocesses`). The three sites that hand a record to a fork
without an earlier resolve in the same process ask the gate first, and a test
pins that: a fork of a record, in a module that neither resolves nor publishes
nor uses `spawn`, fails.

Co-Authored-By: Claude Opus 5 <[email protected]>

@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: 9725d83eea

ℹ️ 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 +9622 to +9624
if not (
isinstance(memo, ModelConfig) and memo.model_path != self.model_path
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve model-config memos for remote model paths

When model_path is a RunAI object URI or another remote URL, ModelConfig._maybe_pull_model_for_runai() / _maybe_pull_model_tokenizer_from_remote() intentionally replaces memo.model_path with a local cache directory while ServerArgs.model_path remains the remote URI. This comparison therefore always treats a valid memo as stale, repeatedly pulls/reloads the remote configuration during resolution, and, after resolve_once() arms the read-only guard, the next get_model_config() call reaches self.model_config = ... and raises AttributeError. Track the source path separately or invalidate the memo only when the ServerArgs source actually changes.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant