Use upstream XLA concurrency utilities#5799
Merged
will-cromar merged 7 commits intomasterfrom Nov 15, 2023
Merged
Conversation
JackCaoG
reviewed
Nov 15, 2023
| std::vector<std::vector<torch_xla::runtime::ComputationClient::DataPtr>> | ||
| results(device_strings.size()); | ||
| torch_xla::runtime::util::MultiWait mwait(device_strings.size()); | ||
| absl::BlockingCounter mwait(device_strings.size()); |
Collaborator
There was a problem hiding this comment.
let's rename it to bc or something, mwait would be confusing if the type is not MultiWait.
mbzomowski
pushed a commit
to mbzomowski-test-org/xla
that referenced
this pull request
Nov 16, 2023
* Use TSL threadpool * remove multiwait * fix test build * Move threadpool namespace * formatting * fix test build * Use BlockingCounter
zpcore
pushed a commit
that referenced
this pull request
Nov 21, 2023
* Use TSL threadpool * remove multiwait * fix test build * Move threadpool namespace * formatting * fix test build * Use BlockingCounter
lsy323
pushed a commit
to lsy323/xla
that referenced
this pull request
Nov 28, 2023
* Use TSL threadpool * remove multiwait * fix test build * Move threadpool namespace * formatting * fix test build * Use BlockingCounter
jonb377
added a commit
that referenced
this pull request
Dec 1, 2023
* Distribute Literal->Tensor copies across thread pool * Update for #5799
ManfeiBai
pushed a commit
to ManfeiBai/PyTorchXLA
that referenced
this pull request
Dec 1, 2023
* Distribute Literal->Tensor copies across thread pool * Update for pytorch#5799
ManfeiBai
pushed a commit
to ManfeiBai/PyTorchXLA
that referenced
this pull request
Dec 1, 2023
* Distribute Literal->Tensor copies across thread pool * Update for pytorch#5799
chunnienc
pushed a commit
to chunnienc/xla
that referenced
this pull request
Dec 14, 2023
* Use TSL threadpool * remove multiwait * fix test build * Move threadpool namespace * formatting * fix test build * Use BlockingCounter
chunnienc
pushed a commit
to chunnienc/xla
that referenced
this pull request
Dec 14, 2023
* Distribute Literal->Tensor copies across thread pool * Update for pytorch#5799
golechwierowicz
pushed a commit
that referenced
this pull request
Jan 12, 2024
* Use TSL threadpool * remove multiwait * fix test build * Move threadpool namespace * formatting * fix test build * Use BlockingCounter
golechwierowicz
pushed a commit
that referenced
this pull request
Jan 12, 2024
* Distribute Literal->Tensor copies across thread pool * Update for #5799
bhavya01
pushed a commit
that referenced
this pull request
Apr 22, 2024
* Use TSL threadpool * remove multiwait * fix test build * Move threadpool namespace * formatting * fix test build * Use BlockingCounter
bhavya01
pushed a commit
that referenced
this pull request
Apr 22, 2024
* Distribute Literal->Tensor copies across thread pool * Update for #5799
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.
@JackCaoG and I both have run into cases where our existing concurrency utilities add significant overhead (e.g. waiting >1ms for lock when completing a
MultiWaittask), which functionally limits the number of threads we can spawn. This PR replaces two custom implementations of common utilities (thread pool and latch/MultiWait) with more optimized upstream equivalents.tsl::thread::ThreadPool. The underlying implementation more carefully reuses threads and handles NUMA affinity to reduce context switching costs.Details
Before:
After:
MultiWaitwithabsl::BlockingCounter. Completing a task requires acquiring a lock, which can cost >1ms in practice with enough threads.BlockingCounterinstead uses a lockless atomic counter, significantly reducing the latency to decrement the remaining task count.MultiWaitstill exists upstream PyTorch if we need to use it for anything. I left usage of the upstreamMultiWaitalone.We already depend on absl and TSL through OpenXLA, so this PR adds no new dependencies.
Tested with SPMD llama inference to confirm no regression in performance:
Baseline:
With this PR:
I found these performance benefits while working on #5737, which spawns significantly more threads and potentially reduces the synchronous time spent in
ExecuteReplicated. See my comment about performance. But, I don't expect this PR to provide significant benefits on its own. Benefits of this PR alone:Future work:
low_latency_hintmakes a difference in performance. Operations through the thread pool are assumed to be low latency by default.tf_prefix from thread names.Details