From ee73bcb209dfe54818719e4b0b50ed560fa44639 Mon Sep 17 00:00:00 2001 From: Hyacinth-of-Security <144213008+lxcxjxhx@users.noreply.github.com> Date: Wed, 15 Jul 2026 19:39:38 +0800 Subject: [PATCH] Fix bare except clauses and remove duplicate MAX_FUSED_SIZE definition (#7138) * fix: replace bare except clauses and remove duplicate MAX_FUSED_SIZE definition * Also catch NameError in mllama RMSNorm patch/unpatch fallbacks If mllama exists but MllamaTextRMSNorm is missing, the module-level import fails so Unsloth_MllamaTextRMSNorm/MllamaTextRMSNorm stay undefined. The patch/unpatch module imports then succeed and reference the undefined name, raising NameError. Add NameError so these fallbacks stay no-ops as before. --------- Co-authored-by: lxcxjxhx Co-authored-by: Daniel Han <23090290+danielhanchen@users.noreply.github.com> --- unsloth/kernels/cross_entropy_loss.py | 3 --- unsloth/kernels/rms_layernorm.py | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py index 39446ec639..0d3bf08c35 100644 --- a/unsloth/kernels/cross_entropy_loss.py +++ b/unsloth/kernels/cross_entropy_loss.py @@ -285,9 +285,6 @@ _cross_entropy_backward = triton.heuristics( )(_cross_entropy_backward) -MAX_FUSED_SIZE = 65536 # 2**16 - - class Fast_CrossEntropyLoss(torch.autograd.Function): @staticmethod def forward( diff --git a/unsloth/kernels/rms_layernorm.py b/unsloth/kernels/rms_layernorm.py index bc81c5533a..5fc867e0cb 100644 --- a/unsloth/kernels/rms_layernorm.py +++ b/unsloth/kernels/rms_layernorm.py @@ -270,7 +270,7 @@ try: return fast_rms_layernorm(self, X, gemma = False) -except: +except (ImportError, AttributeError): pass @@ -281,7 +281,7 @@ def patch_rms_layernorm(): try: import transformers.models.mllama.modeling_mllama transformers.models.mllama.modeling_mllama.MllamaTextRMSNorm = Unsloth_MllamaTextRMSNorm - except: + except (ImportError, AttributeError, NameError): pass return @@ -293,7 +293,7 @@ def unpatch_rms_layernorm(): try: import transformers.models.mllama.modeling_mllama transformers.models.mllama.modeling_mllama.MllamaTextRMSNorm = MllamaTextRMSNorm - except: + except (ImportError, AttributeError, NameError): pass return