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 <lxcxjxhx@users.noreply.github.com>
Co-authored-by: Daniel Han <23090290+danielhanchen@users.noreply.github.com>
This commit is contained in:
Hyacinth-of-Security 2026-07-15 19:39:38 +08:00 committed by GitHub
commit ee73bcb209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 6 deletions

View file

@ -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(

View file

@ -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