Skip to content

fixup rope sync for everything - #3061

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
Datta0:sync_rope
Aug 2, 2025
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
Datta0:sync_rope

Conversation

@Datta0

@Datta0 Datta0 commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

Move sync back to fast_rope_embedding to make it apply for all models.

@Datta0
Datta0 marked this pull request as ready for review July 29, 2025 11:19
@danielhanchen
danielhanchen merged commit 7d040c4 into unslothai:main Aug 2, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants