You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug Report: ValueError: Attempting to unscale FP16 gradients during training with `fp16=False (ModernBERT-large) #2902
Bug Report: ValueError: Attempting to unscale FP16 gradients during training with fp16=False
📌 Summary
I'm experiencing a runtime crash when fine-tuning answerdotai/ModernBERT-large using unsloth.FastModel with fp16=False. The error indicates that FP16 gradients are being used and attempted to be unscaled, even though automatic mixed precision (AMP) is explicitly disabled.
The training should proceed normally with full precision (fp32) since both fp16 and bf16 are explicitly set to False. No gradient unscaling or AMP logic should be triggered in this configuration.
💡 Suspected Cause
It seems like FastModel.from_pretrained() might still initialize some parts of the model or layers in float16 or c10::Half, regardless of fp16=False in training args.
Please verify if FastModel or ModernBERT initializes with float16 layers by default. If so, consider providing a flag to fully opt-out of any low-precision mode during model loading.
Thanks a lot for the great work on unsloth! It's incredibly fast and well-documented ❤️
Fixed! ModernBERT-large loaded in fp16, cast to fp32 and trained with a plain Trainer completes without the unscale error. Two things for the current release: pass auto_model set to AutoModelForSequenceClassification for a classifier, and use full_finetuning=True rather than flipping requires_grad by hand.
Please update Unsloth: uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir (if it's not in the current release yet it'll be in the next one). Reopen if it still happens!
Activity
bx0-0 commentedon Jul 8, 2025
Also, just to confirm it's not an issue on my end:
Even when I run your official notebook [here](https://colab.research.google.com/github/timothelaborie/text_classification_scripts/blob/main/bert_classification.ipynb) without any modifications, I still get the exact same error:
So it seems like the issue is reproducible even in your own default setup.
Etherll commentedon Aug 5, 2025
Hi, if you want to use full param training please set full_finetuning=True, in FastModel.from_pretrained
instead of
danielhanchen commentedon Sep 15, 2026
Fixed! ModernBERT-large loaded in fp16, cast to fp32 and trained with a plain Trainer completes without the unscale error. Two things for the current release: pass auto_model set to AutoModelForSequenceClassification for a classifier, and use full_finetuning=True rather than flipping requires_grad by hand.
Please update Unsloth:
uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir(if it's not in the current release yet it'll be in the next one). Reopen if it still happens!