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

[V1] Refactor parallel sampling support #13774

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

markmc
Copy link
Collaborator

@markmc markmc commented Feb 24, 2025

The initial implementation in #10980 went to great efforts to add parallel sampling as a wrapper at the highest layer of abstraction possible. This resulted in a lot of tricky code to post-process RequestOutputs to aggregate them where necessary.

Instead, it probably makes sense to implement parallel sampling at the layer that actually creates RequestOutput objects - i.e. in OutputProcessor

To do this, we simply need to allow for fanning out child requests in LLMEngine.add_request(), passing details of the fan-out to OutputProcessor.

This adds some overhead to the n=1 case (see SingularSamplingRequest) in return for significantly less overhead and complication in the parallel sampling case.

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

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 either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label Feb 24, 2025
@mgoin
Copy link
Member

mgoin commented Feb 24, 2025

Nice work cleaning this up!

This adds some overhead to the n=1 case (see SingularSamplingRequest) in return for significantly less overhead and complication in the parallel sampling case.

We should verify that this overhead is negligible with a quick benchmark

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks @markmc, looks great and I agree doing the aggregation in the output processor is much nicer! Just some minor suggestions to simplify further.

Copy link

mergify bot commented Feb 25, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @markmc.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Feb 25, 2025
@markmc markmc closed this Feb 25, 2025
@markmc markmc force-pushed the parallel-sampling-refactor branch from 1aed2ed to 75e9d49 Compare February 25, 2025 10:34
@markmc markmc reopened this Feb 25, 2025
@mergify mergify bot removed the needs-rebase label Feb 25, 2025
@markmc markmc force-pushed the parallel-sampling-refactor branch from 0153a5b to 60fa08d Compare February 26, 2025 12:16
@afeldman-nm
Copy link
Contributor

afeldman-nm commented Feb 27, 2025

Initial benchmarking results with n=1 (averaged over 3x runs) - it appears that there is not a performance regression. I may try a serving benchmark later.

main:

  • Throughput: 41.7 rps
  • P99 LLMEngine average execution time: 2.50 sec

parallel-sampling-refactor:

  • Throughput (rps): 42.0 rps
  • P99 LLMEngine average execution time: 2.47 sec

Command to measure LLMEngine throughput:

VLLM_USE_V1=1 VLLM_ENABLE_V1_MULTIPROCESSING=1 python benchmarks/benchmark_throughput.py --model meta-llama/Llama-3.2-3B-Instruct --input-len 128 --output-len 512

Command to measure LLMEngine average execution time:

VLLM_USE_V1=1 VLLM_ENABLE_V1_MULTIPROCESSING=1 python benchmarks/benchmark_latency.py --model meta-llama/Llama-3.2-3B-Instruct --input-len 128 --output-len 512

@afeldman-nm
Copy link
Contributor

afeldman-nm commented Feb 27, 2025

Async serving benchmarking results with n=1 (averaged over 3x runs) - it appears that there is not a performance regression. Since serving benchmark results can have high variance on beaker, for each metric I also include (loosely speaking) the range of each metric, computed as "worst" minus "best" as a percentage of the "best".

main:

  • Throughput: 79.44 rps (Lowest-Highest %: -2.3%)
  • P99 TTFT: 3512.56 ms (Highest-Lowest %: 5.3%)
  • P99 TPOT: 110.70ms (Highest-Lowest %: 21.6%)
  • P99 ITL: 114.84ms (Highest-Lowest %: 3.0%)

parallel-sampling-refactor:

  • Throughput: 80.49 rps (Lowest-Highest %: -5.3%), +1% improvement over main
  • P99 TTFT: 3289.69 ms (Highest-Lowest %: 6.4%), -6% improvement over main
  • P99 TPOT: 98.53ms (Highest-Lowest %: 1.52%), -11% improvement over main
  • P99 ITL: 111.13ms (Highest-Lowest %: 0.96%), -3% improvement over main

Command to bring up vLLM v1 engine server:

