[diffusion] Honor XDG cache for model overlays (#36019)
This commit is contained in:
@@ -17,6 +17,7 @@ from huggingface_hub.errors import (
|
|||||||
from requests.exceptions import ConnectionError as RequestsConnectionError
|
from requests.exceptions import ConnectionError as RequestsConnectionError
|
||||||
from requests.exceptions import RequestException
|
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.loader.weight_utils import get_lock
|
||||||
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
|
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
|
||||||
from sglang.utils import load_diffusion_overlay_registry_from_env
|
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:
|
def get_diffusion_cache_root() -> str:
|
||||||
return os.path.expanduser(
|
return envs.SGLANG_DIFFUSION_CACHE_ROOT
|
||||||
os.getenv("SGLANG_DIFFUSION_CACHE_ROOT", "~/.cache/sgl_diffusion")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def clear_model_overlay_registry_cache() -> None:
|
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"
|
||||||
Reference in New Issue
Block a user