forced precision
This commit is contained in:
parent
ac5f2b33dc
commit
33c7219dc7
2 changed files with 13 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue