Skip to content

config: spell the parallel config tier at the call site - #36250

Merged
ch-wan merged 1 commit into
mainfrom
cheng/gc-p1-parallel-tier
Aug 26, 2026
Merged

config: spell the parallel config tier at the call site#36250
ch-wan merged 1 commit into
mainfrom
cheng/gc-p1-parallel-tier

Conversation

@ch-wan

@ch-wan ch-wan commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Motivation

get_parallel() exposes two different things through one spelling. Bare
get_parallel().tp_size answers from the live process groups; the
configured_*_size() accessors answered from the published parallel config. Both
spellings work everywhere, neither says which one it is, and they are not
interchangeable — they provably differ in three situations:

  1. before torch.distributed is initialised, or in a process that has no group, the live
    surface has no answer at all while the configured one does;
  2. initialize_model_parallel aliases the MoE-DP group onto the attention-CP group when
    attn_cp_size > moe_dp_size, so the live sizes stop matching what was configured;
  3. elastic EP rescales the live groups at runtime.

A reader that wants "what did this deployment ask for" and reaches for the live surface
gets a different number in exactly the cases that are hardest to reproduce.

What changes

  • ParallelContext.config is added: it returns the published parallel namespace, and
    raises ValueError("config namespace 'parallel' not published") if nothing published yet.
  • ParallelContext.__getattr__ becomes error-only: it never answers a config leaf. When
    the parallel namespace is published it recognises the name and says where to read it —
    'nccl_port' is a parallel config leaf, not live topology; read it as get_parallel().config.nccl_port — and otherwise raises the plain
    ParallelContext has no 'nccl_port'. (A live size read before dist init still surfaces
    the distributed layer's own tensor model parallel group is not initialized; that path
    does not go through __getattr__ because those names are real properties.)
  • _configured_parallel and the five configured_*_size() accessors are deleted.
  • All 81 call sites of those accessors (30 files) become get_parallel().config.<size>,
    and the reads that meant the configured value but were written against the live surface
    get the same treatment. Reads that genuinely want the live groups keep the bare spelling.
  • test_global_config_read_ratchet.py enumerates the result as 33 (file, size) cells over
    23 files, each with the reason the live property cannot serve it, and asserts that the
    registry and the code agree in both directions. Its subject set — which sizes are
    "live-shadowed" at all — is derived from ParallelContext properties ∩ the parallel
    namespace leaves, so a size that gains a live property joins the watched set without an
    edit here. Every spelling of the call resolves — an aliased import, a module-qualified
    receiver, a local bound to either hop — and TestParallelConfigReadSpellings runs each
    one, because a spelling the scanner cannot resolve drops the read instead of failing.

No behaviour change is intended: every rewritten read keeps the value it had, and the
sites that must stay live are unchanged.

How to verify

export PYTHONPATH=$PWD/python
python -m pytest -q test/registered/unit/test_global_config_read_ratchet.py
python -m pytest -q test/registered/unit/test_launch_path_reads_configured_sizes.py
python -m pytest -q test/registered/unit/test_runtime_context.py

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #32953996109
Latest PR Test (Extra): ❌ Run #32953995839
Latest PR Test (AMD ROCm 7.2): ❌ Run #32953996116

@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: 762949f4c3

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

self._config = None # parallel config bag, wired at publish

@property
def config(self) -> _ConfigBag:

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 Quote the _ConfigBag forward reference

On supported Python 3.10–3.13, annotations are evaluated while the class body executes, but _ConfigBag is not defined until later in this module. Importing runtime_context therefore raises NameError: name '_ConfigBag' is not defined, preventing SGLang from starting. Quote this annotation or enable postponed annotation evaluation.

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-p1-parallel-tier branch from 762949f to bd01f13 Compare August 25, 2026 03:47
@ch-wan ch-wan added the ready-to-merge The PR is ready to merge after the CI is green. label Aug 26, 2026
@ch-wan
ch-wan force-pushed the cheng/gc-p1-parallel-tier branch from bd01f13 to 1303cea Compare August 26, 2026 06:48
@ch-wan
ch-wan force-pushed the cheng/gc-p1-parallel-tier branch from 1303cea to 18e7fd8 Compare August 26, 2026 07:22

@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: 18e7fd86c0

ℹ️ 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 +582 to +585
elif isinstance(node, ast.Import):
for a in node.names:
if a.name.endswith("runtime_context"):
modules.add(a.asname or a.name.split(".")[0])

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 Handle fully qualified imports in the config-read ratchet

When a module uses import sglang.srt.runtime_context without an alias, Python binds only sglang, so this records sglang in modules; however, is_bag_call only recognizes a single-name receiver such as sglang.get_parallel() and cannot match the actual sglang.srt.runtime_context.get_parallel() attribute chain. Consequently, a configured shadowed-size read through that fully qualified spelling silently escapes _CONFIGURED_SIZE_CALL_SITES, even though this scanner explicitly claims to cover module-qualified calls.

Useful? React with 👍 / 👎.

@ch-wan
ch-wan force-pushed the cheng/gc-p1-parallel-tier branch from 18e7fd8 to 27cde8d Compare August 26, 2026 08:12
`get_parallel()` served two facts through one surface: a bare name was the
live process group where a `@property` happened to exist and the published
`parallel` bag otherwise, and the five sizes that are both had to be read
through a separate `configured_*_size()` free-function family. A call site
could not tell which tier it got -- `get_parallel().ep_size` was config,
`get_parallel().moe_ep_size` was live -- and the two tiers are not two
spellings of one number: elastic EP scales the live world away from the
configured one, and `initialize_model_parallel` aliases `_MOE_DP` to
`_ATTN_CP` when `attn_cp_size > moe_dp_size`, which makes a live comparison of
that pair degenerate.

Bare is now the live group and `get_parallel().config.<leaf>` is the published
bag. The five `configured_*_size()` functions are gone (76 call sites
converted), the remaining 291 config-leaf reads moved under the same hop, and
a bare read of a config-only leaf raises an AttributeError naming the `.config`
spelling instead of quietly answering from the bag. Every converted read keeps
its tier; the `config` hop is a plain property over a slot, so config-leaf
reads inside compiled model forwards still trace under `fullgraph=True`.

The two guards follow: `_CONFIGURED_SIZE_CALL_SITES` keys on (file, size) and
derives its subject set from the two sides themselves (ParallelContext
properties intersected with the `parallel` NS leaves) instead of a hand list,
and the launch-path guard builds its remedy text from the same derivation.
Both resolve `get_parallel` aliases and the `getattr` spelling, so neither an
import rename nor a new shadowed size escapes them.
@ch-wan
ch-wan force-pushed the cheng/gc-p1-parallel-tier branch from 27cde8d to 06caed3 Compare August 26, 2026 09:37
@ch-wan
ch-wan merged commit 8005df6 into main Aug 26, 2026
104 of 120 checks passed
@ch-wan
ch-wan deleted the cheng/gc-p1-parallel-tier branch August 26, 2026 10:00
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 31, 2026
nzr-niu pushed a commit to nzr-niu/sglang that referenced this pull request Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd deepseek documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang lora ready-to-merge The PR is ready to merge after the CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant