Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(server): require a usable startup budget for SGLang profiles (#301)

Krisztian Gajdar038a8d9116a0
diff --git a/deploy/helm/sie-cluster/README.md b/deploy/helm/sie-cluster/README.md
index fd23e3242..8ab5dc586 100644
--- a/deploy/helm/sie-cluster/README.md
+++ b/deploy/helm/sie-cluster/README.md
@@ -621,6 +621,7 @@ profiles:
loadtime:
tensor_parallel_size: 4
request_read_timeout_s: 600
+ startup_timeout_s: 900
```
A complete device-group pool follows. Its CPU, memory, and shared-memory sizes
@@ -657,7 +658,13 @@ workers:
while every device is held evicts the least recently used unpinned group.
- The SGLang generation and embedding adapters accept a width. The generation
adapter also requires `request_read_timeout_s` above width one, because a
- stalled collective produces no bytes and no error.
+ stalled collective produces no bytes and no error, and its own
+ `startup_timeout_s`, because startup at a width is dominated by per-rank graph
+ compilation and capture, so neither `workers.common.modelReadyTimeoutSec` nor
+ the built-in default describes it. Keep the declared budget within
+ `workers.common.modelReadyTimeoutSec` and below the liveness probe budget.
+- A declared `startup_timeout_s` that is not a finite number of seconds above
+ zero is refused when the model loads rather than replaced by a default.
- Width and placement are declared only through `tensor_parallel_size`. Engine
placement flags in `extra_launch_args` (including abbreviations such as
`--tp`) and device-visibility variables in `extra_env` are refused.
diff --git a/packages/sie_server/src/sie_server/adapters/sglang/_server.py b/packages/sie_server/src/sie_server/adapters/sglang/_server.py
index 098591c68..96f16cf2c 100644
--- a/packages/sie_server/src/sie_server/adapters/sglang/_server.py
+++ b/packages/sie_server/src/sie_server/adapters/sglang/_server.py
@@ -239,15 +239,15 @@ def resolve_startup_timeout(timeout_s: float | None = None) -> float:
1. Explicit adapter/profile value (``adapter_options.loadtime.startup_timeout_s``).
2. Environment variables in ``STARTUP_TIMEOUT_ENV_VARS`` order.
3. ``DEFAULT_STARTUP_TIMEOUT_S``.
+
+ Raises:
+ ValueError: If an explicit value is not a finite number greater than
+ zero, or the resolved timeout is not below the worker liveness
+ budget.
"""
- if timeout_s is not None:
- try:
- value = float(timeout_s)
- except (TypeError, ValueError):
- value = 0.0
- if math.isfinite(value) and value > 0:
- return _validate_liveness_budget(value)
- logger.warning("Ignoring invalid SGLang startup timeout override: %r (must be finite > 0)", timeout_s)
+ declared = validate_optional_positive(timeout_s, field="startup_timeout_s")
+ if declared is not None:
+ return _validate_liveness_budget(declared)
for name in STARTUP_TIMEOUT_ENV_VARS:
raw = os.environ.get(name)
diff --git a/packages/sie_server/src/sie_server/adapters/sglang/generation.py b/packages/sie_server/src/sie_server/adapters/sglang/generation.py
index 0e52ee796..6e256e3c8 100644
--- a/packages/sie_server/src/sie_server/adapters/sglang/generation.py
+++ b/packages/sie_server/src/sie_server/adapters/sglang/generation.py
@@ -134,6 +134,33 @@ def _resolve_profile_read_timeout(declared: float | None, *, tensor_parallel_siz
return effective
+def _resolve_profile_startup_timeout(declared: float | None, *, tensor_parallel_size: int) -> float:
+ """Return the engine startup budget for one adapter instance.
+
+ Args:
+ declared: The profile's own value, or None to inherit the environment
+ or module default.
+ tensor_parallel_size: Declared width. Above one the profile must
+ declare its own budget rather than inherit one.
+
+ Raises:
+ ValueError: If the declared value is not a positive finite number, or
+ if a width above one declares none. A group's startup is dominated
+ by per-rank graph compilation and capture rather than by weights,
+ so a process-wide default says nothing about how long this profile
+ needs, and a capture that stalls never fails on its own.
+ """
+ if declared is None and tensor_parallel_size > 1:
+ msg = (
+ f"a profile declaring tensor_parallel_size={tensor_parallel_size} must also declare "
+ "startup_timeout_s. Startup at a width above one is dominated by per-rank graph compilation "
+ "and capture rather than by weights, so no environment or default budget fits it, and a "
+ "capture that stalls never fails on its own."
+ )
+ raise ValueError(msg)
+ return _server.resolve_startup_timeout(declared)
+
+
def _mamba_scheduler_strategy_value(extra_launch_args: list[str]) -> str | None:
"""Return the value passed to ``--mamba-scheduler-strategy``, or ``None``.
@@ -479,7 +506,10 @@ class SGLangGenerationAdapter(GenerationAdapter):
self._speculative_needs_extra_buffer = speculative_needs_extra_buffer
self._extra_launch_args = list(extra_launch_args or [])
self._extra_env = dict(extra_env or {})
- self._startup_timeout_s = _server.resolve_startup_timeout(startup_timeout_s)
+ self._startup_timeout_s = _resolve_profile_startup_timeout(
+ startup_timeout_s,
+ tensor_parallel_size=self._tensor_parallel_size,
+ )
self._lora_paths = dict(lora_paths or {})
self._max_loras_per_batch = max_loras_per_batch
diff --git a/packages/sie_server/tests/adapters/test_sglang.py b/packages/sie_server/tests/adapters/test_sglang.py
index cd8c91e2e..c0707fc77 100644
--- a/packages/sie_server/tests/adapters/test_sglang.py
+++ b/packages/sie_server/tests/adapters/test_sglang.py
@@ -64,13 +64,26 @@ class TestSGLangEmbeddingAdapter:
assert _server.resolve_startup_timeout() == 1234
- def test_startup_timeout_rejects_non_finite_values(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ def test_startup_timeout_skips_non_finite_environment_values(self, monkeypatch: pytest.MonkeyPatch) -> None:
for name in _server.STARTUP_TIMEOUT_ENV_VARS:
monkeypatch.delenv(name, raising=False)
monkeypatch.setenv("SIE_MODEL_READY_TIMEOUT_S", "inf")
monkeypatch.setenv("SIE_SERVER_STARTUP_TIMEOUT_S", "1200")
- assert _server.resolve_startup_timeout(float("inf")) == 1200
+ assert _server.resolve_startup_timeout() == 1200
+
+ @pytest.mark.parametrize("bad", [0, -1, float("inf"), float("nan"), True, "900"])
+ def test_startup_timeout_refuses_an_invalid_profile_value(self, monkeypatch: pytest.MonkeyPatch, bad) -> None:
+ """A declared budget is used exactly or refused, never replaced by a fallback."""
+ for name in _server.STARTUP_TIMEOUT_ENV_VARS:
+ monkeypatch.setenv(name, "1200")
+
+ with pytest.raises(ValueError, match="startup_timeout_s"):
+ _server.resolve_startup_timeout(bad)
+
+ def test_embedding_adapter_refuses_an_invalid_profile_startup_timeout(self) -> None:
+ with pytest.raises(ValueError, match="startup_timeout_s"):
+ SGLangEmbeddingAdapter("test-model", startup_timeout_s=0)
def test_startup_timeout_rejects_liveness_budget_mismatch(self, monkeypatch: pytest.MonkeyPatch) -> None:
for name in _server.STARTUP_TIMEOUT_ENV_VARS:
diff --git a/packages/sie_server/tests/adapters/test_sglang_generation.py b/packages/sie_server/tests/adapters/test_sglang_generation.py
index 6bef62a7c..7542c22ea 100644
--- a/packages/sie_server/tests/adapters/test_sglang_generation.py
+++ b/packages/sie_server/tests/adapters/test_sglang_generation.py
@@ -2885,11 +2885,13 @@ def _tp_adapter(**overrides: Any) -> SGLangGenerationAdapter:
"mem_fraction_static": 0.85,
"served_model_name": "Qwen/Qwen3-4B-Instruct",
}
- # A width above one requires a finite streaming read cap, so supply one by
- # default here and let the tests that are about that rule set it explicitly.
+ # A width above one requires a finite streaming read cap and a declared
+ # startup budget, so supply both by default here and let the tests that are
+ # about those rules set them explicitly.
declared = overrides.get("tensor_parallel_size", 1)
if isinstance(declared, int) and not isinstance(declared, bool) and declared > 1:
kwargs["request_read_timeout_s"] = 120.0
+ kwargs["startup_timeout_s"] = 600.0
kwargs.update(overrides)
return SGLangGenerationAdapter(**kwargs)
@@ -3078,6 +3080,69 @@ def test_declared_read_cap_reaches_the_http_client() -> None:
assert adapter._request_read_timeout_s == 45.5
+def _clear_startup_environment(monkeypatch: pytest.MonkeyPatch) -> None:
+ for name in (*_server.STARTUP_TIMEOUT_ENV_VARS, _server.LIVENESS_BUDGET_ENV_VAR):
+ monkeypatch.delenv(name, raising=False)
+
+
+def test_width_above_one_requires_a_declared_startup_budget(monkeypatch: pytest.MonkeyPatch) -> None:
+ """Startup at a width is graph work per rank, so no inherited default describes it."""
+ _clear_startup_environment(monkeypatch)
+
+ with pytest.raises(ValueError, match="must also declare startup_timeout_s"):
+ _tp_adapter(tensor_parallel_size=2, startup_timeout_s=None)
+
+
+def test_an_environment_startup_budget_does_not_satisfy_a_width(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A process-wide default is set for every model a worker loads, not for this profile."""
+ _clear_startup_environment(monkeypatch)
+ for name in _server.STARTUP_TIMEOUT_ENV_VARS:
+ monkeypatch.setenv(name, "1200")
+
+ with pytest.raises(ValueError, match="must also declare startup_timeout_s"):
+ _tp_adapter(tensor_parallel_size=4, startup_timeout_s=None)
+
+
+def test_width_one_keeps_inheriting_the_startup_budget(monkeypatch: pytest.MonkeyPatch) -> None:
+ _clear_startup_environment(monkeypatch)
+ monkeypatch.setenv("SIE_SGLANG_STARTUP_TIMEOUT_S", "1234")
+
+ assert _tp_adapter()._startup_timeout_s == 1234
+ assert _tp_adapter(tensor_parallel_size=1)._startup_timeout_s == 1234
+
+
[email protected]("width", [1, 2])
[email protected]("bad", [0, -1, float("inf"), float("nan"), True, "900"])
+def test_invalid_startup_budget_is_refused_at_construction(
+ monkeypatch: pytest.MonkeyPatch, width: int, bad: Any
+) -> None:
+ """An unusable declared budget fails where it is declared instead of being replaced by a fallback."""
+ _clear_startup_environment(monkeypatch)
+ monkeypatch.setenv("SIE_SGLANG_STARTUP_TIMEOUT_S", "1200")
+
+ with pytest.raises(ValueError, match="startup_timeout_s"):
+ _tp_adapter(tensor_parallel_size=width, startup_timeout_s=bad)
+
+
+@patch("sie_server.adapters.sglang._server.wait_for_server", return_value=True)
+@patch("sie_server.adapters.sglang._server.subprocess.Popen")
+@patch("sie_server.adapters.sglang._server.find_free_port")
+def test_declared_startup_budget_bounds_a_group_launch(
+ mock_find_port: MagicMock,
+ mock_popen: MagicMock,
+ mock_wait_for_server: MagicMock,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _clear_startup_environment(monkeypatch)
+ monkeypatch.setenv("SIE_MODEL_READY_TIMEOUT_S", "300")
+ mock_find_port.return_value = 30005
+ mock_popen.return_value = MagicMock(poll=MagicMock(return_value=None))
+
+ _launch(_tp_adapter(tensor_parallel_size=2, startup_timeout_s=1500), mock_popen)
+
+ assert mock_wait_for_server.call_args.kwargs["timeout_s"] == 1500
+
+
@patch("sie_server.adapters.sglang._server.subprocess.Popen")
@patch("sie_server.adapters.sglang._server.requests.get")
@patch("sie_server.adapters.sglang._server.find_free_port")