Repository navigation
MoE heuristic dW config: 128-wide N tile for gpt-oss K = 2880 - #15505
Conversation
With UNSLOTH_MOE_DISABLE_AUTOTUNE=1 the heuristic dW tile for gpt-oss (K = 2880) fit down to 64 x 64 x 64. 64 x 128 x 64 at 3 stages, used when 128 divides N, makes gpt-oss-20b gate_up dW 1.34-1.38x faster on the per-expert kernel and 1.39-1.76x on the legacy one (B200, 512 / 4096 tokens), with the same error against fp64. Every other shape keeps its config, and the shared memory fit still shrinks the tile on small cards.
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 |
|
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". |
…reaches (#15515) `tests/test_optimized_precision_conflicts.py` fails 19 of 19 on main (`Repo tests (CPU, rest)`, e.g. job 122034866725 on #15505): ``` NameError: name '_agree_fast_inference_across_ranks' is not defined ``` The fixture compiles `FastLanguageModel.from_pretrained` out of `loader.py` together with a fixed list of three module helpers. #15390 added a call from `from_pretrained` to a new module helper, `_agree_fast_inference_across_ranks`, which was not on that list, so every case now stops on the NameError before reaching the precision checks this file is about. The product code is fine (the helper returns early when `fast_inference` was not requested); the harness list was stale. Instead of adding one more name, the fixture now lifts every `loader.py` top-level function (and literal constant such as `_VLLM_ENGINE_KWARGS`) that `from_pretrained` reaches by name, transitively, skipping anything the fixture already stubs in its namespace. A future helper is picked up automatically, and the stubs keep precedence. Verification (local, CPU): - main: 19 failed; this branch: 19 passed. - Sabotage: making `_agree_fast_inference_across_ranks` raise fails all 19, so the real helper runs on every case. - Stub precedence: redefining a stubbed name (`_raise_if_modeling_ignores_config`) in `loader.py` to raise still passes 19, so the lift never overrides a stub.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
… device (#15516) `tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe` fails on main (`Repo tests (CPU, studio)`, e.g. job 122034866848 on #15505): ``` these skip guards read a probe tests/_zoo_aggressive_cuda_spoof.py patches to True process-wide ... test_mxfp4_packed_low_memory.py:428: torch.cuda.is_available() ``` #15376 added `test_chunked_dx_stays_inside_its_own_budget` with `@pytest.mark.skipif(not torch.cuda.is_available(), ...)`. That probe is the one the CUDA spoof patches to True, so the guard can un-skip on a CPU-only runner when the test shares a session with `tests/version_compat` or `tests/vllm_compat`. The rest of the file already gates on `has_real_cuda()` through its module `pytestmark`; this switches the new test's guard to the same probe. The guard test is right and the kernel change is unaffected; only the new test's skip condition was wrong. Verification (local): - `tests/python/test_accelerator_skip_guards.py`: main 1 failed, 23 passed; this branch 24 passed. - `tests/test_mxfp4_packed_low_memory.py` on a CPU-only box: all 46 skip, including the new test. - On a real GPU `has_real_cuda()` is True, so the test still runs where it is meant to.
The legacy dW kernel was 5-23% slower with the 128-wide tile at N 1024 x K <= 576 (half the programs on a small output). Only widen at N x K >= 768 * 1024. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
… configs (#15928) Follow-up to #15505. #15505 widens the heuristic backward dW tile to 64 x 128 x 64 at 3 stages when K leaves `BLOCK_SIZE_K` 64 (gpt-oss gate_up). The condition does not look at the activation dtype. On a B200 the wide tile is slower for float32 activations, though it is faster for bf16: | dW N x K, float32 X / dY / dW | tokens | before #15505 (ms) | main (ms) | change | |---|---|---|---|---| | 1024 x 960 | 128 | 0.0906 | 0.1026 | 13.2% slower | | 1024 x 960 | 4096 | 0.6449 | 0.7412 | 14.9% slower | | 5760 x 2880 (gpt-oss gate_up) | 128 | 1.4518 | 1.6368 | 12.7% slower | | 5760 x 2880 (gpt-oss gate_up) | 4096 | 10.709 | 12.309 | 14.9% slower | These are B200 numbers from a recheck reviewer: torch 2.14.1, Triton 3.8, interleaved, A/A spread under 0.14%, and bitwise equal outputs. The same runs reproduced the bf16 gain of 1.35x - 1.50x. float32 reaches this path with float32 expert weights, `UNSLOTH_FORCE_FLOAT32=1`, or `UNSLOTH_MOE_TRITON_FP32=1`. These heuristic configs are used under `UNSLOTH_MOE_DISABLE_AUTOTUNE=1`. The autotuned default and the autotune-failure fallback are unchanged. ## Change Widening now skips float32 activations on compute capability 10.x (B200 / sm100), the only architecture where the wide tile was measured slower for float32. bf16 / fp16, callers that pass no dtype, and float32 on every other architecture keep the wide tile. ## Tests - New `test_heuristic_dw_widens_only_16bit_activations[bf16, fp16, fp32]` checks gpt-oss gate_up and N 1024 x K 960. The fp32 case fails on main and passes here. - `tests/test_moe*.py`: 337 passed, 46 skipped (CUDA only), CPU torch 2.14.1. ## Other architectures On L4 (sm89) and RTX PRO 6000 Blackwell (sm120) the wide tile is faster for float32 too, so the float32 exclusion is limited to sm100. fp32 dW kernel time with the 64-wide tile vs main's 128-wide tile (CUDA graphs, interleaved A / A / B over 9 rounds, medians, torch 2.11.0+cu130, Triton 3.6.0; outputs bitwise equal): | cell (fp32), dW kernel | L4: 64-wide vs main | RTX PRO 6000: 64-wide vs main | |---|---|---| | 1024 x 960, T 128, legacy | -5.3% | +9.5% | | 1024 x 960, T 2048, legacy | +7.4% | +22.5% | | 1024 x 960, T 2048, auto | +17.9% | +21.5% | | 1024 x 960, T 8192, legacy | +17.2% | +39.4% | | 5760 x 2880, T 2048, legacy | +22.5% | +32.5% | | 5760 x 2880, T 4096, legacy | +26.2% | +43.4% | With this change both cards pick main's tile for float32 (fix vs main within the A / A band in every cell). `test_heuristic_dw_widens_all_dtypes_on_sm89[bf16, fp16, fp32]` pins it; the fp32 case fails on the previous head. B200 itself was not re-measured here, and A100 / H100 were not measured. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
With
UNSLOTH_MOE_DISABLE_AUTOTUNE=1, the MoE grouped GEMM uses heuristic kernel configs. For gpt-oss (K = 2880), the dW tile is fitted down to 64 x 64 x 64 with 4 stages, because K only leavesBLOCK_SIZE_K64. dW tiles N x K and reduces over tokens, so a 64 x 64 output tile leaves the kernel starved.Change
_get_heuristic_configs(unsloth/kernels/moe/autotune_cache.py) handles this case: when the fitted dW config hasBLOCK_SIZE_K == 64and 128 divides N, it uses a 128-wide N tile at 3 stages, as long as the dW output is at least N x K = 768 x 1024 and the GPU is NVIDIA sm80 or newer._fit_configs_to_smem) still runs afterwards, so the tile shrinks to fit there as before.Results
gpt-oss-20b gate_up dW: E 32, top-k 4, N 5760, K 2880, bf16, permute_x. B200, CUDA events, 3 interleaved reps per arm; the main arm ran twice per rep for the A/A spread.
The max error against an fp64 reference is the same in both arms. The card was shared, so treat these timings as rough.
Shapes where
BLOCK_SIZE_Kis 64 (old tile vs 128-wide; B200, bf16, E 32, top-k 4; CUDA-graph replays, 7 interleaved A/A/B rounds, A/A spread under 1% except two cells at 2.4% and 4.6%; outputs bit-equal). Speedup of the 128-wide tile, for the per-expert / legacy kernel:The first two rows (N x K below 768 x 1024) keep the old tile; every other shape tested (K 192 to 2880, N 1024 and 5760) was faster on both kernels.
Other GPUs (CUDA-graph replays, interleaved A/A/B, outputs bit-equal in every cell, torch 2.14.1):
Tests
tests/test_moe_fallback_tile_dims.pygains the gpt-oss K = 2880 case and the small-output cases (N 1024 x K 192 / 576 keep the old tile, N 1024 x K 960 widens). Run against main's code, it fails ((64, 64, 64, 8, 4) != (64, 128, 64, 8, 3)); here, 61 passed. The MoE dW GPU suites (tile dims, ROCm LDS fallback, dW accumulate, per-expert dW) give 227 passed on B200.Not covered
UNSLOTH_MOE_DISABLE_AUTOTUNE=1; the numbers above are kernel-level.