Repository navigation
Fixup multi GPU workload. - #3049
Merged
Merged
Conversation
14 tasks
abiswas-realadvice
pushed a commit
to abiswas-realadvice/unsloth
that referenced
this pull request
May 14, 2026
* sync all instead * sync after move and rope init instead * sync after rope inside * Return new tensors and no sync * Sync only current stream * Fixup mask for xformers * sync for prefill only * clean up
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.
Multi GPU was failing due to few reasons
Previously we initialised per gpu position embeddings. That fixed the operands being on right devices. Now there's a small issue that after few layers, the activations/hidden_states end up becoming NaNs.
A workaround I stumbled upon was adding
print(for debugging purposes lol) afterfast_rope_embedding.Inspired by that as discussed with @danielhanchen , I added sync. Initial thought was to sync all devices but syncing only current device felt like the right choice as we use PP. (Might need to revisit for other cases later)
Verified inference of mistralai/Mistral-7B-Instruct-v0.3, unsloth/Llama-3.1-8B-Instruct, google/gemma-2-9b-it and Qwen/Qwen3-8B. There are no NaNs in generate.
On Mi(s/x)tral, when using xformers, no causal mask was being applied. It was doing full attention. To avoid that we need to create and pass mask irrespective of whether attention_mask is mentioned. (Note that when you do
the
inputswould haveattention_maskkey/field causing causal_mask to not be created previously. So this also addresses that.Magistral as example starts at a loss of 1.x as it should :)
