From 64dff1456ba06aa218ed6f5e55643faa737dbe2e Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Fri, 15 Aug 2025 04:00:00 -0700 Subject: [PATCH] GPT OSS MXFP4 fix --- unsloth/models/loader.py | 1 + unsloth/models/vision.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index d0b7d4dc4c..93415f5647 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -621,6 +621,7 @@ class FastModel(FastBaseModel): "if hasattr(module, x): "\ "setattr(module, x, torch.nn.Parameter(getattr(module, x).to(torch.float32)) if isinstance(getattr(module, x), torch.nn.Parameter) else getattr(module, x).to(torch.float32))\n"\ "x = 'down_proj_bias'\n"\ + "setattr(module, x, torch.nn.Parameter(getattr(module, x).to(torch.float32)) if isinstance(getattr(module, x), torch.nn.Parameter) else getattr(module, x).to(torch.float32))\n"\ ";" else: # Set down projection compute dtype to be float32 for float16 machines diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py index 5524d8f16d..a5de457cef 100644 --- a/unsloth/models/vision.py +++ b/unsloth/models/vision.py @@ -457,8 +457,10 @@ class FastBaseModel: # Edit data-types if custom_datatype is not None: - for jj, (name, module) in enumerate(model.named_modules()): - exec(custom_datatype) + with torch.no_grad(): + for jj, (name, module) in enumerate(model.named_modules()): + exec(custom_datatype) + pass pass pass # Clear deleted GPU items