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 Images X/Y plot: shrink grid cells off the event loop (#17265)
Daniel Hana28ec1a581b3
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex 02322d2a33b..38f3d217d1a 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -49940,7 +49940,8 @@ async def _generate_xy_grid(request: DiffusionGenerateRequest) -> DiffusionGenerplan.cells[index].request, captured = captured)records[index] = result.images[0]- pictures[index] = diffusion_xy.fit_cell(captured[0], plan)+ # LANCZOS on a large render would block the event loop.+ pictures[index] = await asyncio.to_thread(diffusion_xy.fit_cell, captured[0], plan)# No await between these two: a Stop after the last cell ends the grid, one after this is not acknowledged._xy_grid_stops.remove(stop)if ticket.cancelled():diff --git a/studio/backend/tests/test_diffusion_xy.py b/studio/backend/tests/test_diffusion_xy.pyindex 24bf3ecc52d..e2a003e24e5 100644--- a/studio/backend/tests/test_diffusion_xy.py+++ b/studio/backend/tests/test_diffusion_xy.py@@ -470,3 +470,40 @@ def test_grid_stop_is_keyed_on_the_stable_account_id(monkeypatch):# Scope moves from None to the owner's id once the first managed account exists.monkeypatch.setattr(routes_inference.account_access, "account_scope", lambda: "something-else")assert routes_inference._stop_xy_grids() is True and ticket.cancelled()+++def test_cells_are_shrunk_off_the_event_loop(client, monkeypatch):+ import asyncio++ import core.inference.diffusion as diffusion_module+ from PIL import Image++ client.post(+ "/api/inference/images/load",+ json = {"model_path": "x/z-image", "gguf_filename": "q.gguf"},+ )+ backend = diffusion_module.get_diffusion_backend()+ backend.generate = lambda **kwargs: {+ "images": [Image.new("RGB", (64, 64), "gray")],+ "seed": kwargs["seed"],+ "repo_id": "x/z-image",+ "workflow": "txt2img",+ }+ on_loop = []+ original = diffusion_xy.fit_cell++ def _fit_cell(image, plan):+ try:+ asyncio.get_running_loop()+ on_loop.append(True)+ except RuntimeError:+ on_loop.append(False)+ return original(image, plan)++ monkeypatch.setattr(diffusion_xy, "fit_cell", _fit_cell)+ resp = client.post(+ "/api/inference/images/generate",+ json = {"prompt": "a sloth", "seed": 3, "xy": {"x": {"field": "steps", "values": [2, 4]}}},+ )+ assert resp.status_code == 200, resp.text+ assert on_loop == [False, False]