Repository navigation
PrefixGrouper flex: skip the doomed compile on small-smem NVIDIA GPUs, opt-in small tiles - #18645
Conversation
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09fd1cc351
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a4bc14ad0
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…el options) [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
Summary
On a T4 (sm75, 64 KB shared memory), the GRPO PrefixGrouper FlexAttention kernel cannot compile. The 16-bit 128 / 64 tile needs 98304 B at head_dim 128, and the one-stage retry needs the same amount. Today the compile check spends about 3 minutes failing, twice, at the first training step. It then switches PrefixGrouper off.
This PR does two things, both inside the compile-options and compile-check code in
unsloth/utils/prefix_grouper_kernel.py:UNSLOTH_GRPO_PREFIX_GROUPER_SMALL_SMEM=1pins forward and backward tiles that fit 64 KB. The tiles are chosen from the device's queried shared memory limit (Tritonmax_shared_mem, falling back to the torch device properties), never from the GPU name. The settings are forward 32 / 32 with 1 stage and 4 warps, and backward 32 / 32 / 32 / 32 with 1 stage and 8 warps. Every key is pass-prefixed (fwd_*,bwd_*), so nothing leaks between passes. That gives one compiled variant per call site, and the one-stage retry adds no second one.GPUs with 96 KB or more shared memory (sm80+, sm86 / sm89 / sm120, V100) keep exactly the same
kernel_optionsas before. ROCm keeps today's behaviour; the opt-in tiles are available there for testing.Why the small tiles are not the default on T4
Triton 3.8 emits no tensor-core MMA on sm75. A plain
tl.dotin fp16 compiles to 0mma.syncand 256fma.rn.f32, and the flex kernels compile the same way. Attention therefore runs on CUDA cores:On 1.7B the logps phase drops from 1.30 to 0.87 s and the compute_loss forward from 1.50 to 0.96 s, with peak memory going from 4.56 to 4.43 GB. Most of that is lost again in the backward.
Default path, Qwen3-0.6B, base vs head without the opt-in:
Correctness on T4 (opt-in path)
The check uses real Qwen3 FastLanguageModel with LoRA. It compares the PrefixGrouper stream against unshared per-row log-probs and LoRA grads, and the flex kernel was called 56 times.
So the fp16 PrefixGrouper error is at the level of fp16 rounding of the unshared path.
Interaction with #18614 / #18616
The branch is rebased on current main, which includes both PRs. The change touches only the tile selection, the small-smem skip and a shared failure helper, so it merges without conflicts. The AsyncGRPO tree mask (
TreeSegInfo) and the Qwen3-MoE opt-in go through the same_run_flexand_checked_first_call. On T4 they therefore get the same up-front skip, and the same tiles under the opt-in.Tests
tests/test_prefix_grouper_small_smem.pycovers the following:_run_flexpasses the device options.On main, 25 of the 27 tests fail. The two that pass assert the unchanged default.