Fix gpt temporary patch for grpo to happen after compile#4180
Fix gpt temporary patch for grpo to happen after compile#4180danielhanchen merged 2 commits intounslothai:mainfrom
Conversation
for more information, see https://pre-commit.ci
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 addresses a critical issue where certain temporary patches, particularly the GPT GRPO patch, were executing at an incorrect stage relative to the compiler, leading to a loss of connection to Highlights
Changelog
Activity
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: 1a93b57df6
ℹ️ 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".
| except (ValueError, TypeError): | ||
| temporary_patch() |
There was a problem hiding this comment.
Narrow TypeError fallback to signature introspection
Catching TypeError around the whole patch invocation can mis-handle real runtime failures inside a temporary patch: if temporary_patch(phase=phase) raises a TypeError from its own logic (not from argument binding), this code retries temporary_patch() and can execute patch side effects twice while obscuring the original failure path. This regression only appears when a patch throws TypeError, but in that case it can leave monkey-patched state inconsistent and make debugging much harder.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request introduces a phased execution for temporary patches, allowing them to run at different stages like 'init', 'pre_compile', and 'post_compile'. This is achieved by adding a _run_temporary_patches function that inspects patch signatures for a phase parameter. My review focuses on improving the robustness of the new error handling logic. Overall, the change is well-structured to address the issue of patch ordering.
| temporary_patch() | ||
| except (ValueError, TypeError): |
There was a problem hiding this comment.
The except (ValueError, TypeError) block is overly broad and can mask TypeError exceptions that signal a genuine issue with a patch function, such as incorrect arguments. By catching TypeError and then unconditionally calling temporary_patch(), you might suppress the original error and cause a new, potentially more confusing one. It's better to only catch ValueError, which inspect.signature raises for callables it can't inspect (like some C built-ins). A TypeError should generally be allowed to propagate to indicate a problem with the patch or its invocation, leading to faster bug detection.
| temporary_patch() | |
| except (ValueError, TypeError): | |
| except ValueError: | |
| temporary_patch() |
Fixes #4175
The gpt oss grpo patch in temporary_patches runs 3 times. Since it runs before compiler, compiler doesnt match the causallm pattern so we lose the connection to unsloth fused loss. This PR proposes phases for temporary patches so patches can determine when they want to run.
Depends on unslothai/unsloth-zoo#536
Notebooks Tested:
gpt finetuning
https://colab.research.google.com/drive/11Hi8srn79s5gGoVbOhtw09LCkq6wfJnb?usp=sharing
gpt long context
https://colab.research.google.com/drive/1jcMg3xQ5c1C1Vxd-6DcZjIuzgfEBh56R?usp=sharing
gpt grpo
https://colab.research.google.com/drive/1JwlBpfg-cpnUDtlIdtziSfDxKP_YlMwW?usp=sharing