[diffusion] Honor XDG cache for model overlays (#36019)

This commit is contained in:
Xiaoyu Zhang
2026-08-24 14:11:26 +08:00
committed by GitHub
parent 97b176e64c
commit cc74aba330
2 changed files with 21 additions and 3 deletions
@@ -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:
@@ -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"