Clean up environ.py: remove dead env vars, unify deprecation handling, move examples to a unit test (#35060)
This commit is contained in:
+2
-1
@@ -26,7 +26,6 @@ MINIMAX_M2_5_W8A8_4P_IN64K_OUT1K_PREFIX90_ENVS = {
|
||||
"ASCEND_USE_FIA": "1",
|
||||
"SGLANG_SET_CPU_AFFINITY": "1",
|
||||
"SGLANG_ENABLE_OVERLAP_PLAN_STREAM": "1",
|
||||
"SGLANG_NPU_FUSED_MOE_MODE": "2",
|
||||
"SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK": "140000",
|
||||
"DEEP_NORMAL_MODE_USE_INT8_QUANT": "1",
|
||||
"DEEPEP_HCCL_BUFFSIZE": "1024",
|
||||
@@ -65,6 +64,8 @@ MINIMAX_M2_5_W8A8_4P_IN64K_OUT1K_PREFIX90_OTHER_ARGS = [
|
||||
26,
|
||||
"--moe-a2a-backend",
|
||||
"ascend_fuseep",
|
||||
"--fuseep-mode",
|
||||
2,
|
||||
"--deepep-mode",
|
||||
"auto",
|
||||
"--quantization",
|
||||
|
||||
+2
-1
@@ -31,7 +31,6 @@ class TestAscendDistTimeout(CustomTestCase):
|
||||
os.environ["HCCL_BUFFSIZE"] = "2048"
|
||||
os.environ["SGLANG_ENABLE_OVERLAP_PLAN_STREAM"] = "1"
|
||||
os.environ["SGLANG_ENABLE_SPEC_V2"] = "1"
|
||||
os.environ["SGLANG_NPU_FUSED_MOE_MODE"] = "1"
|
||||
os.environ["TRANSFORMERS_VERBOSITY"] = "error"
|
||||
cls.env = os.environ.copy()
|
||||
cls.common_args = [
|
||||
@@ -58,6 +57,8 @@ class TestAscendDistTimeout(CustomTestCase):
|
||||
2,
|
||||
"--moe-a2a-backend",
|
||||
"ascend_fuseep",
|
||||
"--fuseep-mode",
|
||||
1,
|
||||
"--deepep-mode",
|
||||
"auto",
|
||||
"--speculative-draft-model-quantization",
|
||||
|
||||
+2
-1
@@ -20,7 +20,6 @@ MINIMAX_M2_5_W8A8_4P_IN64K_OUT1K_PREFIX90_ENVS = {
|
||||
"ASCEND_USE_FIA": "1",
|
||||
"SGLANG_SET_CPU_AFFINITY": "1",
|
||||
"SGLANG_ENABLE_OVERLAP_PLAN_STREAM": "1",
|
||||
"SGLANG_NPU_FUSED_MOE_MODE": "2",
|
||||
"SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK": "140000",
|
||||
"DEEP_NORMAL_MODE_USE_INT8_QUANT": "1",
|
||||
"DEEPEP_HCCL_BUFFSIZE": "1024",
|
||||
@@ -62,6 +61,8 @@ MINIMAX_M2_5_W8A8_4P_IN64K_OUT1K_PREFIX90_OTHER_ARGS = [
|
||||
26,
|
||||
"--moe-a2a-backend",
|
||||
"ascend_fuseep",
|
||||
"--fuseep-mode",
|
||||
2,
|
||||
"--deepep-mode",
|
||||
"auto",
|
||||
"--quantization",
|
||||
|
||||
+2
-1
@@ -26,7 +26,6 @@ QWEN3_235B_ENVS = {
|
||||
"SGLANG_NPU_PROFILING": "0",
|
||||
"SGLANG_NPU_PROFILING_BS": "27",
|
||||
"SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK": "188416",
|
||||
"SGLANG_NPU_FUSED_MOE_MODE": "2",
|
||||
}
|
||||
|
||||
QWEN3_235B_OTHER_ARGS = [
|
||||
@@ -60,6 +59,8 @@ QWEN3_235B_OTHER_ARGS = [
|
||||
"--disable-radix-cache",
|
||||
"--moe-a2a-backend",
|
||||
"ascend_fuseep",
|
||||
"--fuseep-mode",
|
||||
2,
|
||||
"--speculative-algorithm",
|
||||
"EAGLE3",
|
||||
"--speculative-draft-model-path",
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
"""Unit tests for sglang.srt.environ: EnvField semantics and the deprecated-env registry."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
from contextlib import ExitStack
|
||||
|
||||
from sglang.srt.environ import _DEPRECATED_ENVS, _DeprecatedEnv, envs
|
||||
from sglang.test.ci.ci_register import register_cpu_ci
|
||||
|
||||
register_cpu_ci(est_time=15, suite="base-a-test-cpu")
|
||||
|
||||
|
||||
class TestEnvField(unittest.TestCase):
|
||||
def setUp(self):
|
||||
envs.SGLANG_TEST_RETRACT.clear()
|
||||
self.addCleanup(envs.SGLANG_TEST_RETRACT.clear)
|
||||
|
||||
def test_set_get_clear_is_set(self):
|
||||
self.assertFalse(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), False)
|
||||
|
||||
envs.SGLANG_TEST_RETRACT.set(True)
|
||||
self.assertTrue(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), True)
|
||||
|
||||
envs.SGLANG_TEST_RETRACT.clear()
|
||||
self.assertFalse(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), False)
|
||||
|
||||
def test_set_to_none_is_distinct_from_clear(self):
|
||||
envs.SGLANG_TEST_RETRACT.set(None)
|
||||
self.assertTrue(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIsNone(envs.SGLANG_TEST_RETRACT.get())
|
||||
|
||||
envs.SGLANG_TEST_RETRACT.clear()
|
||||
self.assertFalse(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), False)
|
||||
|
||||
def test_override_restores_previous_state(self):
|
||||
envs.SGLANG_TEST_RETRACT.set(True)
|
||||
with envs.SGLANG_TEST_RETRACT.override(None):
|
||||
self.assertTrue(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIsNone(envs.SGLANG_TEST_RETRACT.get())
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), True)
|
||||
|
||||
envs.SGLANG_TEST_RETRACT.set(None)
|
||||
with envs.SGLANG_TEST_RETRACT.override(True):
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), True)
|
||||
self.assertTrue(envs.SGLANG_TEST_RETRACT.is_set())
|
||||
self.assertIsNone(envs.SGLANG_TEST_RETRACT.get())
|
||||
|
||||
def test_override_with_exit_stack(self):
|
||||
envs.SGLANG_TEST_RETRACT.set(None)
|
||||
exit_stack = ExitStack()
|
||||
exit_stack.enter_context(envs.SGLANG_TEST_RETRACT.override(False))
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), False)
|
||||
exit_stack.close()
|
||||
self.assertIsNone(envs.SGLANG_TEST_RETRACT.get())
|
||||
|
||||
def test_override_is_inherited_by_subprocess(self):
|
||||
command = [
|
||||
sys.executable,
|
||||
"-c",
|
||||
"import os; print(os.getenv('SGLANG_TEST_RETRACT'))",
|
||||
]
|
||||
with envs.SGLANG_TEST_RETRACT.override(True):
|
||||
output = subprocess.check_output(command).decode().strip()
|
||||
self.assertEqual(output, "True")
|
||||
|
||||
output = subprocess.check_output(command).decode().strip()
|
||||
self.assertEqual(output, "None")
|
||||
|
||||
def test_implicit_bool_raises(self):
|
||||
message = re.escape(
|
||||
"Please use `envs.YOUR_FLAG.get()` instead of `envs.YOUR_FLAG`"
|
||||
)
|
||||
|
||||
with self.assertRaisesRegex(RuntimeError, message):
|
||||
if envs.SGLANG_TEST_RETRACT:
|
||||
pass
|
||||
|
||||
with self.assertRaisesRegex(RuntimeError, message):
|
||||
if (1 != 1) or envs.SGLANG_TEST_RETRACT:
|
||||
pass
|
||||
|
||||
with self.assertRaisesRegex(RuntimeError, message):
|
||||
if envs.SGLANG_TEST_RETRACT or (1 == 1):
|
||||
pass
|
||||
|
||||
def test_invalid_value_warns_and_returns_default(self):
|
||||
os.environ["SGLANG_TEST_RETRACT"] = "not-a-bool"
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
self.assertIs(envs.SGLANG_TEST_RETRACT.get(), False)
|
||||
self.assertIn("Invalid value", str(caught[0].message))
|
||||
|
||||
|
||||
class TestDeprecatedEnvRegistry(unittest.TestCase):
|
||||
def _apply(self, old_name, deprecation):
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
deprecation.apply(old_name)
|
||||
return caught
|
||||
|
||||
def test_removed_env_warns_without_forwarding(self):
|
||||
old_name = "SGLANG_TEST_REMOVED_ENV"
|
||||
os.environ[old_name] = "1"
|
||||
self.addCleanup(os.environ.pop, old_name, None)
|
||||
|
||||
caught = self._apply(old_name, _DeprecatedEnv())
|
||||
self.assertIn(f"{old_name} is deprecated", str(caught[0].message))
|
||||
|
||||
def test_renamed_env_forwards_value(self):
|
||||
old_name, new_name = "SGLANG_TEST_OLD_ENV", "SGLANG_TEST_NEW_ENV"
|
||||
os.environ[old_name] = "abc"
|
||||
self.addCleanup(os.environ.pop, old_name, None)
|
||||
self.addCleanup(os.environ.pop, new_name, None)
|
||||
|
||||
caught = self._apply(old_name, _DeprecatedEnv(replacement=new_name))
|
||||
self.assertIn(new_name, str(caught[0].message))
|
||||
self.assertEqual(os.environ[new_name], "abc")
|
||||
|
||||
def test_unset_env_is_a_no_op(self):
|
||||
caught = self._apply("SGLANG_TEST_UNSET_ENV", _DeprecatedEnv())
|
||||
self.assertEqual(len(caught), 0)
|
||||
|
||||
def test_disable_tp_imbalance_check_polarity_is_inverted(self):
|
||||
old_name = "SGLANG_DISABLE_TP_MEMORY_INBALANCE_CHECK"
|
||||
new_name = "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK"
|
||||
os.environ[old_name] = "1"
|
||||
self.addCleanup(os.environ.pop, old_name, None)
|
||||
self.addCleanup(os.environ.pop, new_name, None)
|
||||
|
||||
self._apply(old_name, _DEPRECATED_ENVS[old_name])
|
||||
self.assertIs(envs.SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK.get(), False)
|
||||
|
||||
def test_ms_to_s_transform(self):
|
||||
old_name = "SGLANG_QUEUED_TIMEOUT_MS"
|
||||
os.environ[old_name] = "1500"
|
||||
self.addCleanup(os.environ.pop, old_name, None)
|
||||
self.addCleanup(os.environ.pop, "SGLANG_REQ_WAITING_TIMEOUT", None)
|
||||
|
||||
self._apply(old_name, _DEPRECATED_ENVS[old_name])
|
||||
self.assertEqual(envs.SGLANG_REQ_WAITING_TIMEOUT.get(), 1.5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1773,29 +1773,6 @@ class TestGoldenModelOverrides(_IsolatedPublish):
|
||||
)
|
||||
self.assertEqual(_moe_runner_backend_quant_constraints(_view()), {})
|
||||
|
||||
def test_cutlass_moe_env_override_pass(self):
|
||||
from sglang.srt.arg_groups.overrides import (
|
||||
ResolvedView,
|
||||
_cutlass_moe_env_override,
|
||||
)
|
||||
|
||||
with patch("sglang.srt.environ.envs.SGLANG_CUTLASS_MOE") as e:
|
||||
e.get.return_value = True
|
||||
self.assertEqual(
|
||||
_cutlass_moe_env_override(
|
||||
ResolvedView(SimpleNamespace(quantization="fp8"))
|
||||
),
|
||||
{"moe_runner_backend": "cutlass"},
|
||||
)
|
||||
with self.assertRaises(AssertionError):
|
||||
_cutlass_moe_env_override(
|
||||
ResolvedView(SimpleNamespace(quantization=None))
|
||||
)
|
||||
e.get.return_value = False
|
||||
self.assertEqual(
|
||||
_cutlass_moe_env_override(ResolvedView(SimpleNamespace())), {}
|
||||
)
|
||||
|
||||
def test_gguf_quantization_pass(self):
|
||||
from sglang.srt.arg_groups.overrides import ResolvedView, _gguf_quantization
|
||||
|
||||
|
||||
Reference in New Issue
Block a user