From e8328c11de8c14f8fd361bf15d8a98a1cbef83fc Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Mon, 6 Apr 2026 17:28:55 +0000 Subject: [PATCH] fix bfloat16 crash on T4 for FORCE_FLOAT32 models and disable trust_remote_code auto-enable for native t5 models --- studio/backend/core/training/worker.py | 8 ++++---- unsloth/models/loader.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/studio/backend/core/training/worker.py b/studio/backend/core/training/worker.py index db5cf8e948..9815e9d7b7 100644 --- a/studio/backend/core/training/worker.py +++ b/studio/backend/core/training/worker.py @@ -402,9 +402,9 @@ def run_training_process( # ── 1a. Auto-enable trust_remote_code for unsloth/* transformers 5.x models ── # Some newer architectures (e.g. NemotronH) have config parsing bugs in # transformers that require trust_remote_code=True as a workaround. - # Only auto-enable for unsloth/* prefixed models (trusted source). - # Exclude Gemma 4 since it is a native transformers 5.5 model and - # trust_remote_code=True would bypass the compiler (disabling fused CE). + # Only auto-enable for models that genuinely need it (set in YAML defaults). + # Native transformers 5.x models (Qwen3.5, Gemma 4, etc.) do NOT need it + # and enabling it can bypass the compiler (disabling fused CE). from utils.transformers_version import get_transformers_tier _lowered = model_name.lower() @@ -412,7 +412,7 @@ def run_training_process( if ( _tier != "default" and _lowered.startswith("unsloth/") - and _tier != "550" # Gemma 4 is native t5.5 — trust_remote_code bypasses compiler + and _tier not in ("530", "550") # Native t5 models don't need trust_remote_code and not config.get("trust_remote_code", False) ): config["trust_remote_code"] = True diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index df97c5c7df..a34744dba8 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -1357,7 +1357,9 @@ class FastModel(FastBaseModel): or disable_name.lower() in model_types_all ) and ((dtype == torch.float16) or not SUPPORTS_BFLOAT16): os.environ["UNSLOTH_FORCE_FLOAT32"] = "1" - dtype = torch.bfloat16 # Change to bfloat16 loading + # Use bfloat16 storage where supported; fall back to float32 on + # older GPUs (e.g. T4) that lack native bfloat16 support. + dtype = torch.bfloat16 if SUPPORTS_BFLOAT16 else torch.float32 break # Apply gradient checkpointing with smart heuristics use_gradient_checkpointing = apply_unsloth_gradient_checkpointing(