Skip to content
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

[Misc] Optimize ray worker initialization time #11275

Merged
merged 4 commits into from
Dec 19, 2024

Conversation

ruisearch42
Copy link
Collaborator

@ruisearch42 ruisearch42 commented Dec 18, 2024

This PR optimizes ray worker initialization time.

In the current code base, ray.get(worker.get_node_ip.remote()) is called for each worker right after we get its handle, and it takes ~3s. This call is expensive because when RayWorkerWrapper.remote() just returns, we get an actor handle, but the actor itself may not be fully initialized yet. At this time, any method call on the actor would need to wait for actor initialization to happen, which can take some time (~3s in this case).

And since we are calling ray.get(worker.get_node_ip.remote()) in a serialized manner for each newly created actor handle, this time adds up. For example, when we have TP=4, this would take ~12 seconds.

We optimize this by making ray.get(worker.get_node_ip.remote()) calls on all the actor handles after they are created. And since these run in parallel, the total time taken is ~3s. So for TP = 4, this reduces ~9 seconds.

I tested the following command:

python3 benchmarks/benchmark_latency.py --model meta-llama/Llama-3.1-8B-Instruct --tensor-parallel-size 4  --num-iters-warmup 5 --num-iters 20  --batch-size 8 --input-len 128 --output-len 256 --max-model-len 2048 --no-enable-prefix-caching --distributed-executor-backend ray

Without this PR, _init_workers_ray takes ~18 seconds. And with it, it takes ~9 seconds.

FIX #10283

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

Copy link
Collaborator

@comaniac comaniac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

vllm/executor/ray_gpu_executor.py Outdated Show resolved Hide resolved
@ruisearch42 ruisearch42 added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 18, 2024
ruisearch42 and others added 3 commits December 18, 2024 16:22
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Co-authored-by: Cody Yu <hao.yu.cody@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
@comaniac comaniac enabled auto-merge (squash) December 18, 2024 16:28
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
auto-merge was automatically disabled December 18, 2024 16:32

Head branch was pushed to by a user without write access

Copy link
Member

@youkaichao youkaichao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix!

@youkaichao youkaichao merged commit f26c4ae into vllm-project:main Dec 19, 2024
54 checks passed
@@ -179,7 +188,7 @@ def sort_by_driver_then_worker_ip(worker):
3. Finally, if the work is on a node with smaller IP address, it
should be placed first.
"""
ip = ray.get(worker.get_node_ip.remote())
ip = worker_to_ip[worker]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruisearch42 this one looks concerning to me. we should change the tuple to sort, instead of using worker as the key. see the code from #11256
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Can you elaborate a bit on the concern? The pattern of using an external dict for sorting is not uncommon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using an arbitrary python object as a key introduces quite unpredictable behavior and can have silent bugs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not about using an external dict, it's about using the worker object as a dict key, which implicitly calls its __hash__ function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default behavior without a custom __hash__ function is to use the object's identity (memory address) as __hash__ and __eq__, so it's pretty safe unless there is some non-standard user overridden __hash__ and __eq__?

I think your implementation also makes sense.

BKitor pushed a commit to BKitor/vllm that referenced this pull request Dec 30, 2024
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Co-authored-by: Cody Yu <hao.yu.cody@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: LLM initialization time increases significantly with larger tensor parallel size and Ray
3 participants