introduce device_context to simplify code.#3875
introduce device_context to simplify code.#3875ykaitao wants to merge 3 commits intounslothai:mainfrom
Conversation
Summary of ChangesHello @ykaitao, 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 refactors device-specific operations by introducing a 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8a4746caa
ℹ️ 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".
There was a problem hiding this comment.
Code Review
This pull request introduces a DeviceContext class to encapsulate and simplify device-specific operations, which is a great refactoring for code clarity and maintainability. The changes in unsloth/models/llama.py correctly adopt this new abstraction.
My review includes a critical fix for a typo that would cause a NameError and a suggestion to improve exception handling for better robustness. Overall, this is a positive change that improves the codebase structure.
c8a4746 to
fce9504
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a DeviceContext class to encapsulate device-specific logic, which significantly simplifies the code in unsloth/models/llama.py. The refactoring is well-done and improves maintainability by centralizing device-related information and operations. I have a couple of suggestions to further improve the code's clarity and robustness.
fce9504 to
eb3d918
Compare
|
Hi @ykaitao, there is similar statistics logic in vision.py. Would you be able to add your simplifications there as well? Thank you! |
Hi @mmathew23 , yes I can do it later today. |
eb3d918 to
4a2c058
Compare
|
/gemini review |
Hi @mmathew23 , I have handled the similar statistics logic in vision.py. Please review again. |
There was a problem hiding this comment.
Code Review
This pull request introduces a DeviceContext class to encapsulate device-specific logic, which is an excellent refactoring. It significantly simplifies the code in unsloth/models/llama.py and unsloth/models/vision.py by removing duplicated device-checking logic and centralizing it. This greatly improves code clarity and maintainability. My review includes a few suggestions to further enhance the new DeviceContext class for better code quality and to improve exception handling in the model files.
8baf20c to
156d32c
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a DeviceContext class to encapsulate device-specific logic, which is a great improvement. This refactoring simplifies the code in unsloth/models/llama.py and unsloth/models/vision.py by removing duplicated if/elif/else blocks for handling different device types (CUDA, HIP, XPU), enhancing code readability and maintainability. I've found one critical issue regarding module loading that could break the library for users without an XPU-enabled PyTorch build, and I've provided a suggestion to fix it.
f586eb4 to
0e62bc7
Compare
|
Hi Team, I have addressed all the comments. Can this PR be merged? Or do you have additional comments? @mmathew23 @Datta0 @danielhanchen |
No description provided.