Repository navigation
config: constructing a config no longer resolves it - #35907
Conversation
There was a problem hiding this comment.
💡 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, |
There was a problem hiding this comment.
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 👍 / 👎.
61899c4 to
6c1f1a2
Compare
0ee73df to
3ae81a7
Compare
2ceb518 to
48b2540
Compare
3ae81a7 to
9d7c404
Compare
50a4032 to
206c8a1
Compare
9d7c404 to
d06e1c6
Compare
There was a problem hiding this comment.
💡 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)) |
There was a problem hiding this comment.
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 👍 / 👎.
da6799e to
fad16e3
Compare
d06e1c6 to
8560f28
Compare
fad16e3 to
f6fc482
Compare
8560f28 to
ef10029
Compare
f6fc482 to
4cc9b5b
Compare
ef10029 to
1f4985d
Compare
4cc9b5b to
895e318
Compare
There was a problem hiding this comment.
💡 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".
| 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. |
There was a problem hiding this comment.
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 👍 / 👎.
895e318 to
8332e80
Compare
1f4985d to
7462e2f
Compare
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]>
There was a problem hiding this comment.
💡 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".
| if not ( | ||
| isinstance(memo, ModelConfig) and memo.model_path != self.model_path | ||
| ): |
There was a problem hiding this comment.
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 👍 / 👎.
Stack
Part of a series that moves
ServerArgsfrom "mutate the record at construction" to "resolve once, publish into config bags". Each PR stands alone (builds, passes its own tests); review bottom-up.mainWhole-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
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 viaget_context().override).publishasks 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).dp_size, so--tp-size 4 --dwdp-size 4launched one server instead of four, and a speculative benchmark forwarded--mem-fraction-static Noneto 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-spelledServerArgswith no resolution step.ServerArgs.replace_resolved(source, **changes)carries everything resolution left on the instance (raw snapshot, declaration stash, memoizedModelConfig, 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 baredataclasses.replacere-entered resolution on already-resolved values (measured on a 2-GPU Ray run: both scheduler actors ran withchunked_prefill_size=2048while the engine reported 4096). A derived pin forbids baredataclasses.replaceof a record outside the helper, with the helper's own call as the positive control.Verification
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