From cc74aba33077c414e31143cef7b159dbe3a5bcd3 Mon Sep 17 00:00:00 2001 From: Xiaoyu Zhang <1182563586@qq.com> Date: Mon, 24 Aug 2026 14:11:26 +0800 Subject: [PATCH] [diffusion] Honor XDG cache for model overlays (#36019) --- .../runtime/utils/model_overlay.py | 5 ++--- .../test/unit/test_model_overlay.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 python/sglang/multimodal_gen/test/unit/test_model_overlay.py diff --git a/python/sglang/multimodal_gen/runtime/utils/model_overlay.py b/python/sglang/multimodal_gen/runtime/utils/model_overlay.py index 30dee0066..7373a8301 100644 --- a/python/sglang/multimodal_gen/runtime/utils/model_overlay.py +++ b/python/sglang/multimodal_gen/runtime/utils/model_overlay.py @@ -17,6 +17,7 @@ from huggingface_hub.errors import ( from requests.exceptions import ConnectionError as RequestsConnectionError from requests.exceptions import RequestException +from sglang.multimodal_gen import envs from sglang.multimodal_gen.runtime.loader.weight_utils import get_lock from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger from sglang.utils import load_diffusion_overlay_registry_from_env @@ -106,9 +107,7 @@ def _resolve_bundled_overlay_dir(overlay_spec: dict[str, Any]) -> str | None: def get_diffusion_cache_root() -> str: - return os.path.expanduser( - os.getenv("SGLANG_DIFFUSION_CACHE_ROOT", "~/.cache/sgl_diffusion") - ) + return envs.SGLANG_DIFFUSION_CACHE_ROOT def clear_model_overlay_registry_cache() -> None: diff --git a/python/sglang/multimodal_gen/test/unit/test_model_overlay.py b/python/sglang/multimodal_gen/test/unit/test_model_overlay.py new file mode 100644 index 000000000..cbacb77ce --- /dev/null +++ b/python/sglang/multimodal_gen/test/unit/test_model_overlay.py @@ -0,0 +1,19 @@ +"""Unit tests for diffusion model-overlay cache paths.""" + +from sglang.multimodal_gen.runtime.utils.model_overlay import ( + get_diffusion_cache_root, +) + + +def test_uses_xdg_cache_home_by_default(monkeypatch): + monkeypatch.setenv("XDG_CACHE_HOME", "/tmp/sglang-xdg-cache") + monkeypatch.delenv("SGLANG_DIFFUSION_CACHE_ROOT", raising=False) + + assert get_diffusion_cache_root() == "/tmp/sglang-xdg-cache/sgl_diffusion" + + +def test_explicit_diffusion_cache_root_takes_precedence(monkeypatch): + monkeypatch.setenv("SGLANG_DIFFUSION_CACHE_ROOT", "/tmp/sglang-diffusion-cache") + monkeypatch.setenv("XDG_CACHE_HOME", "/tmp/sglang-xdg-cache") + + assert get_diffusion_cache_root() == "/tmp/sglang-diffusion-cache"