Repository navigation
MoE dW: fall back to the legacy kernel when a per-expert tile overflows and no smaller tile is known - #15238
Merged
Conversation
…ws and no smaller tile is known #14550 made the per-expert dW kernel the default. Its OutOfResources retry only shrinks the tile where a shared memory model exists (NVIDIA); on ROCm _card_smem is None, so the fitted tile equals the failed one and the launch re-raises. The heuristic tile that UNSLOTH_MOE_DISABLE_AUTOTUNE=1 (or an explicit 4-stage tile) picks, 64x64x256 at 4 stages, needs ~81,920 B of LDS per-expert on gfx1151 (64 KiB; offline Triton compile), while the legacy kernel needs 32,768 B, so MoE training there failed where it ran before. When no smaller tile is known, run the legacy kernel for this launch (zeroed dW unless accumulating, its own grid and stage count) and record the tile, so later calls skip the per-expert attempt. NVIDIA tiles the fit can shrink keep the existing path.
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. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
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.
Follow-up to #14550 (per-expert MoE dW kernel) for ROCm.
Problem
The per-expert dW kernel can overflow shared memory (LDS) on ROCm, and nothing catches it:
UNSLOTH_MOE_DISABLE_AUTOTUNE=1(64x64x256, 8 warps, 4 stages, bf16) needs about 80 KiB of LDS in the per-expert kernel. gfx1151 has 64 KiB. The legacy kernel needs 32 KiB for the same tile.OutOfResourceslaunch, the launcher retries once with a tile fitted to the card. On HIP,_card_smemreturns None, so there is no shared memory model, the "fitted" tile equals the failed one, and the launch re-raises.The result is a backward-pass crash in MoE training with the unsloth_triton backend on gfx1151:
NVIDIA is not affected, because
_per_expert_dW_stagesand the retry both use the card's real shared memory limit there.Change
Only in
_launch_grouped_gemm_dW(interface.py), and only when a per-expert launch raisesOutOfResourcesand no smaller tile is known:dWis zeroed first unless accumulating, since the legacy kernel skips empty experts;_PER_EXPERT_DW_FITS, so later calls with that tile go straight to legacy without a failed launch.The NVIDIA shrink-and-retry path is unchanged, and a legacy launch that overflows still raises as before.
Tests
New
tests/test_moe_dw_rocm_lds_fallback.pysimulates the ROCm condition on any CUDA GPU:_card_smemreturns None, and the per-expert launch raisesOutOfResources(81920, 65536);dWand an accumulated one, with an empty expert in the routing.test_moe_dw_per_expert.py+test_moe_dw_accumulate.py(B200, torch 2.14.1)gfx1151 (Radeon 8060S, ROCm 7.13, torch 2.11), base vs this PR on the same runner
The heuristic tile runs once with
permute_x(gate_up style) and once unpermuted (down_proj style):permute_x=TrueOutOfResources: shared memory, Required: 73728, Hardware limit: 65536permute_x=FalseOutOfResources: shared memory, Required: 106496, Hardware limit: 65536The dW test files give 108 passed, 1 failed on main and 110 passed, 1 failed with this PR (the new file adds 2). The one failure is the same test on both:
test_moe_dw_accumulate.py::test_existing_gradient_survives_in_microbatch_cancellation. It is a separate, pre-existing gfx1151 accumulate precision issue that this PR does not touch; I will follow up on it separately.Not covered