VLLM_USE_V1=1 VLLM_ENABLE_V1_MULTIPROCESSING=1 vllm serve meta-llama/Llama-3.2-3B-Instruct --port 8091 --disable-log-requests --no-enable-prefix-caching

Benchmark command:

python benchmarks/benchmark_serving.py --model meta-llama/Llama-3.2-3B-Instruct --dataset-path ../sharegpt.json  --port 8091

@afeldman-nm
Copy link
Contributor

Nice work cleaning this up!

This adds some overhead to the n=1 case (see SingularSamplingRequest) in return for significantly less overhead and complication in the parallel sampling case.

We should verify that this overhead is negligible with a quick benchmark

Based on the benchmarking results above, there does not appear to be a perf regression.

Copy link
Contributor

@afeldman-nm afeldman-nm 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 PR @markmc ! I left some feedback.

Comment on lines +157 to +162
request = self.processor.process_inputs(request_id, prompt, params,
arrival_time, lora_request,
trace_headers,
prompt_adapter_request,
priority)
Copy link
Contributor

Choose a reason for hiding this comment

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

Something I wondered - can we reuse the output of process_inputs over multiple child requests? Since I believe process_inputs operates solely on the prompt (or MM inputs or whatever.)

This could be tricky for multimodal so I don't know if it is in-scope for this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I did wonder that too, but didn't dig into it. Seem quite orthogonal to this PR though

Copy link
Member

Choose a reason for hiding this comment

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

Yes agree. Actually we can move this outside of the loop I think, and just update the request_id and sampling_params of the request inside the loop.

Doesn't need to hold up this PR but would be quite a simple change I think.

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks @markmc looks great, just a couple more small things.

gens.append(gen)
# If not streaming, aggregate until all child requests complete
if (final_only and len(request_output.outputs) != self.n):
self.output_aggregator = request_output
Copy link
Member

Choose a reason for hiding this comment

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

It would make more sense to me for this assignment to be in the other if above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But you don't want to set it if final_only == False ...

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, ok ignore my comment then! I'm not sure why I find it slightly confusing to overwrite this for the intermediate outputs.

Comment on lines +157 to +162
request = self.processor.process_inputs(request_id, prompt, params,
arrival_time, lora_request,
trace_headers,
prompt_adapter_request,
priority)
Copy link
Member

Choose a reason for hiding this comment

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

Yes agree. Actually we can move this outside of the loop I think, and just update the request_id and sampling_params of the request inside the loop.

Doesn't need to hold up this PR but would be quite a simple change I think.

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

LGTM

@robertgshaw2-redhat robertgshaw2-redhat added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 2, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
The initial implementation went to great efforts to add parallel
sampling as a wrapper at the highest layer of abstraction possible.
This resulted in a lot of tricky code to post-process RequestOutputs
to aggregate them where necessary.

Instead, it probably makes sense to implement parallel sampling at
the layer that actually creates RequestOutput objects - i.e. in
OutputProcessor.

To do this, we simply need to allow for fanning out child requests
in LLMEngine.add_request(), passing details of the fan-out to
OutputProcessor.

This adds some overhead to the n=1 case in return for significantly
less overhead and complication in the parallel sampling case.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
@markmc markmc force-pushed the parallel-sampling-refactor branch from 044ad2f to 7736b2d Compare March 3, 2025 07:37
Add default values for OutputProcessor.add_request() parent_req
and index parameters to fix tests.

These are the values used in the n==1 case.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
@markmc
Copy link
Collaborator Author

markmc commented Mar 3, 2025

Lint and deploy minio setup failing with:

make_bucket failed: s3://testbucket Could not connect to the endpoint URL: "http://127.0.0.1:9000/testbucket"

As per the original V1 parallel sampling code.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
@njhill njhill merged commit 4167252 into vllm-project:main Mar 3, 2025
33 checks passed
Akshat-Tripathi pushed a commit to krai/vllm that referenced this pull request Mar 3, 2025
Signed-off-by: Mark McLoughlin <markmc@redhat.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 v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants