vllm icon indicating copy to clipboard operation
vllm copied to clipboard

[wip][Core] Introduce SPMD worker execution using Ray accelerated DAG

Open ruisearch42 opened this issue 1 year ago • 4 comments

This introduces an SPMD execution mode for Worker. In this mode, there is no longer a driver worker and the rank 0 worker is moved to a separate process. All workers are expected to take an ExecuteModelRequest input, instead of using NCCL as a control plane to receive inputs.

To keep the changes contained, for now, this path needs to be used with the new Ray accelerated DAG feature. Compared to Ray Core, this feature reduces system performance overheads for task execution and args passing, by using an execution loop and shared memory, respectively.

This PR is based on top of https://github.com/vllm-project/vllm/pull/5980 , and added the following:

  • [x] Added e2e correctness tests for VLLM_USE_SPMD_WORKER=1 VLLM_USE_RAY_COMPILED_DAG=1
  • [x] Fixed test failures
  • [x] Resolved conflicts with master
  • [ ] (TODO: waiting for Ray version to be released) update the required Ray version
  • [ ] (TODO) will add some benchmarks

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:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to 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:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an 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.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

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!

ruisearch42 avatar Jul 01 '24 15:07 ruisearch42

I'd like to support this, but currently the problem is we need to serialize ExecuteModelRequest and SamplerOutput. They have redundant data and can contain on-device data that are expensive to serialize.

I think the first step should be simplify these two structure.

youkaichao avatar Jul 09 '24 01:07 youkaichao

Can you help me understand the problem better @youkaichao ? I want to understand if it's something we can solve with deltas, plus moving the on-device fields to worker state (like what Jamba modeling does).

cadedaniel avatar Jul 09 '24 05:07 cadedaniel

@cadedaniel I think https://github.com/vllm-project/vllm/issues/6241 should be a starting point.

And, if this PR can achieve the same performance as the main, then I would be glad to accept it. My current impression is this would be slow because of the inefficient serialization overhead.

youkaichao avatar Jul 09 '24 05:07 youkaichao

OK. @ruisearch42 will collect numbers and report here.

cadedaniel avatar Jul 10 '24 04:07 cadedaniel

And, if this PR can achieve the same performance as the main, then I would be glad to accept it. My current impression is this would be slow because of the inefficient serialization overhead.

this is correct. Our old fork shows that doing input delta optimization can match the perf with the master. Do you think it makes sense to merge the PR and follow up after given the feature is isolated using an env var?

rkooo567 avatar Jul 11 '24 22:07 rkooo567

sorry for the long wait.

I did some benchmarking for this branch on 4 H100:

without spmd (using mp backend):

$ python benchmarks/benchmark_throughput.py --output-len 256 --input 256 --model meta-llama/Llama-2-7b-hf -tp 4
Throughput: 32.98 requests/s, 16883.88 tokens/s

with spmd:

$ VLLM_USE_SPMD_WORKER=1 VLLM_USE_RAY_COMPILED_DAG=1 python benchmarks/benchmark_throughput.py --output-len 256 --input 256 --model meta-llama/Llama-2-7b-hf -tp 4 --distributed-executor-backend ray
Throughput: 17.78 requests/s, 9102.25 tokens/s

the throughput is only a half. I might be wrong in the benchmarking, please help me investigate or reproduce.

there is also a shutdown error, although it is benign:

Exception ignored in: <function RayGPUExecutor.del at 0x7fb0ba6d6160> Traceback (most recent call last): File "/data/youkaichao/vllm/vllm/executor/ray_gpu_executor.py", line 373, in del self.forward_dag.teardown() File "/data/youkaichao/miniconda/envs/vllm/lib/python3.9/site-packages/ray/dag/compiled_dag_node.py", line 1402, in teardown monitor.teardown(wait=True) File "/data/youkaichao/miniconda/envs/vllm/lib/python3.9/site-packages/ray/dag/compiled_dag_node.py", line 1204, in teardown outer._dag_submitter.close() File "/data/youkaichao/miniconda/envs/vllm/lib/python3.9/site-packages/ray/experimental/channel/common.py", line 383, in close self._output_channel.close() File "/data/youkaichao/miniconda/envs/vllm/lib/python3.9/site-packages/ray/experimental/channel/shared_memory_channel.py", line 629, in close channel.close() File "/data/youkaichao/miniconda/envs/vllm/lib/python3.9/site-packages/ray/experimental/channel/shared_memory_channel.py", line 512, in close self._worker.core_worker.experimental_channel_set_error(self._writer_ref) AttributeError: 'Worker' object has no attribute 'core_worker'

In general, this is the direction I want to push in the future. However, I would say this implementation is quick and dirty. It is too specialized, and would leave much tech debit for the future. We have two control-plane execution pattern in the same codebase, and the code can be very confusing.

By "quick and dirty", I mean, this PR only specializes to execute_model, and a lot of methods are left untouched. For example, in spmd worker, the driver (engine) does not hold the model anymore, but if we call add_lora, it will still call the driver (engine), which will lead to error. For a full spmd style worker, we should consider all possible functions.

My original plan, is to analyze which objects should live in the engine process and which objects should live in the worker process, and then minimize the data transfer between engine process and worker process. Then we can confidently remove the non-spmd style code completely.

youkaichao avatar Jul 16 '24 18:07 youkaichao

@youkaichao we will take a look at the benchmark. I am 99% sure it is due to that we send all tokens to workers at each batch. The overhead increases with more batch size. So this requires delta input optimization.

rkooo567 avatar Jul 16 '24 18:07 rkooo567

why the benchmark of latency shown in https://github.com/vllm-project/vllm/pull/6032#issue-2384111020 is so different from benchmark of throughput then?

"we send all tokens to workers at each batch"

I assume this would also affect benchmark of latency.

youkaichao avatar Jul 16 '24 18:07 youkaichao

Btw, we are confirming the theory now! Latency benchmark has lower batch size in general compared to throughput benchmark, and I assume that's why. (so with higher batch, serialization overhead is much higher without delta optimization). But 2X is pretty big, and rui is taking a look at this.

rkooo567 avatar Jul 16 '24 18:07 rkooo567

Looking into the benchmarks. Some quick responses:

there is also a shutdown error, although it is benign

Thanks for reporting. This is likely some Ray/config issue, I happen to see the same error yesterday where ADAG is not used. I didn't run into it last time in testing. Will take a look.

By "quick and dirty", I mean, this PR only specializes to execute_model, and a lot of methods are left untouched. For example, in spmd worker, the driver (engine) does not hold the model anymore, but if we call add_lora, it will still call the driver (engine), which will lead to error. For a full spmd style worker, we should consider all possible functions.

Hmm, I think in SPMD mode add_lora will be called on the driver worker (which holds the model), not the driver itself. And it looks straightforward to adapt the code if there is a need.

My original plan, is to analyze which objects should live in the engine process and which objects should live in the worker process, and then minimize the data transfer between engine process and worker process. Then we can confidently remove the non-spmd style code completely.

Great thought. We are probably moving towards the same direction. In this PR, SPMD is config guarded and the plan is to remove non-SPMD path in future without being blocked.

ruisearch42 avatar Jul 16 '24 22:07 ruisearch42

thanks for another review @youkaichao !

rkooo567 avatar Jul 17 '24 18:07 rkooo567