Repository navigation
fixup rope sync for everything - #3061
Merged
Merged
Conversation
Datta0
marked this pull request as ready for review
July 29, 2025 11:19
abiswas-realadvice
pushed a commit
to abiswas-realadvice/unsloth
that referenced
this pull request
May 14, 2026
danielhanchen
referenced
this pull request
in danielhanchen/unsloth-staging-2
Oct 14, 2026
…vices (unslothai#13609) * Skip the per-layer RoPE stream sync unless the model spans several devices The stream drain after RoPE (#3049, #3061) fired on every host with more than one visible GPU, so single-GPU training or one DDP rank on a multi-GPU machine paid one host-blocking synchronize per attention layer per forward and per gradient checkpoint recompute. inplace_rope_embedding synced even with one GPU. Keep the drain only once RoPE has run on a second device in the process (device_map / pipeline split), which is the case it was added for. * Register split models at load so RoPE drains from the first forward, and only while one is alive * Register splits made by a hand call to accelerate.dispatch_model too * Drain every RoPE call once a split nobody registered shows up * Resolve index-less device_map entries to the current device, and never let split registration raise * Trim comments in RoPE split-model sync * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Guard the real-kernel RoPE test with has_real_cuda so the CUDA spoof cannot un-skip it --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Lyxot
pushed a commit
to NilayYadav/unsloth
that referenced
this pull request
Oct 22, 2026
…lothai#14611) unslothai#14599 (fused decode RoPE) calls `_sync_if_split(Q)` after its Triton launch in `decode_rope_inplace` and `decode_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 unslothai#3049 / unslothai#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. | decode RoPE path | median s | tokens/s | |---|---|---| | before unslothai#14599 | 0.442 | 72.4 | | main (fused + drain) | 0.723 | 44.3 | | fused, drain removed (this PR) | 0.444 | 72.0 | 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 - Remove `_sync_if_split(Q)` from `decode_rope_inplace` and `decode_qk_norm_rope`. - Single-GPU behaviour is unchanged: the drain was a no-op there. ## Validation - `test_decode_split_sync_and_mixed_devices` now asserts that the decode helpers make no drain call. - New `test_decode_rope_on_another_device_orders_with_the_copy`, which needs two GPUs and skips on one: - rotates Q / K on GPU 1 while GPU 0 is current; - copies straight to GPU 0 with no host sync; - compares the result with the unfused rotation. - `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.
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.
Move sync back to
fast_rope_embeddingto make it apply for all models.