Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
GPT OSS fixes
Daniel Han382042f3b0a1
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 2e88e213e6e..a036970b40b 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -76,6 +76,7 @@ platform_system = platform_system()import numpy as npimport contextlibimport re+import functoolsimport warnings, subprocess, re, inspect, psutil, os, mathfrom unsloth_zoo.utils import Versionfrom unsloth import DEVICE_TYPE, DEVICE_COUNT@@ -422,6 +423,7 @@ HAS_FLASH_ATTENTION_SOFTCAPPING = Falseif DEVICE_TYPE == "cuda":major_version, minor_version = torch.cuda.get_device_capability()+ torch.cuda.get_device_capability = functools.cache(torch.cuda.get_device_capability)if major_version >= 8:SUPPORTS_BFLOAT16 = True@@ -586,7 +588,6 @@ UNSLOTH_COMPILE_DEBUG = os.environ.get("UNSLOTH_COMPILE_DEBUG",UNSLOTH_COMPILE_MAXIMUM = os.environ.get("UNSLOTH_COMPILE_MAXIMUM", "0") == "1"UNSLOTH_COMPILE_IGNORE_ERRORS = os.environ.get("UNSLOTH_COMPILE_IGNORE_ERRORS", "1") == "1"# Just remove max_autotune_gemm warning-import functoolsfrom torch._inductor.runtime.hints import DeviceProperties@functools.lru_cache(None)diff --git a/unsloth/models/loader.py b/unsloth/models/loader.pyindex 77f953a5a3d..15a506174f9 100644--- a/unsloth/models/loader.py+++ b/unsloth/models/loader.py@@ -591,20 +591,12 @@ class FastModel(FastBaseModel):"if name.endswith(('q_proj', 'k_proj', 'v_proj', 'o_proj', 'gate_proj', 'up_proj', 'down_proj', 'head')): module.to(torch.float16); "\"os.environ['TRITON_F32_DEFAULT'] = 'ieee';"elif "gpt-oss" in lowered_model_name:- os.environ["UNSLOTH_DISABLE_STATIC_GENERATION"] = "1"- # the temporary patches for init need UNSLOTH_MODEL_NAME to be set- # which doesn't happen at import so manually call here- # before creating the compiled cache- try:- from unsloth_zoo.temporary_patches.gpt_oss import (- patch_GptOssExperts_MXFP4,- patch_GptOssExperts_bitsandbytes,- )-- patch_GptOssExperts_MXFP4()- patch_GptOssExperts_bitsandbytes()- except:- pass+ os.environ["UNSLOTH_FORCE_CUSTOM_DTYPE"] = \+ "all;None;None;"\+ "x = 'gate_up_proj_bias'\n"\+ "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"\+ "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;"else:for check_model_name in DISABLE_COMPILE_MODEL_NAMES:if check_model_name in lowered_model_name:diff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex 623f263127d..b9cc01e5306 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -365,8 +365,10 @@ class FastBaseModel:allow_float16_runs = (checker == "float16" and dtype == torch.float16)if allow_all_runs or allow_float16_runs:- dtype = eval(_dtype)- bnb_compute_dtype = eval(_bnb_compute_dtype)+ if eval(_dtype) is not None:+ dtype = eval(_dtype)+ if eval(_bnb_compute_dtype) is not None:+ bnb_compute_dtype = eval(_bnb_compute_dtype)correct_dtype = bnb_compute_dtypecustom_datatype = _custom_datatype# Execute code as well