Skip to content

Patch before compile?#3995

Closed
Datta0 wants to merge 2 commits into
unslothai:mainfrom
Datta0:fix_gpt_oss
Closed

Patch before compile?#3995
Datta0 wants to merge 2 commits into
unslothai:mainfrom
Datta0:fix_gpt_oss

Conversation

@Datta0
Copy link
Copy Markdown
Collaborator

@Datta0 Datta0 commented Feb 7, 2026

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Datta0, 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 resolves a critical timing issue in the model compilation workflow. By explicitly applying temporary patches before initiating the main compilation loop, it guarantees that any class replacements or modifications introduced by these patches are correctly registered and active. This prevents the compiler from inadvertently caching references to outdated class definitions, ensuring the integrity and correct behavior of the compiled models.

Highlights

  • Patch Application Order: The unsloth_compile_transformers function has been modified to ensure that TEMPORARY_PATCHES are applied before the model compilation process begins.
  • Compiler Caching Prevention: This reordering prevents the compiler from caching references to original classes (e.g., GptOssTopKRouter, GptOssExperts) before they are replaced by the patches, ensuring the compiler works with the correct, updated class definitions.

🧠 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
  • unsloth/models/_utils.py
    • Reordered the execution flow within the unsloth_compile_transformers function to apply TEMPORARY_PATCHES prior to iterating through model_types for compilation.
Activity
  • The pull request introduces a critical fix for the order of operations during model compilation.
  • The author, Datta0, has opened this PR to address a potential issue with compiler caching of class references.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an extra application of temporary patches right before the model compilation loop. The goal, as stated in the comment, is to ensure class replacements are in place before the compiler caches them. The change is simple and seems to be a targeted fix for a timing issue. My only feedback is a minor concern about the redundancy of applying these patches multiple times (at module load, before compilation, and after compilation), which could be a point for future refactoring to improve maintainability. Overall, the change looks good and addresses a specific need.

Comment thread unsloth/models/_utils.py
Comment on lines +1972 to +1973
for temporary_patch in TEMPORARY_PATCHES:
temporary_patch()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop applies temporary patches, which is also done at the module level (lines 217-218). While the comment explains the need for patching right before compilation, this introduces a second application of the patches before the compilation loop. If these patches are idempotent, this is safe, but it could be slightly inefficient. For long-term maintainability, it would be ideal to have a single, clear point of application or a mechanism to prevent redundant patching. Since this change seems to be a targeted fix, it's acceptable, but it might be worth considering a small refactor to consolidate the patching logic in the future to avoid confusion.

@Datta0 Datta0 marked this pull request as ready for review February 9, 2026 12:19
@Datta0
Copy link
Copy Markdown
Collaborator Author

Datta0 commented Feb 10, 2026

This seems unnecessary. Closing it

@Datta0 Datta0 closed this Feb 10, 2026
@Datta0
Copy link
Copy Markdown
Collaborator Author

Datta0 commented Mar 10, 2026

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant