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 diffusion: read ROCm from the wheel tag in every fast-path gate (#14654)
Daniel Han53719fc150b5
diff --git a/studio/backend/core/inference/diffusion_compile_config.py b/studio/backend/core/inference/diffusion_compile_config.pyindex 60d7a4d7c5b..8765c48579f 100644--- a/studio/backend/core/inference/diffusion_compile_config.py+++ b/studio/backend/core/inference/diffusion_compile_config.py@@ -10,6 +10,7 @@ import osimport threadingfrom contextvars import ContextVarfrom typing import Any+from .rocm_bf16 import is_rocm_torch# dynamic_scale_rblock benchmarks R0_BLOCK vs R0_BLOCK/2 per process (never cached); the two sum in different orders,# so renders differed across servers on one seed (FLUX.1-schnell int8, B200). =1 restores inductor's default, and also@@ -50,7 +51,7 @@ def family_filters_reductions(family: Any) -> bool:def _device_capability() -> Any:try:import torch- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Nonereturn tuple(int(v) for v in torch.cuda.get_device_capability())except Exception: # noqa: BLE001 - no CUDA: nothing pinneddiff --git a/studio/backend/core/inference/diffusion_convrot_quant.py b/studio/backend/core/inference/diffusion_convrot_quant.pyindex f79f459e0ac..b2ccdd1d339 100644--- a/studio/backend/core/inference/diffusion_convrot_quant.py+++ b/studio/backend/core/inference/diffusion_convrot_quant.py@@ -29,6 +29,7 @@ import osimport typesfrom functools import lru_cachefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchINT8_ROTQUANT_ENV = "UNSLOTH_DIFFUSION_INT8_ROTQUANT"_OP_NAMESPACE = "unsloth_studio"@@ -402,7 +403,7 @@ def rotquant_device_config(index: int) -> Optional[tuple]:import torchif (torch.cuda.is_available()- and not getattr(torch.version, "hip", None)+ and not is_rocm_torch(torch)and _triton_ok()and _kernels() is not Noneand _rotq_op() is not Nonediff --git a/studio/backend/core/inference/diffusion_device.py b/studio/backend/core/inference/diffusion_device.pyindex 2cda790b7cb..9bd17d2c9de 100644--- a/studio/backend/core/inference/diffusion_device.py+++ b/studio/backend/core/inference/diffusion_device.py@@ -724,7 +724,10 @@ def resolve_diffusion_device_target(*, ordinal: Optional[int] = None) -> Diffusiexcept Exception:DeviceType = Nonestudio_device = None- is_rocm = bool(getattr(getattr(torch, "version", None), "hip", None))+ from .rocm_bf16 import is_rocm_torch++ # Tag-aware: AMD SDK / Radeon wheels leave torch.version.hip unset.+ is_rocm = is_rocm_torch(torch)if DeviceType is not None and studio_device is not None:if _studio_device_is(studio_device, DeviceType, "CUDA"):diff --git a/studio/backend/core/inference/diffusion_flux2_rope.py b/studio/backend/core/inference/diffusion_flux2_rope.pyindex 7e5a5d6536b..c25280bb90b 100644--- a/studio/backend/core/inference/diffusion_flux2_rope.py+++ b/studio/backend/core/inference/diffusion_flux2_rope.py@@ -15,6 +15,7 @@ import loggingimport osimport threadingfrom typing import Any, Callable, Optional+from .rocm_bf16 import is_rocm_torchFLUX2_FUSED_ROPE_ENV = "UNSLOTH_DIFFUSION_FLUX2_FUSED_ROPE"_MODULE = "diffusers.models.transformers.transformer_flux2"@@ -45,7 +46,7 @@ def wanted(dtype: Any, device: Any = "cuda") -> bool:return Falseif dtype is not torch.float16 or not str(device).startswith("cuda"):return False- if getattr(torch.version, "hip", None):+ if is_rocm_torch(torch):return Falsereturn _kernel() is not Nonediff --git a/studio/backend/core/inference/diffusion_int8_fused.py b/studio/backend/core/inference/diffusion_int8_fused.pyindex 0e95d97389c..ff0a93374aa 100644--- a/studio/backend/core/inference/diffusion_int8_fused.py+++ b/studio/backend/core/inference/diffusion_int8_fused.py@@ -33,6 +33,7 @@ import threadingimport typesfrom functools import lru_cachefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchINT8_FUSED_ENV = "UNSLOTH_DIFFUSION_INT8_FUSED"_MIN_TRITON = (3, 2)@@ -853,7 +854,7 @@ def _device_ok(index: int) -> bool:import torchexcept Exception: # noqa: BLE001return False- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Falseif (not (_triton_version_ok() and _triton_jit_toolchain_ok())@@ -1506,7 +1507,7 @@ def resident_cuda_device(module: Any) -> Any:"""The one CUDA device every parameter of ``module`` lives on (NVIDIA, not ROCm), else None."""try:import torch- if getattr(torch.version, "hip", None):+ if is_rocm_torch(torch):return Nonedevices = {p.device for p in module.parameters()}except Exception: # noqa: BLE001diff --git a/studio/backend/core/inference/diffusion_int8_gemm.py b/studio/backend/core/inference/diffusion_int8_gemm.pyindex 484ce6d2703..28bc98308ef 100644--- a/studio/backend/core/inference/diffusion_int8_gemm.py+++ b/studio/backend/core/inference/diffusion_int8_gemm.py@@ -44,6 +44,7 @@ import threadingimport typesfrom functools import lru_cachefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchINT8_GEMM_ENV = "UNSLOTH_DIFFUSION_INT8_GEMM"INT8_GEMM_CONVROT_ENV = "UNSLOTH_DIFFUSION_INT8_GEMM_CONVROT"@@ -385,7 +386,7 @@ def device_config(index: int) -> Optional[tuple]:import torchif (torch.cuda.is_available()- and not getattr(torch.version, "hip", None)+ and not is_rocm_torch(torch)and _triton_version_ok()and _kernels() is not Noneand _op() is not None@@ -734,7 +735,7 @@ def install(try:import torch- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return 0if not _triton_version_ok() or _kernels() is None:return 0@@ -776,11 +777,7 @@ def _swap(dev = torch.device(device)except Exception: # noqa: BLE001return 0- if (- dev.type != "cuda"- or getattr(torch.version, "hip", None)- or not torch.cuda.is_available()- ):+ if dev.type != "cuda" or is_rocm_torch(torch) or not torch.cuda.is_available():return 0else:dev = resident_cuda_device(transformer)@@ -803,7 +800,7 @@ def _split_cards(transformer: Any) -> tuple:from .diffusion_layer_split import is_layer_split- if getattr(torch.version, "hip", None) or not is_layer_split(transformer):+ if is_rocm_torch(torch) or not is_layer_split(transformer):return ()devices = {p.device for p in transformer.parameters()}except Exception: # noqa: BLE001diff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.pyindex 033043575fe..901c9f7dd0e 100644--- a/studio/backend/core/inference/diffusion_memory.py+++ b/studio/backend/core/inference/diffusion_memory.py@@ -23,6 +23,7 @@ import osimport sysfrom dataclasses import dataclass, field, replacefrom typing import Any, Callable, Optional+from .rocm_bf16 import is_rocm_torchMEMORY_MODE_AUTO = "auto"@@ -937,10 +938,7 @@ def _torch_is_rocm(torch) -> bool:from core.inference.llama_cpp import LlamaCppBackendreturn LlamaCppBackend._torch_is_rocm(torch)except Exception: # noqa: BLE001 - the answer still has to be right- return (- getattr(getattr(torch, "version", None), "hip", None) is not None- or "rocm" in getattr(torch, "__version__", "").lower()- )+ return is_rocm_torch(torch)def _unified_reclaimable_memory_mib(free_mib: int, total_mib: int) -> tuple[int, int]:@@ -4541,7 +4539,7 @@ def _fast_pin_supported() -> bool:try:import torch- if getattr(torch.version, "hip", None) or not torch.cuda.is_available():+ if is_rocm_torch(torch) or not torch.cuda.is_available():return Falsecudart = torch.cuda.cudart()return hasattr(cudart, "cudaHostRegister") and hasattr(cudart, "cudaHostUnregister")diff --git a/studio/backend/core/inference/diffusion_nvfp4_install.py b/studio/backend/core/inference/diffusion_nvfp4_install.pyindex f6664e881a9..1cb66f531f7 100644--- a/studio/backend/core/inference/diffusion_nvfp4_install.py+++ b/studio/backend/core/inference/diffusion_nvfp4_install.py@@ -20,6 +20,7 @@ import sysimport tempfileimport threadingfrom typing import Any, Callable, Optional+from .rocm_bf16 import is_rocm_torch# auto (default) / 1 installs flashinfer when an NVFP4 load needs it; 0 never installs.FLASHINFER_INSTALL_ENV = "UNSLOTH_NVFP4_FLASHINFER_INSTALL"@@ -268,7 +269,7 @@ def _host_refusal(device: Any) -> Optional[str]:import torchexcept Exception as exc: # noqa: BLE001return f"torch is not importable ({type(exc).__name__})"- if getattr(torch.version, "hip", None):+ if is_rocm_torch(torch):return "flashinfer NVFP4 kernels are CUDA only (this torch is a ROCm build)"if not getattr(torch.version, "cuda", None):return "flashinfer NVFP4 kernels need a CUDA build of torch"diff --git a/studio/backend/core/inference/diffusion_qwenimage21_fused.py b/studio/backend/core/inference/diffusion_qwenimage21_fused.pyindex 39d9035aaf0..059fff86a7d 100644--- a/studio/backend/core/inference/diffusion_qwenimage21_fused.py+++ b/studio/backend/core/inference/diffusion_qwenimage21_fused.py@@ -15,6 +15,7 @@ import osimport threadingimport typesfrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchQ21_CONVROT_FUSED_ENV = "UNSLOTH_DIFFUSION_Q21_CONVROT_FUSED"_PREPARE = "_qwenimage21_prepare_qkv"@@ -40,7 +41,7 @@ def arch_ok(device: Any = None) -> bool:try:import torch- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Falsedev = torch.device(device) if device is not None else Noneif dev is None or dev.type != "cuda":diff --git a/studio/backend/core/inference/diffusion_qwenimage21_rocm.py b/studio/backend/core/inference/diffusion_qwenimage21_rocm.pyindex 9a5f73b936d..78d8b780957 100644--- a/studio/backend/core/inference/diffusion_qwenimage21_rocm.py+++ b/studio/backend/core/inference/diffusion_qwenimage21_rocm.py@@ -11,6 +11,7 @@ from __future__ import annotationsimport functoolsimport osfrom typing import Any+from .rocm_bf16 import is_rocm_torchQUERY_CHUNK_ENV = "UNSLOTH_QWEN_IMAGE_ROCM_QUERY_CHUNKING"QUERY_CHUNK_SIZE = 512@@ -27,7 +28,7 @@ def _device_supported(target: Any) -> bool:return Falseimport torch- if not getattr(torch.version, "hip", None):+ if not is_rocm_torch(torch):return Falseif setting in ("1", "true", "on", "yes"):return Truediff --git a/studio/backend/core/inference/diffusion_qwenimage21_rope.py b/studio/backend/core/inference/diffusion_qwenimage21_rope.pyindex 4089b786062..caf813c3a92 100644--- a/studio/backend/core/inference/diffusion_qwenimage21_rope.py+++ b/studio/backend/core/inference/diffusion_qwenimage21_rope.py@@ -17,6 +17,7 @@ import threadingfrom typing import Any, Optionalfrom .diffusion_autoopt.patches import source_digest+from .rocm_bf16 import is_rocm_torchREAL_ROPE_ENV = "UNSLOTH_DIFFUSION_Q21_REAL_ROPE"@@ -58,7 +59,7 @@ def _addcmul_lowering() -> tuple:import torchfrom torch._inductor import lowering- if getattr(torch.version, "hip", None):+ if is_rocm_torch(torch):return False, Falsesrc = inspect.getsource(lowering.addcmul)return (diff --git a/studio/backend/core/inference/diffusion_render_thread.py b/studio/backend/core/inference/diffusion_render_thread.pyindex 1f0f3e736c2..77d69355587 100644--- a/studio/backend/core/inference/diffusion_render_thread.py+++ b/studio/backend/core/inference/diffusion_render_thread.py@@ -10,6 +10,7 @@ import osimport threadingfrom concurrent.futures import ThreadPoolExecutorfrom typing import Any, Callable+from .rocm_bf16 import is_rocm_torch_ENV = "UNSLOTH_DIFFUSION_RENDER_THREAD"_EXECUTORS: dict[str, ThreadPoolExecutor] = {}@@ -22,7 +23,7 @@ def enabled() -> bool:return Falsetry:import torch # noqa: PLC0415- return bool(torch.cuda.is_available()) and getattr(torch.version, "hip", None) is None+ return bool(torch.cuda.is_available()) and not is_rocm_torch(torch)except Exception: # noqa: BLE001return Falsediff --git a/studio/backend/core/inference/diffusion_rocm_fused.py b/studio/backend/core/inference/diffusion_rocm_fused.pyindex 8029575547b..26cd37b0971 100644--- a/studio/backend/core/inference/diffusion_rocm_fused.py+++ b/studio/backend/core/inference/diffusion_rocm_fused.py@@ -18,6 +18,7 @@ import osimport sysimport threadingfrom typing import Any, Callable, Optional+from .rocm_bf16 import is_rocm_torchFUSED_ROPE_ENV = "UNSLOTH_DIFFUSION_FUSED_ROPE"FUSED_ADALN_ENV = "UNSLOTH_DIFFUSION_FUSED_ADALN"@@ -68,7 +69,7 @@ def _is_rocm() -> bool:import torchexcept Exception: # noqa: BLE001return False- return bool(getattr(torch.version, "hip", None))+ return is_rocm_torch(torch)def _is_nvidia_linux() -> bool:@@ -79,9 +80,7 @@ def _is_nvidia_linux() -> bool:import torchexcept Exception: # noqa: BLE001return False- return getattr(torch.version, "hip", None) is None and bool(- getattr(torch.version, "cuda", None)- )+ return not is_rocm_torch(torch) and bool(getattr(torch.version, "cuda", None))# gfx1151 klein 1024^2: RoPE 8.76 -> 8.09 s pixel-identical; AdaLN adds no speed and moves pixels (LPIPS 0.004).diff --git a/studio/backend/core/inference/diffusion_small_host.py b/studio/backend/core/inference/diffusion_small_host.pyindex 0349d748f8c..fd6ef518665 100644--- a/studio/backend/core/inference/diffusion_small_host.py+++ b/studio/backend/core/inference/diffusion_small_host.py@@ -15,6 +15,7 @@ import osfrom dataclasses import dataclass, fieldfrom pathlib import Pathfrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchSMALL_HOST_ENV = "UNSLOTH_DIFFUSION_SMALL_HOST"HOST_RAM_CHECK_ENV = "UNSLOTH_DIFFUSION_HOST_RAM_CHECK"@@ -310,7 +311,7 @@ def int8_act_device_ok(device: Any) -> bool:try:dev = torch.device(device)- if dev.type != "cuda" or getattr(torch.version, "hip", None):+ if dev.type != "cuda" or is_rocm_torch(torch):return Falseidx = dev.index if dev.index is not None else torch.cuda.current_device()except Exception: # noqa: BLE001diff --git a/studio/backend/core/inference/diffusion_vae_attn_chunked.py b/studio/backend/core/inference/diffusion_vae_attn_chunked.pyindex 36ba2de0500..47e3aacdb3c 100644--- a/studio/backend/core/inference/diffusion_vae_attn_chunked.py+++ b/studio/backend/core/inference/diffusion_vae_attn_chunked.py@@ -12,6 +12,7 @@ from __future__ import annotationsimport osfrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchVAE_ATTN_CHUNK_ENV = "UNSLOTH_VAE_ATTN_CHUNKED"VAE_ATTN_CHUNK_MB_ENV = "UNSLOTH_VAE_ATTN_CHUNK_MB"@@ -189,7 +190,7 @@ def wants_install(vae: Any, target: Any = None) -> bool:import torchexcept Exception: # noqa: BLE001return False- return bool(getattr(torch.version, "hip", None))+ return is_rocm_torch(torch)def patch_attention_modules(vae: Any) -> int:diff --git a/studio/backend/core/inference/diffusion_vae_fused.py b/studio/backend/core/inference/diffusion_vae_fused.pyindex 25aa99df815..26a1cb6dda5 100644--- a/studio/backend/core/inference/diffusion_vae_fused.py+++ b/studio/backend/core/inference/diffusion_vae_fused.py@@ -17,6 +17,8 @@ import typesfrom functools import lru_cachefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torch+VAE_FUSED_ENV = "UNSLOTH_VAE_FUSED"_FALSE = ("0", "false", "no", "off")_MIN_TRITON = (3, 3)@@ -454,7 +456,7 @@ def runtime_ok() -> bool:import torchexcept Exception: # noqa: BLE001return False- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Falsereturn _triton_version_ok() and _toolchain_ok() and _kernels() is not Nonediff --git a/studio/backend/core/inference/diffusion_vae_prebuild.py b/studio/backend/core/inference/diffusion_vae_prebuild.pyindex c8b0d5a4735..7bb2c93c104 100644--- a/studio/backend/core/inference/diffusion_vae_prebuild.py+++ b/studio/backend/core/inference/diffusion_vae_prebuild.py@@ -15,6 +15,7 @@ from __future__ import annotationsimport osimport threadingfrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torch_ENV = "UNSLOTH_DIFFUSION_VAE_PREBUILD"_FALSE = ("0", "false", "no", "off")@@ -89,7 +90,7 @@ def maybe_kick(try:import torch- if getattr(torch.version, "hip", None) or not torch.cuda.is_available():+ if is_rocm_torch(torch) or not torch.cuda.is_available():return Falseif compile_ctx is None or getattr(compile_ctx, "hit", False):return False # a restart's Triton cache already holds the kernelsdiff --git a/studio/backend/core/inference/diffusion_vae_tiling.py b/studio/backend/core/inference/diffusion_vae_tiling.pyindex 7a60d808faa..ff34e53564a 100644--- a/studio/backend/core/inference/diffusion_vae_tiling.py+++ b/studio/backend/core/inference/diffusion_vae_tiling.py@@ -21,6 +21,7 @@ from typing import Any, Optionalfrom .diffusion_device import float64_devicefrom .diffusion_vae_oom import clear_partial_decodefrom .diffusion_vae_oom import free_first as oom_free_first+from .rocm_bf16 import is_rocm_torchWIDE_TILES_ENV = "UNSLOTH_DIFFUSION_VAE_WIDE_TILES"@@ -287,7 +288,7 @@ def decode_tile_budget(vae: Any, z: Any) -> Optional[int]:if (z.device.type == "cuda"- and getattr(torch.version, "hip", None)+ and is_rocm_torch(torch)and type(vae).__name__ == "AutoencoderKLQwenImage21"):return TILE_LATENTS**2diff --git a/studio/backend/core/inference/video_minimax_h3_attn.py b/studio/backend/core/inference/video_minimax_h3_attn.pyindex 9f6d579143b..f90956a0eba 100644--- a/studio/backend/core/inference/video_minimax_h3_attn.py+++ b/studio/backend/core/inference/video_minimax_h3_attn.py@@ -15,6 +15,7 @@ from __future__ import annotationsimport osfrom functools import lru_cachefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchSTRIDED_ATTN_ENV = "UNSLOTH_H3_STRIDED_ATTN"FUSED_QKV_ENV = "UNSLOTH_H3_FUSED_QKV"@@ -34,7 +35,7 @@ def _enabled(env: str) -> bool:def _capability(device: Any = None) -> Optional[tuple[int, int]]:try:import torch- if not torch.cuda.is_available() or torch.version.hip is not None:+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Nonereturn tuple(torch.cuda.get_device_capability(device)) # type: ignore[return-value]except Exception: # noqa: BLE001diff --git a/studio/backend/core/inference/video_minimax_h3_qknorm.py b/studio/backend/core/inference/video_minimax_h3_qknorm.pyindex f3207dc087d..e4af37f987a 100644--- a/studio/backend/core/inference/video_minimax_h3_qknorm.py+++ b/studio/backend/core/inference/video_minimax_h3_qknorm.py@@ -13,6 +13,7 @@ from __future__ import annotationsimport osfrom functools import lru_cachefrom typing import Any+from .rocm_bf16 import is_rocm_torchQK_ROPE_ENV = "UNSLOTH_H3_QK_ROPE"_OP = "unsloth_h3::qk_norm_rope"@@ -109,7 +110,7 @@ def _kernel() -> Any:def _triton_ok(x: Any) -> bool:try:import torch- if not (x.is_cuda and torch.version.hip is None):+ if not (x.is_cuda and not is_rocm_torch(torch)):return Falseimport triton # noqa: F401except Exception: # noqa: BLE001diff --git a/studio/backend/core/inference/video_minimax_h3_vae.py b/studio/backend/core/inference/video_minimax_h3_vae.pyindex 3f71a561250..de2e7e0aadd 100644--- a/studio/backend/core/inference/video_minimax_h3_vae.py+++ b/studio/backend/core/inference/video_minimax_h3_vae.py@@ -16,6 +16,7 @@ import typesfrom contextlib import nullcontextfrom functools import lru_cachefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchH3_VAE_FAST_ENV = "UNSLOTH_H3_VAE_FAST"H3_VAE_INT8_ENV = "UNSLOTH_H3_VAE_INT8"@@ -1248,7 +1249,7 @@ def cuda_fast_path_available(vae: Any = None) -> bool:import torchexcept Exception: # noqa: BLE001return False- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Falseif vae is not None:try:diff --git a/studio/backend/core/inference/video_nvenc.py b/studio/backend/core/inference/video_nvenc.pyindex 370fd6586d2..cf9ca41e688 100644--- a/studio/backend/core/inference/video_nvenc.py+++ b/studio/backend/core/inference/video_nvenc.py@@ -12,6 +12,7 @@ import reimport threadingimport timefrom typing import Any, Optional+from .rocm_bf16 import is_rocm_torchENCODER_ENV = "UNSLOTH_STUDIO_VIDEO_ENCODER"CODEC = "h264_nvenc"@@ -99,7 +100,7 @@ def nvenc_gpu(device: Any = None, logger: Any = None) -> Optional[int]:try:import torch- if not torch.cuda.is_available() or getattr(torch.version, "hip", None):+ if not torch.cuda.is_available() or is_rocm_torch(torch):return Noneindex = torch.device(device).index if device is not None else Noneif index is None:diff --git a/studio/backend/core/inference/video_wan_fused.py b/studio/backend/core/inference/video_wan_fused.pyindex 212b50c4e20..39d3711f405 100644--- a/studio/backend/core/inference/video_wan_fused.py+++ b/studio/backend/core/inference/video_wan_fused.py@@ -17,6 +17,7 @@ import functoolsimport osimport threadingfrom typing import Any, Callable, Optional+from .rocm_bf16 import is_rocm_torchWAN_FUSED_ENV = "UNSLOTH_DIFFUSION_WAN_FUSED_ADALN"# rotary only (the block fusion stays): UNSLOTH_DIFFUSION_WAN_FUSED_ROPE=0@@ -53,7 +54,7 @@ def wanted(dtype: Any, device: Any = "cuda") -> bool:return Falseif dtype is not torch.float16 or not str(device).startswith("cuda"):return False- if getattr(getattr(torch, "version", None), "hip", None):+ if is_rocm_torch(torch):return Falsereturn _kernels() is not Nonediff --git a/studio/backend/tests/test_diffusion_flux2_rope.py b/studio/backend/tests/test_diffusion_flux2_rope.pyindex 6bb7a7ffe52..ba47986862d 100644--- a/studio/backend/tests/test_diffusion_flux2_rope.py+++ b/studio/backend/tests/test_diffusion_flux2_rope.py@@ -14,9 +14,15 @@ import pytestfrom core.inference import diffusion_flux2_rope as frtorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402+fmod = pytest.importorskip("diffusers.models.transformers.transformer_flux2")from diffusers.models.embeddings import apply_rotary_emb as stock_rope # noqa: E402+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+needs_cuda = pytest.mark.skipif(not torch.cuda.is_available()or bool(getattr(torch.version, "hip", None))@@ -46,6 +52,7 @@ def fake_kernel(monkeypatch):"""Gate tests run without a GPU: pretend Triton built the kernel on a CUDA (non-ROCm) torch."""monkeypatch.setattr(fr, "_kernel", lambda: (lambda x, cos, sin: None))monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)def test_stock_symbol_is_the_one_flux2_calls():@@ -255,6 +262,7 @@ def test_a_failed_launch_disables_the_fused_path_for_the_load(monkeypatch):monkeypatch.setattr(fr, "_kernel", lambda: failing_launch)monkeypatch.setattr(fr, "_eligible", lambda *a, **k: True)monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)assert fr.install_for_pipe(_Flux2Like(), torch.float16, "cuda")x = torch.randn(1, 6, 2, 8)pos = torch.randn(6, 4, dtype = torch.float64)diff --git a/studio/backend/tests/test_diffusion_reduction_filter_arch.py b/studio/backend/tests/test_diffusion_reduction_filter_arch.pyindex 4c3004e6bdf..ce28023eb67 100644--- a/studio/backend/tests/test_diffusion_reduction_filter_arch.py+++ b/studio/backend/tests/test_diffusion_reduction_filter_arch.py@@ -16,10 +16,16 @@ import typesimport pytesttorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402+from core.inference import diffusion_compile_config as cc # noqa: E402from core.inference import diffusion_speed as ds # noqa: E402+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+_SM120 = (12, 0)_MEASURED_ARCHS = ((8, 0), (8, 9), (12, 0))_IMAGE_FAMILIES = ("flux.1", "z-image", "qwen-image", "flux.1-kontext", "qwen-image-edit")@@ -125,6 +131,7 @@ def test_no_family_or_plain_object(monkeypatch):def test_capability_query_never_raises(monkeypatch):monkeypatch.setattr(torch.cuda, "is_available", lambda: True)monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)def boom(*a, **k):raise RuntimeError("no device")diff --git a/studio/backend/tests/test_diffusion_rocm_fused.py b/studio/backend/tests/test_diffusion_rocm_fused.pyindex 0e50cd8dc3c..76dc8e4971d 100644--- a/studio/backend/tests/test_diffusion_rocm_fused.py+++ b/studio/backend/tests/test_diffusion_rocm_fused.py@@ -13,6 +13,8 @@ from pathlib import Pathimport pytesttorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402+from core.inference import diffusion_eager_patches as ep # noqa: E402from core.inference import diffusion_rocm_fused as rf # noqa: E402@@ -21,6 +23,10 @@ fmod = pytest.importorskip("diffusers.models.transformers.transformer_flux")from diffusers.models import normalization as nm # noqa: E402from diffusers.models.embeddings import apply_rotary_emb as stock_rope # noqa: E402+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+# another test file may leave Studio's eager AdaLN patch on the classes: start from stockep.uninstall_patches()_STOCK_FWD = {name: getattr(nm, name).forward for name in rf._ADALN_CLASSES}@@ -57,6 +63,7 @@ def fake_kernels(monkeypatch):def _nvidia(monkeypatch, platform = "linux"):monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setattr(torch.version, "cuda", "13.0", raising = False)monkeypatch.setattr(rf.sys, "platform", platform)@@ -79,6 +86,7 @@ def test_auto_is_inert_on_nvidia_outside_linux(fake_kernels, monkeypatch, platfodef test_auto_is_inert_without_a_gpu_torch(fake_kernels, monkeypatch):monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setattr(torch.version, "cuda", None, raising = False)monkeypatch.setattr(rf.sys, "platform", "linux")assert rf.install_for_pipe(_PipeLike(), torch.bfloat16, "cuda") == {"rope": False, "adaln": 0}@@ -135,6 +143,7 @@ def test_kill_switches_on_rocm(fake_kernels, monkeypatch, value):def test_force_on_engages_on_cuda(fake_kernels, monkeypatch):monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setenv(rf.FUSED_ROPE_ENV, "1")monkeypatch.setenv(rf.FUSED_ADALN_ENV, "1")assert rf.install_for_pipe(_PipeLike(), torch.float16, "cuda") == {"rope": True, "adaln": 3}diff --git a/studio/backend/tests/test_diffusion_rocm_tag_detect.py b/studio/backend/tests/test_diffusion_rocm_tag_detect.pynew file mode 100644index 00000000000..0139434b012--- /dev/null+++ b/studio/backend/tests/test_diffusion_rocm_tag_detect.py@@ -0,0 +1,176 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""AMD SDK / Radeon torch wheels leave ``torch.version.hip`` unset and carry the ROCm tag only in ``__version__``.++Studio's device target already reads them as ROCm (``rocm_bf16.is_rocm_torch``), but the diffusion and video fast-path+gates read ``torch.version.hip`` directly, so on such a wheel the ROCm-only paths (fused FLUX RoPE, VAE attention+chunking, Qwen-Image-2.1 query chunks) declined and the NVIDIA-only ones (render thread, NVENC, NVFP4, int8 GEMM)+treated the AMD card as NVIDIA. Every gate now goes through the one tag-aware helper.+"""++from __future__ import annotations++import ast+import sys+from pathlib import Path+from types import SimpleNamespace++import pytest++_BACKEND = Path(__file__).resolve().parents[1]+if str(_BACKEND) not in sys.path:+ sys.path.insert(0, str(_BACKEND))++torch = pytest.importorskip("torch")++INFERENCE = _BACKEND / "core" / "inference"+# Mentions that are not gates: a cache key / label recording the build, and comments or docstrings.+_ALLOWED = {+ "diffusion_probe_cache.py", # records str(torch.version.hip) in a cache key+ "diffusion_measured_peaks.py", # labels the toolkit version+}+++def amd_sdk_wheel(monkeypatch):+ """torch as an AMD SDK wheel reports itself: no version.hip, no version.cuda, the tag in __version__."""+ monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch.version, "cuda", None, raising = False)+ monkeypatch.setattr(torch, "__version__", "2.11.0+rocm7.13.0", raising = False)+ monkeypatch.setattr(torch.cuda, "is_available", lambda: True)+ monkeypatch.setattr(sys, "platform", "linux")+ for env in (+ "UNSLOTH_DIFFUSION_FUSED_ROPE",+ "UNSLOTH_DIFFUSION_RENDER_THREAD",+ "UNSLOTH_DIFFUSION_VAE_ATTN_CHUNK",+ ):+ monkeypatch.delenv(env, raising = False)+ return torch+++def test_fused_flux_rope_switch_is_on_for_a_tag_only_rocm_wheel(amd_sdk_wheel):+ from core.inference import diffusion_rocm_fused as rf++ assert rf._is_rocm() is True+ assert rf._is_nvidia_linux() is False+ assert rf._switch_on(rf.FUSED_ROPE_ENV) is True+++def test_render_thread_stays_off_on_a_tag_only_rocm_wheel(amd_sdk_wheel):+ from core.inference import diffusion_render_thread as rt+ assert rt.enabled() is False+++def test_vae_attention_chunking_installs_on_a_tag_only_rocm_wheel(amd_sdk_wheel):+ from core.inference import diffusion_vae_attn_chunked as vc+ vae = SimpleNamespace(modules = lambda: iter(()))+ assert vc.wants_install(vae, SimpleNamespace(backend = "rocm")) is True+++def test_nvidia_only_paths_decline_on_a_tag_only_rocm_wheel(amd_sdk_wheel, monkeypatch):+ from core.inference import (+ diffusion_compile_config,+ diffusion_flux2_rope,+ diffusion_nvfp4_install,+ diffusion_render_thread,+ video_nvenc,+ )++ monkeypatch.setenv(video_nvenc.ENCODER_ENV, "nvenc")+ assert video_nvenc.nvenc_gpu() is None+ assert diffusion_compile_config._device_capability() is None+ assert diffusion_flux2_rope.wanted(torch.float16, "cuda") is False+ reason = diffusion_nvfp4_install._host_refusal("cuda")+ assert reason is not None and "ROCm" in reason+ assert diffusion_render_thread.enabled() is False+++def test_cuda_build_keeps_the_nvidia_answers(monkeypatch):+ """The helper must not read a CUDA build as ROCm: same gates, NVIDIA identity."""+ from core.inference import diffusion_render_thread as rt+ from core.inference import diffusion_rocm_fused as rf++ monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch.version, "cuda", "13.0", raising = False)+ monkeypatch.setattr(torch, "__version__", "2.13.0+cu130", raising = False)+ monkeypatch.setattr(torch.cuda, "is_available", lambda: True)+ monkeypatch.setattr(sys, "platform", "linux")+ monkeypatch.delenv("UNSLOTH_DIFFUSION_RENDER_THREAD", raising = False)+ assert rf._is_rocm() is False+ assert rf._is_nvidia_linux() is True+ assert rt.enabled() is True+++def _is_version_lookup(node: ast.AST) -> bool:+ """``torch.version`` or ``getattr(torch, "version", ...)``."""+ if isinstance(node, ast.Attribute):+ return node.attr == "version"+ return (+ isinstance(node, ast.Call)+ and isinstance(node.func, ast.Name)+ and node.func.id == "getattr"+ and len(node.args) >= 2+ and isinstance(node.args[1], ast.Constant)+ and node.args[1].value == "version"+ )+++def _raw_hip_reads(path: Path) -> list[int]:+ """Lines of ``torch.version.hip`` / ``getattr(torch.version, "hip", ...)`` reads in code (not comments)."""+ tree = ast.parse(path.read_text(encoding = "utf-8"))+ # Inside an f-string the read labels a cache key with the build string; it gates nothing.+ labels = {id(n) for js in ast.walk(tree) if isinstance(js, ast.JoinedStr) for n in ast.walk(js)}+ lines = []+ for node in ast.walk(tree):+ if id(node) in labels:+ continue+ if isinstance(node, ast.Attribute) and node.attr == "hip":+ base = node.value+ if isinstance(base, ast.Attribute) and base.attr == "version":+ lines.append(node.lineno)+ elif (+ isinstance(node, ast.Call)+ and isinstance(node.func, ast.Name)+ and node.func.id == "getattr"+ and len(node.args) >= 2+ and isinstance(node.args[1], ast.Constant)+ and node.args[1].value == "hip"+ and _is_version_lookup(node.args[0])+ ):+ lines.append(node.lineno)+ return sorted(set(lines))+++def test_no_diffusion_or_video_gate_reads_version_hip_directly():+ offenders = {}+ for path in sorted(INFERENCE.glob("*.py")):+ if not path.name.startswith(("diffusion", "video")) or path.name in _ALLOWED:+ continue+ lines = _raw_hip_reads(path)+ if lines:+ offenders[path.name] = lines+ assert offenders == {}, (+ "use core.inference.rocm_bf16.is_rocm_torch(torch): AMD SDK / Radeon wheels leave torch.version.hip "+ f"unset. Raw reads: {offenders}"+ )+++def test_the_detector_sees_every_spelling_of_a_hip_read(tmp_path):+ src = tmp_path / "gates.py"+ src.write_text(+ "def a(torch):\n return torch.version.hip\n"+ "def b(torch):\n return getattr(torch.version, 'hip', None)\n"+ "def c(torch):\n return getattr(getattr(torch, 'version', None), 'hip', None)\n"+ "def d(torch):\n return f\"hip{getattr(torch.version, 'hip', None)}\"\n",+ encoding = "utf-8",+ )+ assert _raw_hip_reads(src) == [2, 4, 6]+++def test_fp16_wan_fused_kernels_decline_on_a_tag_only_rocm_wheel(amd_sdk_wheel, monkeypatch):+ from core.inference import video_wan_fused++ monkeypatch.setattr(video_wan_fused, "_kernels", lambda: {"stub": True})+ monkeypatch.setattr(video_wan_fused, "disabled", lambda: False)+ assert video_wan_fused.wanted(torch.float16, "cuda") is Falsediff --git a/studio/backend/tests/test_diffusion_small_host_int8_act.py b/studio/backend/tests/test_diffusion_small_host_int8_act.pyindex 18848aacd60..5fa068718c1 100644--- a/studio/backend/tests/test_diffusion_small_host_int8_act.py+++ b/studio/backend/tests/test_diffusion_small_host_int8_act.py@@ -9,9 +9,15 @@ import typesimport pytestimport torch+from torch.torch_version import TorchVersion # noqa: E402+import core.inference.diffusion_small_host as sh+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+@pytest.fixture(autouse = True)def _clean(monkeypatch):@@ -71,6 +77,8 @@ def _fake_cuda(monkeypatch.setattr(torch.cuda, "get_device_capability", lambda idx = None: cap)monkeypatch.setattr(torch.cuda, "current_device", lambda: 0)monkeypatch.setattr(torch.version, "hip", hip, raising = False)+ if hip is None:+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setattr(torch, "_int_mm", int_mm, raising = False)real_to = torch.Tensor.todiff --git a/studio/backend/tests/test_diffusion_vae_attn_chunked.py b/studio/backend/tests/test_diffusion_vae_attn_chunked.pyindex b2abb8368eb..e99c4b9bb53 100644--- a/studio/backend/tests/test_diffusion_vae_attn_chunked.py+++ b/studio/backend/tests/test_diffusion_vae_attn_chunked.py@@ -8,12 +8,18 @@ import typesimport pytesttorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402+F = torch.nn.functionalattention = pytest.importorskip("torch.nn.attention")from torch.utils._python_dispatch import TorchDispatchMode # noqa: E402from core.inference import diffusion_vae_attn_chunked as C # noqa: E402+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+def _math():return attention.sdpa_kernel(attention.SDPBackend.MATH)@@ -194,6 +200,7 @@ def test_install_gates(monkeypatch, rocm):assert C.install(vae, rocm) == 0monkeypatch.delenv(C.VAE_ATTN_CHUNK_ENV)monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)assert C.install(vae, rocm) == 0assert not any(getattr(m, C._PATCHED, False) for m in vae.modules())assert C.install(None, rocm) == 0diff --git a/studio/backend/tests/test_diffusion_vae_prebuild.py b/studio/backend/tests/test_diffusion_vae_prebuild.pyindex 12c9263d876..684014165a1 100644--- a/studio/backend/tests/test_diffusion_vae_prebuild.py+++ b/studio/backend/tests/test_diffusion_vae_prebuild.py@@ -15,9 +15,15 @@ from pathlib import Pathimport pytesttorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402+from core.inference import diffusion_vae_prebuild as prebuild # noqa: E402+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+BACKEND = Path(__file__).resolve().parents[1]@@ -75,6 +81,8 @@ def test_restart_and_kill_switch_never_spawn(monkeypatch):monkeypatch.setattr(prebuild, "_spawn", lambda job, logger: spawned.append(job) or True)monkeypatch.setattr(prebuild, "plan", lambda pipe: {"device": 0})monkeypatch.setattr(torch.cuda, "is_available", lambda: True)+ monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setattr(torch.cuda, "mem_get_info", lambda device: (64 * 1024**3, 96 * 1024**3))pipe = types.SimpleNamespace()assert prebuild.maybe_kick(pipe, types.SimpleNamespace(hit = True)) is Falsediff --git a/studio/backend/tests/test_qwen21_rocm_vae_budget.py b/studio/backend/tests/test_qwen21_rocm_vae_budget.pyindex 16ec6c84476..d3e61b85914 100644--- a/studio/backend/tests/test_qwen21_rocm_vae_budget.py+++ b/studio/backend/tests/test_qwen21_rocm_vae_budget.py@@ -8,6 +8,11 @@ import pytestfrom core.inference import diffusion_vae_tiling as vttorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402++# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")@pytest.fixture@@ -35,6 +40,7 @@ def test_other_decoders_retain_their_adaptive_budget(monkeypatch, decoder, othervae, z = decoderif other_path == "cuda":monkeypatch.setattr(torch.version, "hip", None)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)elif other_path == "cpu":z.device.type = "cpu"else:diff --git a/studio/backend/tests/test_video_minimax_h3_vae.py b/studio/backend/tests/test_video_minimax_h3_vae.pyindex 4616df099cd..68ba0e9eb7e 100644--- a/studio/backend/tests/test_video_minimax_h3_vae.py+++ b/studio/backend/tests/test_video_minimax_h3_vae.py@@ -10,9 +10,15 @@ import typesimport pytestimport torch+from torch.torch_version import TorchVersion # noqa: E402+from core.inference import video_minimax_h3_vae as H+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+CUDA = torch.cuda.is_available() and not getattr(torch.version, "hip", None)needs_cuda = pytest.mark.skipif(not CUDA or H._kernels() is None or not H._triton_version_ok(),@@ -717,8 +723,8 @@ def test_the_fast_path_is_for_the_h3_vae_class_only(monkeypatch):class AutoencoderKLMiniMaxH3:pass- if getattr(torch.version, "hip", None):- pytest.skip("ROCm build")+ monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)assert not H.cuda_fast_path_available(AutoencoderKLWan())assert H.cuda_fast_path_available(AutoencoderKLMiniMaxH3())@@ -741,6 +747,7 @@ def test_the_fast_path_asks_the_windows_triton_toolchain(monkeypatch, platform,monkeypatch.setattr(torch.cuda, "is_available", lambda: True)monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setattr(H, "_kernels", lambda: object())monkeypatch.setattr(H, "_triton_version_ok", lambda: True)monkeypatch.setattr(H.sys, "platform", platform)@@ -1079,6 +1086,7 @@ def test_the_fast_path_needs_a_verified_triton(monkeypatch, version, ok):assert H._triton_version_ok(version) is okmonkeypatch.setattr(torch.cuda, "is_available", lambda: True)monkeypatch.setattr(torch.version, "hip", None, raising = False)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)monkeypatch.setattr(H, "_kernels", lambda: object())monkeypatch.setattr(H, "_triton_jit_toolchain_ok", lambda: True)monkeypatch.setattr(H, "_triton_version_ok", lambda: ok)diff --git a/studio/backend/tests/test_video_nvenc.py b/studio/backend/tests/test_video_nvenc.pyindex f789960b12a..8bdefa08de8 100644--- a/studio/backend/tests/test_video_nvenc.py+++ b/studio/backend/tests/test_video_nvenc.py@@ -9,9 +9,15 @@ import numpy as npimport pytesttorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402+from core.inference import video_nvenc as vn # noqa: E402+# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+@pytest.fixture(autouse = True)def _fresh(monkeypatch):@@ -28,6 +34,8 @@ def _fake_cuda(monkeypatch.setattr(torch.cuda, "current_device", lambda: 0)monkeypatch.setattr(torch.cuda, "get_device_name", lambda index = None: name)monkeypatch.setattr(torch.version, "hip", hip, raising = False)+ if hip is None:+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)probes: list = []def _probe(gpu):diff --git a/studio/backend/tests/test_video_wan_fused.py b/studio/backend/tests/test_video_wan_fused.pyindex a718ba42d5c..93c6f0a9225 100644--- a/studio/backend/tests/test_video_wan_fused.py+++ b/studio/backend/tests/test_video_wan_fused.py@@ -16,6 +16,12 @@ import pytestfrom core.inference import video_wan_fused as wftorch = pytest.importorskip("torch")+from torch.torch_version import TorchVersion # noqa: E402++# A CUDA build's version tag: Studio reads ROCm from the "+rocm" tag too (AMD SDK / Radeon wheels leave+# torch.version.hip unset), so a test that fakes NVIDIA clears both.+_CUDA_TORCH_VERSION = TorchVersion(str(torch.__version__).split("+")[0] + "+cu130")+transformer_wan = pytest.importorskip("diffusers.models.transformers.transformer_wan")WanTransformerBlock = transformer_wan.WanTransformerBlock@@ -37,6 +43,7 @@ def _fake_kernels(monkeypatch):# install logic without a GPU; on ROCm torch wanted() refuses HIP, so pretend a CUDA build toomonkeypatch.setattr(wf, "_kernels", lambda: {"modnorm": None})monkeypatch.setattr(torch.version, "hip", None)+ monkeypatch.setattr(torch, "__version__", _CUDA_TORCH_VERSION, raising = False)def test_stock_block_matches_the_fingerprint():