-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix] set OMP_NUM_THREADS to 1 by default when using the multiproc_gpu_executor #6109
[Bugfix] set OMP_NUM_THREADS to 1 by default when using the multiproc_gpu_executor #6109
Conversation
Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com>
which code uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @tjohnson31415!!
Libraries like Pytorch and numpy that wrap lower level BLAS libraries often use OpenMP which uses OMP_NUM_THREADS to configure the number of CPU threads to spawn for parallel computations. In my testing, I was looking at the base model load time and the lora adapter load/optmize times, both of which are loading data to the CPU. Any CPU operation on tensors will be affected by this setting. So some more performance testing may be good, but it is clear to me that not setting OMP_NUM_THREADS is more likely to cause problems than setting it to 1 and this change aligns the default behavior w.r.t. threading for the Ray and MP backends. |
Co-authored-by: Nick Hill <nickhill@us.ibm.com>
Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com>
Adding some notes/timing measurements from my testing: My test env was in a Pod in Kubernetes with cpu requests set to 8 and cpu limits set to 16 running on a node with 80 total cores. Without OMP_NUM_THREADS, I think each shard would spawn 80 threads and they'd fight for the CPU. Watching the load with top I noticed CPU time exceeding 16, which caused throttling on top of the context switching overhead. Data recorded below was measured in a Jupyter notebook with Code used for testing.%%time
import os
# Change for testing
#os.environ["OMP_NUM_THREADS"] = "1"
from vllm import LLM, SamplingParams
from vllm.lora.request import LoRARequest
llm = LLM(
model="meta-llama/Llama-2-70b-hf",
tensor_parallel_size=4,
enable_lora=True,
enforce_eager=True,
# change for testing
distributed_executor_backend="ray",
) sampling_params = SamplingParams(
temperature=0,
max_tokens=4
)
prompts = [
"### Text: I have no water and the bill is current and paid. Can you do something about this?\n\n### Label:",
]
lora_path = '/tmp/my_lora'
lora_request = LoRARequest("my_adapter", 1, lora_path) %%time
outputs = llm.generate(
prompts,
sampling_params,
lora_request=lora_request
) For loading Llama 2 70B with TP=4:No OMP_NUM_THREADS set:
OMP_NUM_THREADS = 1:
Using Ray backend (one thread per worker):
For loading and running
|
…m-project#6109) Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com> Co-authored-by: Nick Hill <nickhill@us.ibm.com>
…m-project#6109) Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com> Co-authored-by: Nick Hill <nickhill@us.ibm.com>
…m-project#6109) Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com> Co-authored-by: Nick Hill <nickhill@us.ibm.com>
…m-project#6109) Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com> Co-authored-by: Nick Hill <nickhill@us.ibm.com> Signed-off-by: Alvant <alvasian@yandex.ru>
Set OMP_NUM_THREADS to 1 by default (if unset) when using the
MultiprocessingGPUExecutor
to prevent CPU contention amongst the sharded processes.Without this change, use of the MP backend has caused some regressions because of this CPU contention. From what I can tell, the Ray GPU executor uses
num_cpus=0
which then sets OMP_NUM_THREADS=1 for the Ray worker, regardless of the outside environment.#5230 changed the distributed backend to default to MP instead of Ray in certain conditions. This was released in version 0.5.0, which explains the regression noted in #5564 between versions 0.4.3 and 0.5.0.
For reference, here's how Ray states that it handles OMP_NUM_THREADS generally:
REF
FIX #6072
FIX #5564
FIX #5532
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!