Conversation
Add dtype casting for vision encoder when using FORCE_FLOAT32.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances model compatibility and stability by addressing data type inconsistencies for specific models, particularly Qwen 3.5. It ensures that models prone to numerical issues with Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for Qwen 3.5 to use float32 precision to prevent overflows, which is a necessary change. The implementation correctly adds the model to the FORCE_FLOAT32 list and includes a patch for vision models to ensure the vision encoder remains in float32. The logic is sound. I have one minor suggestion in unsloth/models/vision.py to improve code readability by using more descriptive variable names.
| _vision_attrs = ("visual", "vision_tower", "vision_model", "vision_encoder") | ||
| _inner = model.model if hasattr(model, "model") else model | ||
| for _va in _vision_attrs: | ||
| _ve = getattr(_inner, _va, None) | ||
| if _ve is not None: | ||
| _ve.to(torch.float32) | ||
| break |
There was a problem hiding this comment.
For improved code readability and long-term maintainability, it would be beneficial to use more descriptive variable names. For instance, _vision_attrs could be renamed to vision_tower_attributes, _inner to inner_model, _va to attr_name, and _ve to vision_tower. This makes the code's intent clearer at a glance.
| _vision_attrs = ("visual", "vision_tower", "vision_model", "vision_encoder") | |
| _inner = model.model if hasattr(model, "model") else model | |
| for _va in _vision_attrs: | |
| _ve = getattr(_inner, _va, None) | |
| if _ve is not None: | |
| _ve.to(torch.float32) | |
| break | |
| vision_tower_attributes = ("visual", "vision_tower", "vision_model", "vision_encoder") | |
| inner_model = model.model if hasattr(model, "model") else model | |
| for attr_name in vision_tower_attributes: | |
| vision_tower = getattr(inner_model, attr_name, None) | |
| if vision_tower is not None: | |
| vision_tower.to(torch.float32) | |
| break |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52769a6c9a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # mismatches in nn.LayerNorm / nn.Linear (e.g. Qwen3.5, Gemma3). | ||
| if do_forced_float32: | ||
| _vision_attrs = ("visual", "vision_tower", "vision_model", "vision_encoder") | ||
| _inner = model.model if hasattr(model, "model") else model |
There was a problem hiding this comment.
Resolve vision encoder from both wrapper and inner model
The forced-float32 fix only looks under model.model when that attribute exists, so for VLM wrappers that keep the vision tower on the outer module (while .model is text-only), no vision submodule gets recast and the original float32-input/float16-weight mismatch still occurs. This means the new Qwen3.5 forced-float32 path can still fail at runtime on those wrappers, so the search should include both the outer model and inner model before giving up.
Useful? React with 👍 / 👎.
No description provided.