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 diffusion: read the XPU's float64 support from the device (Arc A-series LTX RoPE) (#17070)

Daniel Han93f1913d188f
diff --git a/studio/backend/core/inference/diffusion_device.py b/studio/backend/core/inference/diffusion_device.py
index 884eeeb8ac9..73b4eedf110 100644
--- a/studio/backend/core/inference/diffusion_device.py
+++ b/studio/backend/core/inference/diffusion_device.py
@@ -756,6 +756,11 @@ def diffusion_device_target_from_torch_device(
ordinal = int(index) if index.isdigit() else None,
)
if device == "xpu":
+ try:
+ import torch
+ xpu = getattr(torch, "xpu", None)
+ except Exception:
+ xpu = None
return DiffusionDeviceTarget(
device = "xpu",
dtype = dtype,
@@ -764,6 +769,10 @@ def diffusion_device_target_from_torch_device(
supports_model_cpu_offload = True,
supports_default_torch_compile = False,
supports_pinned_transfer = False,
+ # float64_device() (VAE tiling blend weights) comes through here, not _xpu_target.
+ supports_float64 = _xpu_has_fp64(xpu, int(index) if index.isdigit() else None)
+ if xpu is not None
+ else True,
)
if device == "mps":
return DiffusionDeviceTarget(
@@ -832,6 +841,21 @@ def _cuda_or_rocm_target(
)
+# Arc A-series has no fp64 ("Required aspect fp64"); 0 skips the probe.
+XPU_FP64_PROBE_ENV = "UNSLOTH_DIFFUSION_XPU_FP64_PROBE"
+
+
+def _xpu_has_fp64(xpu: Any, index: Optional[int] = None) -> bool:
+ """True when the probe is off or unanswerable."""
+ if (os.environ.get(XPU_FP64_PROBE_ENV) or "").strip().lower() in ("0", "off", "false", "no"):
+ return True
+ try:
+ idx = xpu.current_device() if index is None else index
+ return bool(getattr(xpu.get_device_properties(idx), "has_fp64", True))
+ except Exception:
+ return True
+
+
def _xpu_target(torch: Any) -> DiffusionDeviceTarget:
bf16_ok = False
xpu = getattr(torch, "xpu", None)
@@ -847,6 +871,7 @@ def _xpu_target(torch: Any) -> DiffusionDeviceTarget:
supports_model_cpu_offload = True,
supports_default_torch_compile = False,
supports_pinned_transfer = False,
+ supports_float64 = _xpu_has_fp64(xpu) if xpu is not None else True,
)
diff --git a/studio/backend/tests/test_diffusion_device.py b/studio/backend/tests/test_diffusion_device.py
index aa3a994c6a4..9b46d802e0d 100644
--- a/studio/backend/tests/test_diffusion_device.py
+++ b/studio/backend/tests/test_diffusion_device.py
@@ -1003,3 +1003,87 @@ def test_mps_cap_failure_keeps_target(monkeypatch):
_install(monkeypatch, _mps_cap_torch([], fraction_raises = True), studio_device = "mlx")
t = dd.resolve_diffusion_device_target()
assert t.device == "mps" and t.dtype == BF16
+
+
+_PROBE_ENV = "UNSLOTH_DIFFUSION_XPU_FP64_PROBE"
+
+
+def _fake_xpu_torch(has_fp64 = None, raises = False):
+ import torch
+
+ def props(index):
+ if raises:
+ raise RuntimeError("no device properties")
+ return (
+ types.SimpleNamespace()
+ if has_fp64 is None
+ else types.SimpleNamespace(has_fp64 = has_fp64)
+ )
+
+ xpu = types.SimpleNamespace(
+ is_bf16_supported = lambda: True,
+ current_device = lambda: 0,
+ get_device_properties = props,
+ )
+ return types.SimpleNamespace(xpu = xpu, bfloat16 = torch.bfloat16, float16 = torch.float16)
+
+
+ "has_fp64, raises, env, want",
+ [
+ (False, False, None, False), # Arc A-series
+ (True, False, None, True),
+ (None, False, None, True),
+ (False, True, None, True),
+ (False, False, "0", True),
+ ],
+)
+def test_xpu_target_reports_the_devices_float64(monkeypatch, has_fp64, raises, env, want):
+ if env is None:
+ monkeypatch.delenv(_PROBE_ENV, raising = False)
+ else:
+ monkeypatch.setenv(_PROBE_ENV, env)
+ target = dd._xpu_target(_fake_xpu_torch(has_fp64, raises))
+ assert target.device == "xpu"
+ assert target.supports_float64 is want
+
+
+def test_fp64_less_xpu_demotes_ltx2_rope_to_float32(monkeypatch):
+ torch = pytest.importorskip("torch")
+ ltx2 = pytest.importorskip("diffusers.models.transformers.transformer_ltx2")
+ monkeypatch.delenv(_PROBE_ENV, raising = False)
+ rope = ltx2.LTX2AudioVideoRotaryPosEmbed(dim = 96, num_attention_heads = 2)
+ assert rope.double_precision
+ pipe = types.SimpleNamespace(components = {"transformer": torch.nn.Sequential(rope)})
+ coords = rope.prepare_video_coords(1, 4, 8, 8, device = "cpu")
+ oracle = rope(coords, device = "cpu")
+ assert dd.force_float32_rope(pipe, dd._xpu_target(_fake_xpu_torch(True))) == 0
+ assert rope.double_precision
+ assert dd.force_float32_rope(pipe, dd._xpu_target(_fake_xpu_torch(False))) == 1
+ assert not rope.double_precision
+ got = rope(coords, device = "cpu")
+ for a, b in zip(got, oracle):
+ assert a.dtype == b.dtype == torch.float32
+ assert 0 < float((a - b).abs().max()) < 1e-2
+ assert dd.float64_device("cpu") == "cpu"
+
+
+def test_float64_device_probes_the_operands_xpu(monkeypatch):
+ """``float64_device`` must probe the operand's own XPU index, not the current card."""
+ import torch
+
+ asked = []
+
+ def props(index):
+ asked.append(index)
+ return types.SimpleNamespace(has_fp64 = index != 1)
+
+ xpu = types.SimpleNamespace(current_device = lambda: 1, get_device_properties = props)
+ monkeypatch.setattr(torch, "xpu", xpu, raising = False)
+ monkeypatch.delenv(_PROBE_ENV, raising = False)
+ assert dd.float64_device("xpu:1") == "cpu"
+ assert dd.float64_device("xpu:0") == "xpu:0"
+ assert dd.float64_device("xpu") == "cpu"
+ assert asked == [1, 0, 1]
+ monkeypatch.setenv(_PROBE_ENV, "0")
+ assert dd.float64_device("xpu:1") == "xpu:1"