Files
sglang/test/registered/unit/test_server_args_writer_ratchet.py
T
Cheng Wan ebb1c88d23 config: stop writing config onto the published ServerArgs at three sites (#33334)
Each of these wrote a value after resolution so a later reader would find it on
the instance. None of them needed the instance: one write was redundant, and the
two that carry a value the resolved-config readback reports move to
get_context().override, which the readback overlays.

- The SM100 GDN prefill default was written onto ServerArgs and read back one
  line later by initialize_linear_attn_config. It is now the return value of
  flashinfer_gdn_prefill_default, threaded into initialize_linear_attn_config
  (an explicit --linear-attn-prefill-backend still wins) and recorded with
  get_context().override so /server_info reports the backend in effect.
- The XGrammar fallback recorded grammar_backend="none" on the instance. No code
  reads the field after the factory reads it once, but get_internal_state
  reports the whole resolved config, so the fallback now lands there instead:
  the readback tells the truth and the seed keeps the requested backend.
- UnifiedRadixCache.init_hicache re-applied the direct-IO layout fixup that
  __post_init__ already applies: init_hicache only runs when hierarchical cache
  is on, which is exactly when _handle_hicache normalizes page_first to
  page_first_direct (pinned by test_hicache_io_backend_and_mem_layout_
  compatibility::direct_with_page_first). Three fixtures reached the fixup by
  building ServerArgs(model_path="dummy"), whose resolution is skipped, so they
  now declare the layout resolution would have produced.

Writer ratchet 34 -> 31.
2026-08-02 21:22:05 -07:00

82 lines
3.1 KiB
Python

"""Ratchet guard: ``ServerArgs.override`` call-sites may only decrease.
``ServerArgs.override(source, **fields)`` mutates a ``ServerArgs`` *instance*
only — the resolved-config bags on the runtime context never see the write, so
any consumer reading the namespace accessors (``get_exec()`` / ``get_memory()``
/ …) desyncs from the writer. The migration end-state removes this primitive
entirely: post-publish, process-global config changes go through
``get_context().override(source, **fields)`` (which writes the bags), and
per-runner resolved values live on the runner object rather than on a
``ServerArgs`` copy.
Until every call-site is rerouted together with its readers, this exact pin
keeps the writer surface from growing unwatched: new writers must use
``get_context().override``, and each rerouted batch lowers the baseline to
lock in the progress. (The count is textual and includes docstring mentions
and the test-kit's private-config use — the pin tracks growth, not the exact
production-writer census.)
"""
from sglang.test.ci.ci_register import register_cpu_ci
register_cpu_ci(est_time=5, suite="base-a-test-cpu")
import re
import unittest
from pathlib import Path
import sglang
from sglang.test.test_utils import CustomTestCase
_SGLANG_ROOT = Path(next(iter(sglang.__path__)))
# ``server_args.override(`` also matches ``self.server_args.override(``,
# ``<obj>.server_args.override(``, and the ``draft_server_args`` /
# ``dp_server_args`` copies; ``args`` / ``sa`` are the aliases a few call-sites
# bind first.
_WRITER_PATTERNS = [
re.compile(r"server_args\.override\("),
re.compile(r"\bargs\.override\("),
re.compile(r"\bsa\.override\("),
]
# The resolution pipeline itself (its declare face forwards through
# ``override`` by design) and multimodal_gen, whose ServerArgs is a different
# class outside this contract.
_EXCLUDED = (
"srt/server_args.py",
"srt/arg_groups",
"multimodal_gen",
)
_BASELINE = 31
class TestServerArgsWriterRatchet(CustomTestCase):
def test_server_args_override_call_sites_match_the_baseline(self):
count = 0
for path in sorted(_SGLANG_ROOT.rglob("*.py")):
rel = path.relative_to(_SGLANG_ROOT).as_posix()
if rel.startswith(_EXCLUDED):
continue
source = path.read_text()
count += sum(len(p.findall(source)) for p in _WRITER_PATTERNS)
if count > _BASELINE:
self.fail(
f"ServerArgs.override call-sites grew: {count} > baseline "
f"{_BASELINE}. Instance writes never reach the resolved-config "
"bags, so namespace readers desync from the writer. Post-publish "
"process-global changes go through get_context().override(...); "
"per-runner resolved values belong on the runner object."
)
if count < _BASELINE:
self.fail(
f"ServerArgs.override call-sites shrank: {count} < baseline "
f"{_BASELINE}. Lower the baseline in this file to lock in the "
"progress."
)
if __name__ == "__main__":
unittest.main()