diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 1a8fff9ada..c13b2286f3 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -986,8 +986,8 @@ def _unsloth_pre_compute_loss(self, model, inputs, *args, **kwargs): "Read more on gradient accumulation issues here: https://unsloth.ai/blog/gradient" ) pass - with torch.autocast(device_type = "cuda", dtype = torch.float32): - outputs = self._old_compute_loss(model, inputs, *args, **kwargs) + # with torch.autocast(device_type = "cuda", dtype = torch.float32): + outputs = self._old_compute_loss(model, inputs, *args, **kwargs) return outputs pass diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py index 73497e70a7..26e9edffd3 100644 --- a/unsloth/models/vision.py +++ b/unsloth/models/vision.py @@ -65,6 +65,9 @@ __all__ = [ "FastBaseModel", ] +global FORCE_FLOAT32 +FORCE_FLOAT32 = ["gemma3"] + def unsloth_base_fast_generate( self, @@ -178,6 +181,14 @@ class FastBaseModel: assert(dtype == torch.float16 or dtype == torch.bfloat16 or dtype == torch.float32) + global FORCE_FLOAT32 + os.environ["UNSLOTH_FORCE_FLOAT32"] = "0" + for disable_name in FORCE_FLOAT32: + if disable_name.lower() == model_type_arch.lower() and dtype == torch.float16: + print(f"Unsloth: Using float16 precision for {model_type_arch} won't work! Using float32.") + os.environ["UNSLOTH_FORCE_FLOAT32"] = "1" + break + bnb_config = None if full_finetuning and (load_in_4bit or load_in_8bit): print("Unsloth: You selected full finetuning support, but 4bit / 8bit is enabled - disabling LoRA / QLoRA.")