Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
perf(server): keep SGLang's JIT kernel builds in the kernel cache root (#989)
Krisztian Gajdarbfee97c2eb3f
diff --git a/packages/sie_server/src/sie_server/adapters/sglang/_server.py b/packages/sie_server/src/sie_server/adapters/sglang/_server.pyindex 6c98bfa58..a09c6f313 100644--- a/packages/sie_server/src/sie_server/adapters/sglang/_server.py+++ b/packages/sie_server/src/sie_server/adapters/sglang/_server.py@@ -113,6 +113,7 @@ _KERNEL_CACHE_DIRS = {"FLASHINFER_WORKSPACE_BASE": "flashinfer","SGLANG_CACHE_DIR": "sglang","SGLANG_DG_CACHE_DIR": "deep-gemm",+ "SGLANG_JIT_CACHE_DIR": "sglang/jit","TORCHINDUCTOR_CACHE_DIR": "torchinductor","TRITON_CACHE_DIR": "triton","XDG_CACHE_HOME": "xdg",@@ -183,6 +184,14 @@ def _kernel_cache_env(env: dict[str, str], *, device_indices: Sequence[int]) ->if not root.is_absolute():logger.warning("SGLang kernel cache disabled: %s must be an absolute path", KERNEL_CACHE_ROOT_ENV_VAR)return {}+ # SGLang's JIT cache leaves out its own build files only when their resolved+ # path lies under the build directory it was given; under a symlinked root it+ # records them by a per-build path, and no later process can reuse the build.+ try:+ root = root.resolve()+ except (OSError, RuntimeError) as exc:+ logger.warning("SGLang kernel cache disabled: cannot resolve %s: %s", root, exc)+ return {}gpu_key = _gpu_cache_key(device_indices)if gpu_key is None:diff --git a/packages/sie_server/tests/adapters/test_sglang.py b/packages/sie_server/tests/adapters/test_sglang.pyindex ae90010d7..93c5dcc0e 100644--- a/packages/sie_server/tests/adapters/test_sglang.py+++ b/packages/sie_server/tests/adapters/test_sglang.py@@ -882,6 +882,7 @@ class TestKernelCacheEnvironment:assert cache_env["SGLANG_DG_CACHE_DIR"] == str(namespace / "deep-gemm")assert cache_env["FLASHINFER_WORKSPACE_BASE"] == str(namespace / "flashinfer")assert cache_env["CUTE_DSL_CACHE_DIR"] == str(namespace / "cutlass")+ assert cache_env["SGLANG_JIT_CACHE_DIR"] == str(namespace / "sglang" / "jit")assert cache_env["TRITON_CACHE_DIR"] == str(namespace / "triton")assert all(Path(path).is_dir() for path in cache_env.values())@@ -919,6 +920,21 @@ class TestKernelCacheEnvironment:assert not explicit.exists()assert "TRITON_CACHE_DIR" in cache_env+ def test_symlinked_root_resolves_to_its_target(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:+ """A mount reached through a symlink yields resolved cache paths."""+ monkeypatch.setattr(_server, "_installed_jit_abi_key", lambda: "abi123")+ monkeypatch.setattr(_server, "_gpu_cache_key", lambda _device_indices: "sm90-gpu123")+ target = tmp_path / "mounted-volume"+ target.mkdir()+ link = tmp_path / "kernel-cache"+ link.symlink_to(target, target_is_directory=True)++ cache_env = _server._kernel_cache_env({_server.KERNEL_CACHE_ROOT_ENV_VAR: str(link)}, device_indices=[0])++ namespace = target.resolve() / "v1" / "abi123" / "sm90-gpu123" / "device-0"+ assert cache_env["SGLANG_JIT_CACHE_DIR"] == str(namespace / "sglang" / "jit")+ assert all(Path(path).is_relative_to(namespace) for path in cache_env.values())+def test_invalid_or_unwritable_root_falls_back(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(_server, "_installed_jit_abi_key", lambda: "abi123")monkeypatch.setattr(_server, "_gpu_cache_key", lambda _device_indices: "sm90-gpu123")@@ -927,6 +943,12 @@ class TestKernelCacheEnvironment:assert _server._kernel_cache_env({_server.KERNEL_CACHE_ROOT_ENV_VAR: "relative"}, device_indices=[0]) == {}assert _server._kernel_cache_env({_server.KERNEL_CACHE_ROOT_ENV_VAR: str(blocker)}, device_indices=[0]) == {}+ loop = tmp_path / "loop"+ loop.symlink_to(loop)+ assert (+ _server._kernel_cache_env({_server.KERNEL_CACHE_ROOT_ENV_VAR: str(loop / "cache")}, device_indices=[0])+ == {}+ )with patch("sie_server.adapters.sglang._server.tempfile.NamedTemporaryFile",