[Config] Retire get_global_server_args, and clear the deprecated flags that have a replacement (#38375)

This commit is contained in:
Cheng Wan
2026-09-08 16:42:12 -07:00
committed by GitHub
parent 5177a3ec08
commit db272201a2
213 changed files with 625 additions and 892 deletions
@@ -6,7 +6,6 @@ from sglang.srt.layers.layernorm import RMSNorm
from sglang.srt.layers.rotary_embedding import get_rope
from sglang.srt.server_args import (
ServerArgs,
get_global_server_args,
set_global_server_args_for_scheduler,
)
from sglang.srt.utils import (
@@ -120,7 +120,7 @@ class _GlmDistributedCluster:
"--disable-fast-image-processor",
"--tp-size",
"1",
"--cuda-graph-bs",
"--cuda-graph-bs-decode",
"2",
"--base-gpu-id",
"0",
@@ -71,7 +71,7 @@ class ARCluster(DisaggCluster):
"--tokenizer-path",
os.path.join(local_model, "processor"),
"--enable-multimodal",
"--cuda-graph-bs",
"--cuda-graph-bs-decode",
"1",
"--image-processor-backend",
"pil",
@@ -29,10 +29,9 @@ from sglang.multimodal_gen.runtime.disaggregation.scheduler_mixin import (
)
from sglang.multimodal_gen.runtime.disaggregation.transport.codec import pack_tensors
from sglang.multimodal_gen.runtime.pipelines_core import Req
from sglang.srt import server_args as srt_server_args_module
from sglang.srt.observability import trace as srt_trace
from sglang.srt.observability.trace import TraceNullContext, TraceReqContext
from sglang.srt.runtime_context import reset_context
from sglang.srt.runtime_context import get_server_args, reset_context
from sglang.srt.server_args import set_global_server_args_for_scheduler
try:
@@ -63,7 +62,7 @@ def _enable_minimal_otel() -> None:
@contextmanager
def _srt_trace_server_args():
try:
prev_server_args = srt_server_args_module.get_global_server_args()
prev_server_args = get_server_args()
except ValueError: # nothing published yet
prev_server_args = None
# publish resolves what it is handed, so a stand-in cannot go through it.
+20 -25
View File
@@ -39,7 +39,6 @@ annotation is equivalent to ``Arg(help=that_string)``.
from __future__ import annotations
import copy
import dataclasses
import functools
import types
@@ -57,20 +56,6 @@ from typing import (
A = Annotated
class _NoFallback:
"""Sentinel for ``Arg.fallback``: this field declares none.
``None`` cannot serve, because ``None`` is what a field *holds* when the
operator did not type it -- the state a fallback answers for.
"""
def __repr__(self) -> str: # pragma: no cover - debugging aid
return "<no fallback>"
NO_FALLBACK = _NoFallback()
@dataclasses.dataclass(frozen=True)
class Arg:
"""CLI argument metadata attached to a dataclass field via ``Annotated``."""
@@ -96,11 +81,13 @@ class Arg:
# What the field means when nobody said anything -- the bottom of the read
# chain: override, decision, input, then this. Not the dataclass default,
# which stays `None` because that is how the record spells "not typed".
# `None` here means the field declares no fallback, which is the same
# answer the read chain gives without one.
#
# Only a value fixed for the life of the configuration belongs here. One
# that depends on the machine, on another field, or on anything impure is a
# decision, and decisions stay in a hook where their order is visible.
fallback: Any = NO_FALLBACK
fallback: Any = None
@dataclasses.dataclass(frozen=True)
@@ -232,7 +219,20 @@ def fallbacks_of(cls) -> dict:
out = {}
for field in dataclasses.fields(cls):
_, arg = _unwrap_annotated(hints.get(field.name, field.type))
if arg is not None and arg.fallback is not NO_FALLBACK:
if arg is not None and arg.fallback is not None:
# Two things `with_fallback` relies on and cannot check itself,
# asserted where a new declaration passes through. This function is
# cached, so a mutable fallback would hand one shared object to
# every reader; and a field whose dataclass default is not `None`
# can never reach the fallback, which makes the declaration dead.
assert not isinstance(arg.fallback, (list, dict, set)), (
f"{cls.__name__}.{field.name}: a mutable fallback would be "
"shared by every reader -- use a scalar"
)
assert field.default is None, (
f"{cls.__name__}.{field.name}: declares a fallback but defaults "
f"to {field.default!r}, so the fallback is unreachable"
)
out[field.name] = arg.fallback
return out
@@ -246,17 +246,12 @@ def with_fallback(cls, name: str, value: Any) -> Any:
on `if cfg.swa_full_tokens_ratio is None`, and a fallback answering there
would make that branch dead. `test_declared_fallbacks.py` pins both halves.
A container fallback is copied, for the reason a dataclass spells this
`default_factory`.
A mutable fallback would need copying per read, for the reason a dataclass
spells this `default_factory`. Every declared one is a scalar.
"""
if value is not None:
return value
fallback = fallbacks_of(cls).get(name, NO_FALLBACK)
if fallback is NO_FALLBACK:
return value
if isinstance(fallback, (list, dict, set)):
return copy.deepcopy(fallback)
return fallback
return fallbacks_of(cls).get(name, value)
# ---------------------------------------------------------------------------
@@ -29,18 +29,45 @@ def print_deprecated_warning(message: str):
logger.warning(f"\033[1;33m{message}\033[0m")
# Retiring a flag comes in four shapes, and which one you need depends on what
# the flag was and what replaced it:
#
# * the flag is gone and there is no automatic translation
# -> `DeprecatedAction` with `error_message=`, which stops the launch and
# names the replacement;
# * an old boolean whose field survives, possibly renamed
# -> `DeprecatedStoreTrueAction`;
# * an old boolean replaced by one *value* of a new valued flag
# -> `DeprecatedStoreConstAction` with `const_value=`;
# * an old valued flag replaced by a renamed valued flag
# -> `DeprecatedAliasStoreAction`.
#
# Only the second has a registration today (`--disable-cuda-graph`). The other
# three are kept because the shapes recur -- this package has retired flags of
# every one of them -- and the fiddly parts (`nargs=0` on a boolean, where the
# const goes, warn-and-continue versus `parser.error`) are what a
# reimplementation gets wrong. Pass `new_flag=` so the warning tells the
# operator what to switch to; that pointer is the whole point.
class DeprecatedAction(argparse.Action):
"""A retired flag with no automatic translation: stop and say so.
`error_message` should name the replacement, because a bare "unrecognized
arguments" leaves the operator guessing. Without one it warns and continues,
which suits a flag that has become a no-op rather than a rename.
"""
def __init__(self, option_strings, dest, error_message=None, nargs=0, **kwargs):
self.error_message = error_message
super(DeprecatedAction, self).__init__(
option_strings, dest, nargs=nargs, **kwargs
)
super().__init__(option_strings, dest, nargs=nargs, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
if self.error_message is not None:
parser.error(self.error_message)
print_deprecated_warning(
f"The command line argument '{option_string}' is deprecated and will be removed in future versions."
f"The command line argument '{option_string}' is deprecated and "
"will be removed in future versions."
)
@@ -71,10 +98,12 @@ class DeprecatedStoreTrueAction(argparse.Action):
class DeprecatedStoreConstAction(argparse.Action):
"""Deprecated boolean flag that stores a fixed string/value into ``dest``
and prints a warning. Used to translate a legacy boolean flag into a
setting on the new per-phase config dict (e.g.
``--disable-piecewise-cuda-graph`` -> ``cuda_graph_backend_prefill="disabled"``)."""
"""An old boolean whose replacement is one *value* of a valued flag.
The bool-to-enum migration: the operator passes no value, and the action
writes the fixed one `const_value` names onto the new field. `nargs=0`
because the old spelling took no argument.
"""
def __init__(
self,
@@ -93,13 +122,14 @@ class DeprecatedStoreConstAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
replacement = f" Use '{self.new_flag}' instead." if self.new_flag else ""
print_deprecated_warning(
f"'{option_string}' is deprecated and will be removed in a future release.{replacement}"
f"'{option_string}' is deprecated and will be removed in a future "
f"release.{replacement}"
)
setattr(namespace, self.dest, self.const_value)
class DeprecatedAliasStoreAction(argparse.Action):
"""Deprecated alias that stores its value and prints a warning."""
"""An old valued flag renamed: keep the value, move it to the new dest."""
def __init__(self, option_strings, dest, new_flag=None, **kwargs):
self.new_flag = new_flag
@@ -108,6 +138,7 @@ class DeprecatedAliasStoreAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
replacement = f" Use '{self.new_flag}' instead." if self.new_flag else ""
print_deprecated_warning(
f"'{option_string}' is deprecated and will be removed in a future release.{replacement}"
f"'{option_string}' is deprecated and will be removed in a future "
f"release.{replacement}"
)
setattr(namespace, self.dest, values)
@@ -175,6 +175,11 @@ def handle_attention_backend_compatibility(server_args: Any):
# AMD platforms backends
if resolved_view(server_args).attention_backend == "aiter":
if model_config.context_len > 8192:
# The record, via the input snapshot rather than the field: a
# hook may not read a field off the record (the guard in
# `test_resolution_reads_the_declarations.py`), and what this
# needs is the input anyway -- whether the operator asked for a
# memory fraction, not the value in effect.
explicit_mem_fraction = (
getattr(server_args, "_raw_input", None) or {}
).get("mem_fraction_static") is not None
@@ -40,8 +40,8 @@ def parse_cuda_graph_config(server_args: Any):
Precedence (highest first): explicit JSON > convenience > legacy > defaults.
Also populates server_args._cuda_graph_config_locked — the set of
(phase, key) tuples that came from non-default sources; the
auto-disable cascade respects this lock (the old
--enforce-piecewise-cuda-graph semantics generalized).
auto-disable cascade respects this lock (an explicitly supplied prefill
backend skips the cascade, whichever value it is).
"""
cfg = resolving_view(server_args)
raw_input = cfg.cuda_graph_config
@@ -107,8 +107,8 @@ def apply_cuda_graph_compatibility(server_args: Any):
"""Auto-disable prefill cuda graph for incompatible configs.
Rules are split per backend — TcPiecewise and Breakable have
different constraints. Skipped when the user explicitly set the
prefill backend (this folds in the old
--enforce-piecewise-cuda-graph contract).
prefill backend, whichever value they chose (the contract the removed
--enforce-piecewise-cuda-graph used to spell).
"""
cfg = resolving_view(server_args)
@@ -48,7 +48,7 @@ def _inkling_overrides(server_args: Any, hf_config: Any) -> dict:
overrides["mamba_full_memory_ratio"] = 0.1
# Inkling requires the extra-buffer mamba strategy (inkling.py asserts
# enable_mamba_extra_buffer()); the generic "auto" resolution does not cover
# Inkling, so pin it here. Yields to an explicit --mamba-scheduler-strategy.
# Inkling, so pin it here. Yields to an explicit --mamba-radix-cache-strategy.
#
# Compared against the unresolved token rather than the class default: the
# default only answers "unset" while nothing has declared the field first,
+1 -1
View File
@@ -429,7 +429,7 @@ def validate_deepep_v2_dispatch_token_budget(server_args: Any) -> None:
"SGLANG_DEEPEP_V2_NUM_MAX_DISPATCH_TOKENS_PER_RANK: "
f"required={graph_tokens}, capacity={capacity} "
f"(requests={graph_bs}, tokens/request={tokens_per_req}). Raise "
"the environment value or lower --cuda-graph-max-bs."
"the environment value or lower --cuda-graph-max-bs-decode."
)
@@ -132,7 +132,7 @@ class SingleForwardManager:
if bs > self._write_req_capacity:
raise RuntimeError(
f"kv-canary: forward_batch.batch_size={bs} exceeds pre-allocated "
f"write_req_capacity={self._write_req_capacity}; raise --cuda-graph-max-bs "
f"write_req_capacity={self._write_req_capacity}; raise --cuda-graph-max-bs-decode "
f"or check CanaryLaunchCapacities.from_args"
)
if num_tokens > self._write_entry_capacity:
+1 -1
View File
@@ -1375,7 +1375,7 @@ class CommunicateWithAllReduceAndLayerNormFn:
# - During CP extend: zigzag split guarantees all CP ranks have non-zero tokens,
# so no rank hits this path while others proceed to the allgather.
# - During decode: moe_cp allgather is skipped (guarded by is_context_parallel_extend).
# - CUDA graph warmup: not applicable when --disable-piecewise-cuda-graph is used.
# - CUDA graph warmup: not applicable when --cuda-graph-backend-prefill=disabled is used.
if hidden_states.shape[0] == 0:
return hidden_states, residual
+2 -2
View File
@@ -224,8 +224,8 @@ def _run_mega_routed(
assert num_tokens <= num_max_tokens_per_rank, (
f"mega MoE: num_tokens={num_tokens} exceeds cap "
f"SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK="
f"{num_max_tokens_per_rank}; raise the env var or shrink "
f"cuda_graph_max_bs / chunked_prefill_size accordingly"
f"{num_max_tokens_per_rank}; raise the env var or lower "
f"--cuda-graph-max-bs-decode / --chunked-prefill-size accordingly"
)
buf = _get_mega_moe_symm_buffer(
+1 -1
View File
@@ -314,7 +314,7 @@ def _unified_attention_with_output_impl(
sinks: Optional[torch.Tensor] = None,
attn_sink: Optional[torch.Tensor] = None,
# MLA / TRT-LLM / NSA paths pass these through RadixAttention.forward(**kwargs);
# they must appear in the schema when --enforce-piecewise-cuda-graph is on.
# they must appear in the schema when --cuda-graph-backend-prefill=tc_piecewise is on.
cos_sin_cache: Optional[torch.Tensor] = None,
is_neox: Optional[bool] = None,
llama_4_scaling: Optional[torch.Tensor] = None,
@@ -206,7 +206,7 @@ Important details from this validation:
- Use a real `.toml` file path with `--hicache-storage-backend-extra-config`.
- For this validated path, the storage directory was provided through `SGLANG_HICACHE_NIXL_BACKEND_STORAGE_DIR`.
- Use `--mamba-scheduler-strategy extra_buffer` to support page sizes larger than 1.
- Use `--mamba-radix-cache-strategy extra_buffer` to support page sizes larger than 1.
Example TOML file:
@@ -237,7 +237,7 @@ export SGLANG_HICACHE_NIXL_BACKEND_STORAGE_DIR=/tmp/sglang_nixl_e2e_storage
--disable-cuda-graph \
--hicache-storage-backend nixl \
--hicache-storage-backend-extra-config @/tmp/nixl.config.toml \
--mamba-scheduler-strategy extra_buffer
--mamba-radix-cache-strategy extra_buffer
```
Expected behavior for this validated setup:
@@ -193,7 +193,6 @@ from sglang.srt.server_args import ( # noqa: F401 (re-export)
CHUNKED_PREFIX_CACHE_SUPPORTED_ATTENTION_BACKENDS,
ServerArgs,
add_chunked_prefix_cache_attention_backend,
get_global_server_args,
)
from sglang.srt.speculative.adaptive_spec_params import (
resolve_candidate_steps_from_config,
+2 -2
View File
@@ -26,8 +26,8 @@ user's raw input, kept **read-only** for debug and reproduction; what
resolution decided lives in the declarations (``resolution_result``) and, for
business code, in the namespace bags below -- never on this object's fields. The context owns the storage:
publishing goes through ``RuntimeContext.set_server_args`` (the legacy
``set_global_server_args_for_scheduler`` / ``get_global_server_args`` are thin
shims over this slot).
``set_global_server_args_for_scheduler`` is a thin shim over this slot;
``get_global_server_args`` is retired and raises).
``get_exec()`` / ``get_memory()`` / ``get_schedule()`` / ``get_device()`` /
``get_model()`` / ``get_spec()`` / ``get_lora()`` / ``get_mm()`` /
+34 -184
View File
@@ -41,16 +41,13 @@ import logging
import tempfile
import uuid
from contextlib import contextmanager
from typing import Any
from typing import Any, NoReturn
from sglang.kernels.ops.kv_canary.consts import RealKvHashMode
from sglang.srt.arg_groups.arg_utils import (
add_cli_args_from_dataclass,
)
from sglang.srt.arg_groups.argparse_actions import (
DeprecatedAction,
DeprecatedAliasStoreAction,
DeprecatedStoreConstAction,
DeprecatedStoreTrueAction,
)
from sglang.srt.arg_groups.model_override_base import ep_joiner_of, ep_scale_joiner_of
@@ -61,13 +58,8 @@ from sglang.srt.arg_groups.overrides import (
)
from sglang.srt.environ import envs
from sglang.srt.function_call.function_call_parser import FunctionCallParser
from sglang.srt.model_executor.cuda_graph_config import Backend
from sglang.srt.parser.reasoning_parser import ReasoningParser
from sglang.srt.runtime_context import (
get_context,
get_platform,
publish,
)
from sglang.srt.runtime_context import get_platform, publish
from sglang.srt.speculative.decoupled_spec_io import DecoupledSpecIpcConfig
from sglang.srt.utils.network import NetworkAddress, get_free_port, wait_port_available
@@ -210,8 +202,9 @@ class ServerArgs:
A few arguments cannot use the annotation style and must be
registered manually in ``add_cli_args``:
- **Deprecated flags** that redirect to another field via
``DeprecatedAction`` / ``DeprecatedAliasStoreAction`` / etc.
- **Deprecated flags** that redirect to another field via one of the
``Deprecated*Action`` classes in ``arg_groups/argparse_actions.py``
(that module's header says which shape fits which migration).
- **Dynamic choices** computed at runtime (e.g. ``reasoning_parser``
whose choices come from a plugin registry).
- The ``--config`` meta-argument (not a dataclass field).
@@ -434,175 +427,14 @@ class ServerArgs:
)
# --- Deprecated argument registrations ---
parser.add_argument(
"--enable-expert-distribution-metrics",
action=DeprecatedAction,
error_message=(
"--enable-expert-distribution-metrics is no longer supported. Use "
"--expert-balancedness-report-mode with one of: off, server_log, "
"prometheus, both."
),
help=(
"Removed. Use --expert-balancedness-report-mode with one of: "
"off, server_log, prometheus, both."
),
)
parser.add_argument(
"--stream-output",
action=DeprecatedStoreTrueAction,
dest="incremental_streaming_output",
new_flag="--incremental-streaming-output",
help="[Deprecated] Use --incremental-streaming-output instead.",
)
parser.add_argument(
"--prefill-round-robin-balance",
action=DeprecatedAction,
help="Note: --prefill-round-robin-balance is deprecated now.",
)
parser.add_argument(
"--collect-tokens-histogram",
action=DeprecatedAction,
help="Deprecated. Token histograms are now automatically collected when --enable-metrics is set.",
)
parser.add_argument(
"--nsa-prefill-backend",
dest="dsa_prefill_backend",
action=DeprecatedAliasStoreAction,
new_flag="--dsa-prefill-backend",
default=argparse.SUPPRESS,
type=str,
choices=[
"flashmla_sparse",
"flashmla_sparse_q8",
"flashmla_kv",
"flashmla_auto",
"flashinfer_sparse_mla",
"fa3",
"tilelang",
"aiter",
"trtllm",
],
help="[Deprecated] Use --dsa-prefill-backend instead.",
)
parser.add_argument(
"--nsa-decode-backend",
dest="dsa_decode_backend",
action=DeprecatedAliasStoreAction,
new_flag="--dsa-decode-backend",
default=argparse.SUPPRESS,
type=str,
choices=[
"flashmla_sparse",
"flashmla_sparse_q8",
"flashmla_kv",
"flashmla_auto",
"flashinfer_sparse_mla",
"fa3",
"tilelang",
"aiter",
"trtllm",
],
help="[Deprecated] Use --dsa-decode-backend instead.",
)
parser.add_argument(
"--speculative-dflash-draft-window-size",
type=int,
dest="speculative_draft_window_size",
action=DeprecatedAliasStoreAction,
new_flag="--speculative-draft-window-size",
help=argparse.SUPPRESS,
)
parser.add_argument(
"--mamba-scheduler-strategy",
dest="mamba_radix_cache_strategy",
type=str,
action=DeprecatedAliasStoreAction,
new_flag="--mamba-radix-cache-strategy",
default=ServerArgs.mamba_radix_cache_strategy,
help="Deprecated alias for --mamba-radix-cache-strategy.",
)
parser.add_argument(
"--cuda-graph-max-bs",
type=int,
action=DeprecatedAliasStoreAction,
new_flag="--cuda-graph-max-bs-decode",
dest="cuda_graph_max_bs_decode",
help="Deprecated alias for --cuda-graph-max-bs-decode.",
)
parser.add_argument(
"--cuda-graph-bs",
type=int,
nargs="+",
action=DeprecatedAliasStoreAction,
new_flag="--cuda-graph-bs-decode",
dest="cuda_graph_bs_decode",
help="Deprecated alias for --cuda-graph-bs-decode.",
)
# `disable_cuda_graph` is `no_cli=True`, so this deprecated spelling is
# its only command-line entry point.
parser.add_argument(
"--disable-cuda-graph",
action=DeprecatedStoreTrueAction,
new_flag="--cuda-graph-backend-{decode,prefill}=disabled",
help="Deprecated. Use --cuda-graph-backend-{decode,prefill}=disabled instead.",
)
parser.add_argument(
"--enable-breakable-cuda-graph",
action=DeprecatedStoreConstAction,
dest="cuda_graph_backend_prefill",
const_value=Backend.BREAKABLE,
new_flag="--cuda-graph-backend-prefill=breakable",
help="Deprecated alias for --cuda-graph-backend-prefill=breakable.",
)
parser.add_argument(
"--disable-piecewise-cuda-graph",
action=DeprecatedStoreConstAction,
dest="cuda_graph_backend_prefill",
const_value=Backend.DISABLED,
new_flag="--cuda-graph-backend-prefill=disabled",
help="Deprecated alias for --cuda-graph-backend-prefill=disabled.",
)
parser.add_argument(
"--enforce-piecewise-cuda-graph",
action=DeprecatedStoreConstAction,
dest="cuda_graph_backend_prefill",
const_value=Backend.TC_PIECEWISE,
new_flag="--cuda-graph-backend-prefill=tc_piecewise",
help="Deprecated alias for --cuda-graph-backend-prefill=tc_piecewise. "
"Explicitly setting the prefill backend now skips the auto-disable "
"cascade automatically.",
)
parser.add_argument(
"--piecewise-cuda-graph-tokens",
type=int,
nargs="+",
action=DeprecatedAliasStoreAction,
new_flag="--cuda-graph-bs-prefill",
dest="cuda_graph_bs_prefill",
help="Deprecated alias for --cuda-graph-bs-prefill.",
)
parser.add_argument(
"--piecewise-cuda-graph-compiler",
type=str,
choices=["eager", "inductor"],
action=DeprecatedAliasStoreAction,
new_flag="--cuda-graph-tc-compiler",
dest="cuda_graph_tc_compiler",
help="Deprecated alias for --cuda-graph-tc-compiler.",
)
parser.add_argument(
"--piecewise-cuda-graph-max-tokens",
type=int,
action=DeprecatedAliasStoreAction,
new_flag="--cuda-graph-max-bs-prefill",
dest="cuda_graph_max_bs_prefill",
help="Deprecated alias for --cuda-graph-max-bs-prefill.",
)
parser.add_argument(
"--enable-gdn-replayssm-spec",
dest="enable_linear_replayssm_spec",
action=DeprecatedStoreTrueAction,
new_flag="--enable-linear-replayssm-spec",
help="[Deprecated] Use --enable-linear-replayssm-spec instead.",
)
parser.add_argument(
"--enable-flashinfer-allreduce-fusion",
action="store_true",
@@ -648,6 +480,11 @@ class ServerArgs:
# the record exists to remember, and the decision it meant to record
# belongs in the stash, where it carries a source and does not destroy
# the input it was derived from.
# Underscore names are mostly the record's own bookkeeping --
# `_input_frozen`, `_raw_input`, `_resolved_overrides`, the memo slots
# -- which resolution writes on purpose. A *field* spelled that way is
# still configuration, so the test cannot be on spelling alone or that
# one leaf stays writable on a read-only record.
if not name.startswith("_") or name in _underscore_field_names():
if getattr(self, "_input_frozen", False):
raise AttributeError(
@@ -770,11 +607,6 @@ def m3_fp8_attn_gemm_enabled(args) -> bool:
)
# NOTE: The process-wide ServerArgs is owned by the runtime context
# (sglang.srt.runtime_context). The two functions below are LEGACY shims kept
# for the existing call-sites; they publish/read the same live object by
# reference. Do not add new call-sites.
# Imports are in-function so the two modules stay cycle-free at import time.
@functools.lru_cache(maxsize=1)
def _underscore_field_names() -> frozenset:
"""Real dataclass fields whose names start with an underscore.
@@ -792,6 +624,12 @@ def _underscore_field_names() -> frozenset:
)
# NOTE: The process-wide ServerArgs is owned by the runtime context
# (sglang.srt.runtime_context). The two publish functions below are LEGACY
# shims kept for the existing call-sites; they hand over the same live object
# by reference. Do not add new call-sites. The third function is retired and
# only raises.
# Imports are in-function so the two modules stay cycle-free at import time.
def set_global_server_args_for_scheduler(server_args: ServerArgs):
"""Legacy publish shim (role=scheduler) — prefer
``runtime_context.publish(server_args, role=...)`` in new code."""
@@ -806,11 +644,23 @@ def set_global_server_args_for_tokenizer(server_args: ServerArgs):
publish(server_args, role="tokenizer")
def get_global_server_args() -> ServerArgs:
"""Legacy accessor shim — prefer ``get_server_args()`` from
``sglang.srt.runtime_context`` in new code."""
def get_global_server_args() -> NoReturn:
"""Retired. It raises, because what it used to return is the problem: the
record answers with the operator's *input*, so a caller reading a field
resolution decided got a stale value and no error.
return get_context().server_args
The name survives so that a caller importing it from this module lands on
a message instead of an ImportError. Annotated ``NoReturn`` so a type
checker rejects the call rather than accepting the attribute access after
it. The message lives once, in the exception.
"""
raise RuntimeError(
"get_global_server_args() is retired. Read the value that is in effect "
"from its namespace bag -- `get_exec().kernel.attention_backend`, "
"`get_schedule().max_running_requests`, and so on "
"(sglang.srt.runtime_context). For the operator's raw input, which is a "
"different question, `get_server_args()` still answers it."
)
@contextmanager
@@ -25,7 +25,7 @@ class TestNPULoggingBase(CustomTestCase):
[Test Target] --log-requests; --log-requests-level; --log-requests-target; --uvicorn-access-log-exclude-prefixes;
--enable-metrics; --enable-metrics-for-all-scheduler;
--bucket-time-to-first-token; --bucket-inter-token-latency; --bucket-e2e-request-latency;
--collect-tokens-histogram; --prompt-tokens-buckets; --generation-tokens-buckets;
--prompt-tokens-buckets; --generation-tokens-buckets;
--tokenizer-metrics-custom-labels-header; --tokenizer-metrics-allowed-custom-labels;
--gc-warning-threshold-secs
"""
@@ -34,7 +34,7 @@ KV_CANARY_ARGS: List[str] = [
"partial",
"--kv-canary-sweep-interval",
"100",
"--disable-piecewise-cuda-graph",
"--cuda-graph-backend-prefill=disabled",
]
+1 -1
View File
@@ -17,7 +17,7 @@ def build_canary_server_args(
args = [
"--kv-canary",
kv_canary_mode.value,
"--disable-piecewise-cuda-graph",
"--cuda-graph-backend-prefill=disabled",
"--context-length",
"16384",
*extra_server_args,
+1 -1
View File
@@ -21,7 +21,7 @@ _MOCK_MODEL_SERVER_ARGS_NO_CANARY: list[str] = [
"dummy",
"--sampling-backend",
"token_oracle",
"--disable-piecewise-cuda-graph",
"--cuda-graph-backend-prefill=disabled",
]