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

Vllm model handler #32410

Merged
merged 20 commits into from
Sep 24, 2024
Merged

Vllm model handler #32410

merged 20 commits into from
Sep 24, 2024

Conversation

damccorm
Copy link
Contributor

@damccorm damccorm commented Sep 9, 2024

This PR adds a model handler for running inference using vLLM. To leverage vLLM's dynamic batching, this spins up a central vLLM serving process, coordinated by a single global model wrapper, which individual worker threads can send RPCs to.

Testing this is tricky since it requires a gpu; I followed the same pattern we use for TensorRT - just launch some examples directly on Dataflow and validate that they run to completion. I didn't do any kind of result validation since results produced by a LLM are non-deterministic.

Part of #32528


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions github-actions bot added the build label Sep 9, 2024
@damccorm damccorm changed the title [WIP] Do not merge: Vllm model handler Vllm model handler Sep 23, 2024
@damccorm damccorm marked this pull request as ready for review September 23, 2024 18:50
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @shunping for label python.
R: @Abacn for label build.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

formatted = []
for message in messages:
formatted.append({"role": message.role, "content": message.content})
completion = client.chat.completions.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if an server exception occurs during the query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will bubble up as an exception and either be retried or sent to a DLQ depending on user configuration. With that said, previously if the server died it would have just stayed dead. I added some logic to handle/avoid that problem by restarting the server if we can't connect.

client = getVLLMClient(model.get_server_port())
inference_args = inference_args or {}
predictions = []
# TODO(https://github.com/apache/beam/issues/32528): We should add support
Copy link
Contributor

Choose a reason for hiding this comment

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

Do they support batch mode in the query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They do not as far as I can tell, unfortunately. I plan on addressing this in a follow up pr though - with vLLMs dynamic batching it still almost certainly makes sense to do something here.

Copy link
Contributor

@shunping shunping left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@damccorm damccorm merged commit 97cb452 into apache:master Sep 24, 2024
104 checks passed
@damccorm damccorm deleted the users/damccorm/vllm branch September 24, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants