Repository navigation
Fused decode RoPE: drop the per-layer host drain on split models - #14611
Merged
Merged
Conversation
decode_rope_inplace and decode_qk_norm_rope launch inside torch_gpu_device(Q.device), so the kernel runs on Q's device and current stream, and the next layer's cross-device copy is already ordered after it. The _sync_if_split drain added in #14599 blocked the host once per layer and made split-device decode about 40% slower. Adds a two-GPU ordering test (skips on one GPU).
Member
Author
|
@codex review |
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. Bravo. 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]
danielhanchen
added a commit
that referenced
this pull request
Oct 22, 2026
…able probe (#14661) `tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe` fails on main since #14611: ``` E AssertionError: these skip guards read a probe tests/_zoo_aggressive_cuda_spoof.py patches to True process-wide, ... E test_decode_fused_rope.py:230: torch.cuda.device_count() ``` It runs in the Backend CI `studio` shard (`tests/python`), so every PR whose shard runs on current main goes red there. The product code is fine; the test's skip condition is what the guard exists to catch. ### Change `tests/test_decode_fused_rope.py`: - The two-GPU test is gated `not has_real_cuda() or torch.cuda.device_count() < 2`, so the recorded real-hardware answer short-circuits ahead of the spoofable `device_count()`, which is the form the guard accepts. - The module-level skip read `torch.cuda.is_available()`, which the same spoof patches to True. The guard only inspects `skipif` decorators so it did not flag it, but in a session that loads the spoof it would un-skip the whole file on a CPU box. It now uses `has_real_cuda()` too. ### Verification - The guard passes on this branch (24 passed) and fails on main with the line above (1 failed, 23 passed). - On a CPU box the file is skipped as one module. - On a real GPU, `has_real_cuda()` is True with `device_count()` 1, so the module still runs and only the two-GPU test skips.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 22, 2026
…2 ulp (unslothai#14752) Follow-up to unslothai#14611. `test_decode_rope_on_another_device_orders_with_the_copy` compared the fused decode RoPE output with the unfused ops at `atol = 0.05`. The fused kernel rounds once and the unfused ops round several times, so valid bf16 results differ by one ulp, which is 0.0625 for |x| >= 8. With the test's `3 * randn` inputs that happens on most seeds, so the test fails on a two-GPU runner without anything being wrong. ## Change - The copy is compared bitwise with the same kernel run on the same inputs with its own device current. That is the property the test exists for: a copy racing the rotation would see unrotated values, which a bitwise check catches and a 0.05 tolerance could hide. - Fused vs unfused uses the 2 ulp bound already used by `test_decode_rope_inplace_matches_unfused` in the same file. ## Validation - Single-GPU stand-in of the same comparison over 200 seeds (400 tensors): max fused vs unfused difference 0.0625, the old `atol = 0.05` check fails 367 of 400, the 2 ulp bound holds on all 400, and the fused kernel is bitwise deterministic run to run. - Not run as written: the test needs two GPUs in one process and still skips on single-GPU runners. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.
#14599 (fused decode RoPE) calls
_sync_if_split(Q)after its Triton launch indecode_rope_inplaceanddecode_qk_norm_rope. On a model split across GPUs (device_map), that blocks the host once per layer per decoded token.The drain is not needed there. Both helpers launch inside
torch_gpu_device(Q.device), so the kernel runs on Q's device and its current stream. The next layer's.to(other_device)is already ordered after it: PyTorch's device-to-device copy synchronizes with the current streams of both devices (aten/src/ATen/native/cuda/Copy.cu). The older eager RoPE entry points keep their drains. Those were added in #3049 / #3061 for launches made while another GPU was current, and this PR does not touch them.Measured on a random-weight 8-layer Llama (hidden 2048, fp16) split 4 + 4 over two B200s: batch 1, 32 new tokens, 4 interleaved repeats, median generate time.
All three arms produced the same tokens. With random weights that is only a weak correctness check (the output is mostly one repeated token), so this PR also adds a direct ordering test.
Change
_sync_if_split(Q)fromdecode_rope_inplaceanddecode_qk_norm_rope.Validation
test_decode_split_sync_and_mixed_devicesnow asserts that the decode helpers make no drain call.test_decode_rope_on_another_device_orders_with_the_copy, which needs two GPUs and skips on one:test_decode_fused_rope,test_qk_norm_rope,test_rope_kernel_layouts,test_rope_sync_single_device,test_qwen3_decode_offset_rope, GPU-marked tests included: 414 passed, 1 skipped (the two-GPU test) on torch 2.14.1 and on torch 2.10.0.Not covered: the two-GPU test was not run here (single-GPU leases). The timing table comes from a two-GPU run of the same change outside this PR's CI. ROCm split models were not tested.