Repository navigation
Context parallel and async GRPO: recognise gated fast forwards - #15559
Merged
Merged
Conversation
Since pre_patch gates its patched methods to Unsloth-loaded models, the class forward of a patched attention or model is a wrapper around the fast forward. Two checks still compared the class forward with `is`: - context_parallel._supports_context_parallel, so context_parallel_size > 1 refused every FastLanguageModel Llama / Qwen2 / Gemma model; - rl._is_unsloth_fast_backbone, so AsyncGRPOTrainer treated the Unsloth backbone like a compiled or vision one when wiring packed rows. Add runs_fast_forward(module, fast), which accepts the fast forward itself or the gate around it on a module marked by mark_unsloth_fast_path, and use it in both places.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
[skip ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
context_parallel_size > 1refused every FastLanguageModel model on main, including Llama, the family it is documentedfor. The error was:
The cause is the pre_patch gate, which runs patched methods only on Unsloth-loaded models. After it, the class
forwardof a patched attention or model is a
functools.wrapswrapper around the fast forward. Two checks still compared theclass forward with
is, so both returned False:context_parallel._supports_context_parallel: context parallelism was refused for every FastLanguageModel model.rl._is_unsloth_fast_backbone:AsyncGRPOTrainertreated an Unsloth backbone like a compiled or vision one whenwiring packed rows. It ran the position_ids self-test, or skipped it on flash attention, instead of passing
packed_seq_lengths.This PR adds
runs_fast_forward(module, fast)inunsloth/models/llama.py. It returns True when the class runsfastdirectly, or through the gate on a module marked by
mark_unsloth_fast_path. An unmarked module behind the gate runsthe stock forward, so it still returns False. Both checks now use it.
Tests
tests/test_gated_fast_forward_checks.pybuilds gated classes with the real_gated_method. It covers:test_context_parallel_fsdp2_gloo.py,test_context_parallel_fsdp2_save_gloo.pyGPU (Kaggle 2x T4, fp16, Ulysses backend, Llama-3.2-1B LoRA r16, seq 16384, 8 steps)
Base (main): all 8 runs raise the
NotImplementedErrorabove inSFTTrainer.__init__.Head: all 8 runs train. Ulysses all-to-all is engaged on every run (3136 calls). Columns:
use_gradient_checkpointing="unsloth"offload was engaged (562 MiB pinned against the 50 MiB initial pool).transformers'
offload=Truealso engaged (816save_on_cpupacks).Ring attention stays refused on T4 by design (it needs compute capability 8.0+); Ulysses is the backend that runs there.
Not covered