fix bfloat16 crash on T4 for FORCE_FLOAT32 models and disable trust_remote_code auto-enable for native t5 models

This commit is contained in:
Roland Tannous 2026-04-06 17:28:55 +00:00
commit 778a802703
2 changed files with 3 additions and 18 deletions

View file

@ -1737,7 +1737,6 @@ def run_training_process(
)
return
<<<<<<< HEAD
# ── 1a. Auto-enable trust_remote_code for NemotronH/Nano models ──
# NemotronH has config parsing bugs in transformers that require
# trust_remote_code=True as a workaround. Other transformers 5.x models
@ -1749,22 +1748,6 @@ def run_training_process(
if (
any(sub in _lowered for sub in _NEMOTRON_TRUST_SUBSTRINGS)
and (_lowered.startswith("unsloth/") or _lowered.startswith("nvidia/"))
=======
# ── 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).
from utils.transformers_version import get_transformers_tier
_lowered = model_name.lower()
_tier = get_transformers_tier(model_name)
if (
_tier != "default"
and _lowered.startswith("unsloth/")
and _tier != "550" # Gemma 4 is native t5.5 — trust_remote_code bypasses compiler
>>>>>>> 970219a3 (split venv_t5 into venv_t5_530 and venv_t5_550 for tiered transformers 5.x support)
and not config.get("trust_remote_code", False)
):
config["trust_remote_code"] = True

View file

@ -1396,7 +1396,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(