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.

fix(ROCm): Comprehensive RDNA GPU support - fix Gemma3 NaN & add is_rdna() (#4109)

金黄色葡萄球君君8a8dcd48ddcf
diff --git a/unsloth/kernels/utils.py b/unsloth/kernels/utils.py
index 0b13c045320..b1211ae3450 100644
--- a/unsloth/kernels/utils.py
+++ b/unsloth/kernels/utils.py
@@ -86,6 +86,15 @@ def is_cdna():
)
+def is_rdna():
+ """Detect RDNA consumer/workstation GPUs (RDNA3, RDNA3.5, RDNA4)."""
+ if not is_hip():
+ return False
+ arch = triton.runtime.driver.active.get_current_target().arch
+ return arch.startswith("gfx1") and not is_cdna()
+
+
def calculate_settings(
n: int,
) -> (
diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py
index 711476b7596..7bb2a24e004 100644
--- a/unsloth/models/loader.py
+++ b/unsloth/models/loader.py
@@ -1131,6 +1131,14 @@ class FastModel(FastBaseModel):
# Set norms to float32 since anyways they get upcasted to float32
# common in both gemma-3 and gemma-3n
os.environ["UNSLOTH_HIGH_PRECISION_LAYERNORM"] = "1"
+ # ROCm/HIP: Gemma3 compiled forward produces NaN on RDNA GPUs
+ # (gfx1100, gfx1101, gfx1102, gfx1150, gfx1151, etc.).
+ # Disable torch.compile for model forward; loss compilation is fine.
+ # See https://github.com/unslothai/unsloth/issues/3385
+ from unsloth.kernels.utils import is_rdna
+
+ if is_rdna():
+ os.environ["UNSLOTH_COMPILE_DISABLE"] = "partial"
# Cohere
elif "cohere2" in model_types_all and transformers_version < Version(
"4.50.0.dev0"