Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: key the i2v availability cache on the diffusers module, not its id (#13667)
Daniel Han95f51c8ecd36
diff --git a/studio/backend/core/inference/video_i2v.py b/studio/backend/core/inference/video_i2v.pyindex d9e9199f650..4fdb615534d 100644--- a/studio/backend/core/inference/video_i2v.py+++ b/studio/backend/core/inference/video_i2v.py@@ -46,19 +46,22 @@ def i2v_pipeline_available(name: Optional[str]) -> bool:import diffusersexcept Exception: # noqa: BLE001return False- key = (id(diffusers), name)- cached = _AVAILABLE.get(key)- if cached is None:- try:- resolve_i2v_pipeline_class(name)- cached = True- except Exception: # noqa: BLE001 -- an absent or unimportable class is simply unavailable- cached = False- _AVAILABLE[key] = cached- return cached+ # Keyed by name and checked by identity, not by id(diffusers): once a replaced module is collected+ # its id can be handed to the next one, and a stale answer for a module that lacked the class+ # would then hide one that has it.+ entry = _AVAILABLE.get(name)+ if entry is not None and entry[0] is diffusers:+ return entry[1]+ try:+ resolve_i2v_pipeline_class(name)+ available = True+ except Exception: # noqa: BLE001 -- an absent or unimportable class is simply unavailable+ available = False+ _AVAILABLE[name] = (diffusers, available)+ return available-_AVAILABLE: dict[tuple[int, str], bool] = {}+_AVAILABLE: dict[str, tuple[Any, bool]] = {}def _init_kwargs(pipe: Any, cls: type, config_overrides: dict[str, Any]) -> dict[str, Any]:diff --git a/studio/backend/tests/test_video_i2v.py b/studio/backend/tests/test_video_i2v.pyindex 6877c820dc6..7b5090a97c1 100644--- a/studio/backend/tests/test_video_i2v.py+++ b/studio/backend/tests/test_video_i2v.py@@ -525,3 +525,33 @@ def test_model_offload_sends_the_vae_back_when_the_first_frame_encode_raises():pipe.vae.encode(torch.zeros(1))assert offloaded == [pipe.vae]assert pipe.vae.__dict__["encode"] is _boom+++def test_availability_follows_the_module_not_a_reused_id(monkeypatch):+ """i2v_pipeline_available cached by id(diffusers). Once a replaced module is collected, its id can+ be handed to the next one, and the next module then inherits the first one's answer: a fake+ diffusers without WanImageToVideoPipeline made a later fake that has it read as unavailable,+ an order-dependent "needs diffusers' WanImageToVideoPipeline" in test_video_backend. Forcing the+ ids to collide reproduces that deterministically."""+ import builtins+ import sys+ import types++ from core.inference import video_i2v as vi++ monkeypatch.setattr(vi, "_AVAILABLE", {})+ # Every module gets the same id, as two short-lived fakes can in a real run.+ monkeypatch.setattr(builtins, "id", lambda obj: 1)+ name = "WanImageToVideoPipeline"++ without = types.ModuleType("diffusers")+ monkeypatch.setitem(sys.modules, "diffusers", without)+ assert vi.i2v_pipeline_available(name) is False++ with_class = types.ModuleType("diffusers")+ setattr(with_class, name, type(name, (), {}))+ monkeypatch.setitem(sys.modules, "diffusers", with_class)+ assert vi.i2v_pipeline_available(name) is True+ # And the answer for the module that is current is still cached, not recomputed each call.+ monkeypatch.delattr(with_class, name)+ assert vi.i2v_pipeline_available(name) is True