Repository navigation
Conversation
DTensor's embedding lookup keeps the mask of the ids on a placement that torch caches for the whole process but fills per thread, so a forward in a second thread fails with 'assert self.mask_buffer.data is not None'. Each rank now looks up the ids of its rows on plain tensors, gives zeros for the others, and the ranks' outputs are summed.
24 tasks
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This branch has not been deployed
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.
What does this PR do?
A model split with tensor parallelism fails as soon as it runs in a second thread:
The embedding with a split vocabulary goes through DTensor's lookup, which keeps some state per thread, and torch reuses it across threads.
Instead, we do the lookup on plain tensors instead. Each rank looks up the ids it owns, returns zeros for the others, and the results are summed. Works for training and inference.
Feel free to push on top of this branch, I didn't gave time to check the code yet.
Reproducer
Continuous batching hits it in practice: every
generate_batchcall runs the model in a new generation thread, so the second call on a tensor-parallel model returns empty outputs.Tests
Added
test_forward_in_another_threadintests/tensor_parallel/test_tensor_parallel.py(tiny Llama config, 2 processes): fails onmainwith the assertion above, passes here.On 2x H100, torch 2.10.0:
maintests/tensor_parallelContinuousBatchingTensorParallelTest(RUN_SLOW=1)test_tp_forward,test_tp_backward,test_tp_generationfor Qwen3 (CPU)Speed
Embedding alone, 2x H100, median ms per call,
main→ this PR:A full model step is unchanged on Qwen2.5-0.5B (forward 31.9 → 32.1 ms, forward + backward 220.7 → 220.0 ms).