Repository navigation
Fix bare except clauses and remove duplicate MAX_FUSED_SIZE definition - #7138
danielhanchen merged 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request removes an unused constant MAX_FUSED_SIZE in cross_entropy_loss.py and replaces bare except: blocks with specific exception handling (ImportError, AttributeError) in rms_layernorm.py. The review feedback correctly identifies that if the referenced RMSNorm classes are not defined due to import failures, referencing them will raise a NameError which is not caught by the new exception handlers. It is recommended to include NameError in the caught exceptions to prevent potential runtime crashes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| import transformers.models.mllama.modeling_mllama | ||
| transformers.models.mllama.modeling_mllama.MllamaTextRMSNorm = Unsloth_MllamaTextRMSNorm | ||
| except: | ||
| except (ImportError, AttributeError): |
There was a problem hiding this comment.
If the module-level import of MllamaTextRMSNorm fails (e.g., if the class is missing but the mllama module exists), Unsloth_MllamaTextRMSNorm will not be defined. In patch_rms_layernorm, the import of mllama will succeed, but referencing Unsloth_MllamaTextRMSNorm will raise a NameError. Since NameError is not caught by (ImportError, AttributeError), this will cause a runtime crash. Catching NameError prevents this regression.
| except (ImportError, AttributeError): | |
| except (ImportError, AttributeError, NameError): |
There was a problem hiding this comment.
Fixed in 117b540: added NameError to this fallback. If the mllama module exists but MllamaTextRMSNorm was never bound (module-level import failed), the import here still succeeds and the RHS reference would raise NameError, so catching it keeps patch a no-op.
| import transformers.models.mllama.modeling_mllama | ||
| transformers.models.mllama.modeling_mllama.MllamaTextRMSNorm = MllamaTextRMSNorm | ||
| except: | ||
| except (ImportError, AttributeError): |
There was a problem hiding this comment.
If the module-level import of MllamaTextRMSNorm fails, MllamaTextRMSNorm will not be defined in the module scope. In unpatch_rms_layernorm, the import of mllama will succeed, but referencing MllamaTextRMSNorm will raise a NameError. Since NameError is not caught by (ImportError, AttributeError), this will cause a runtime crash. Catching NameError prevents this regression.
| except (ImportError, AttributeError): | |
| except (ImportError, AttributeError, NameError): |
There was a problem hiding this comment.
Fixed in 117b540: same for unpatch. Added NameError so this fallback stays a no-op when MllamaTextRMSNorm is unbound in that version-mismatch case.
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.
|
Pushed a small follow-up: added NameError to the two mllama patch/unpatch fallbacks. If the mllama module exists but MllamaTextRMSNorm is missing, the module-level import fails, so Unsloth_MllamaTextRMSNorm and MllamaTextRMSNorm never get defined. In that case the imports inside patch_rms_layernorm / unpatch_rms_layernorm still succeed and then reference the undefined name, raising NameError, which (ImportError, AttributeError) would not catch. Adding NameError keeps those paths as no-ops, matching the previous bare except. The MAX_FUSED_SIZE removal and the module-level except narrowing look good. Thanks for the cleanup. |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Thanks
|
Changes
1. Replace bare except clauses (rms_layernorm.py)
2. Remove duplicate MAX_FUSED_SIZE definition (cross_entropy_loss.py)
Testing
Note: Full test suite could not be run locally due to environment constraints (requires unsloth_zoo, datasets dependencies and GPU for Triton kernels). Changes are based on static analysis.
Impact