Skip to content

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.

Studio tests: make the compiled-wrapper onload test hold its own weakref (follow-up to #17141) (#17189)

Daniel Han2dc697791001
diff --git a/studio/backend/tests/test_diffusion_offload_prefetch.py b/studio/backend/tests/test_diffusion_offload_prefetch.py
index b1c35609bdd..9373107bd2d 100644
--- a/studio/backend/tests/test_diffusion_offload_prefetch.py
+++ b/studio/backend/tests/test_diffusion_offload_prefetch.py
@@ -705,8 +705,12 @@ def test_streamed_onload_of_a_compiled_wrapper_weight_does_not_swap(monkeypatch)
w = lin.weight.detach().clone()
lin.weight = torch.nn.Parameter(two.TwoTensor(w, w.clone()), requires_grad = False)
torch._dynamo.reset()
+ compiled = torch.compile(lin, backend = "eager")
+ x = torch.randn(2, 8)
with torch.no_grad():
- torch.compile(lin, backend = "eager")(torch.randn(2, 8))
+ compiled(x)
+ # compile's own weakref is gone by torch 2.12; hold one so swap_tensors would refuse, as in a render.
+ held = weakref.ref(lin.weight)
assert weakref.getweakrefs(lin.weight)
host = two.TwoTensor(w + 1, w + 2)
monkeypatch.setattr(type(host), "is_pinned", lambda self: True, raising = False)
@@ -725,4 +729,8 @@ def test_streamed_onload_of_a_compiled_wrapper_weight_does_not_swap(monkeypatch)
pf._issue(group)
assert lin.weight is param
assert torch.equal(param.a, w + 1) and torch.equal(param.b, w + 2)
+ assert held() is param
+ with torch.no_grad():
+ got = compiled(x)
+ assert torch.equal(got, torch.nn.functional.linear(x, two.TwoTensor(w + 1, w + 2), lin.bias))
torch._dynamo.reset()