fix: multiple bug fixes (#390, #311, #316)#405
fix: multiple bug fixes (#390, #311, #316)#405yurekami wants to merge 1 commit intounslothai:mainfrom
Conversation
- Fix unslothai#390: Pass system_type to do_we_need_sudo() for proper package manager detection on non-Debian systems - Fix unslothai#311: Use namespace dictionary for exec/eval in patch_compiling_bitsandbytes to properly access imported modules, add ImportError handling for optional peft dependency - Fix unslothai#316: Handle tuple patch sizes (e.g., (14, 14) for InternVL3 models) in UnslothVisionDataCollator 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @yurekami, 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 addresses three distinct bugs to enhance the stability and compatibility of the system. It improves the detection of system utilities across different Linux distributions, makes module patching more robust by handling optional dependencies and using safer execution contexts, and extends vision model support by correctly interpreting varied patch size formats. These changes collectively contribute to a more reliable and versatile application. 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. 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 introduces several important bug fixes that enhance compatibility and robustness. The changes correctly pass system_type for broader Linux distribution support, refactor module patching to be safer and more robust by using a dedicated namespace and handling ImportError, and add support for tuple-based patch sizes in the vision data collator. The fixes are well-implemented. I've added a couple of suggestions to improve exception handling by replacing bare except clauses with more specific ones, which will improve code clarity and prevent unintended side effects.
| for fx in layers: | ||
| try: layer = eval(f"{x}.{fx}") | ||
| try: layer = getattr(module, fx) | ||
| except: continue |
There was a problem hiding this comment.
Using a bare except is generally discouraged as it can catch unexpected errors, including SystemExit and KeyboardInterrupt, making the program harder to debug and interrupt. Per PEP 8, it's better to catch specific exceptions. In this case, since accessing attributes from dir() can sometimes raise various exceptions if they are computed properties, catching Exception would be a safer and more explicit choice.
| except: continue | |
| except Exception: continue |
| if isinstance(patch_size, (tuple, list)): | ||
| patch_size = patch_size[0] | ||
| self.patch_size = patch_size | ||
| except: |
There was a problem hiding this comment.
The use of a bare except is not ideal as it can hide unexpected errors and goes against PEP 8 guidelines. The code in the try block is likely to raise AttributeError if model.config.vision_config.patch_size does not exist, or IndexError if patch_size is an empty list or tuple. Specifying these exceptions makes the code more robust and easier to understand.
| except: | |
| except (AttributeError, IndexError): |
Summary
system_typetodo_we_need_sudo()for proper package manager detection on non-Debian systems (e.g., Fedora using yum/dnf)exec/evalinpatch_compiling_bitsandbytesto properly access imported modules, addImportErrorhandling for optional peft dependency(14, 14)for InternVL3 models) inUnslothVisionDataCollatorby extracting the first elementChanges
llama_cpp.py: Passsystem_typeargument todo_we_need_sudo()callpatching_utils.py: Refactor import handling with proper namespace and error handlingvision_utils.py: Normalize tuple patch sizes to single integerTest plan
do_we_need_sudo()works correctly with different Linux distrosFixes #390, #311, #316
🤖 Generated with Claude Code