Repository navigation
fix(generator): scale torch threads by fetcher count - #781
sirius8050 wants to merge 1 commit into
Conversation
|
Hi @sirius8050! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Configure the PyTorch thread pool of each weight fetcher based on the total
number of fetcher processes running on the host.
This prevents multiple weight fetchers from oversubscribing the available CPUs
during TorchStore tensor assembly.
The change is applied to both the vLLM v0 and v1 generator implementations.
Problem
Weight prefetching can create multiple independent
_WeightFetcherprocessesthrough
n_fetcher_procs, which defaults to 8.The parameter keys are correctly partitioned between these processes, but the
fetcher count was not passed to
_WeightFetcher. As a result, each processconfigured or inherited its PyTorch/OpenMP thread pool without considering the
other fetchers running on the same host.
For example, if every fetcher creates a thread pool based on the full process
CPU affinity, eight fetchers can create approximately eight times more runnable
OpenMP threads than the host can execute concurrently.
This causes CPU oversubscription during TorchStore tensor assembly. Operations
such as
torch.Tensor.copy_, used while assembling tensor shards, enter nativeOpenMP regions and compete with the thread pools of the other fetcher processes.
Adding more fetchers can therefore make assembly slower instead of faster.
see: https://docs.pytorch.org/docs/2.13/notes/multiprocessing.html
Solution
Pass
n_fetcher_procsto every_WeightFetcherwhen it is spawned.Each fetcher runs a setup endpoint once after spawning and calculates its
PyTorch thread budget from the process CPU affinity: