Add /v1/chat/completions/batch endpoint for batched chat completions#38011
Conversation
|
Documentation preview: https://vllm--38011.org.readthedocs.build/en/38011/ |
There was a problem hiding this comment.
Code Review
This pull request introduces support for batched chat completion requests, which is a valuable feature. The implementation is mostly solid, with new examples, tests, and protocol/serving logic changes. I've found two issues that should be addressed: one critical issue regarding the handling of the n parameter in batched requests which could lead to malformed responses, and a high-severity bug in the echo=True functionality for these new batched requests. After these are fixed, the PR should be in good shape.
|
👋 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. 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 If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
|
Documentation preview: https://vllm--38011.org.readthedocs.build/en/38011/ |
|
Hi @MatejRojec, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, Tip Is
|
234ec82 to
7e98641
Compare
|
This is outside of OpenAI API spec so we will not support this for Chat Completions API to avoid bloating the existing functionality and make the implementation even more complicated. If you want this feature, it would be better to define a separate endpoint and use it. |
/v1/chat/completions/batch endpoint for batched chat completions
Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com>
Head branch was pushed to by a user without write access
Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com>
Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com>
|
I had to make some small changes, because some of the tests were failing and some import errors. I have tested the code again now and all looks good to me. |
vllm-project#38011) Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com>
vllm-project#38011) Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com> Signed-off-by: Nithin Chalapathi <nithin.ch10@gmail.com>
vllm-project#38011) Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com>
vllm-project#38011) Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com> Signed-off-by: Rishi Puri <riship@nvidia.com>
vllm-project#38011) Signed-off-by: Matej Rojec <64556640+MatejRojec@users.noreply.github.com>
Purpose
This PR adds a new
/v1/chat/completions/batchendpoint to vLLM's OpenAI compatible API. The existing/v1/chat/completionsendpoint only accepts a single conversation per request and remains unchanged. The new endpoint accepts messages as alist[list[...]].This is useful for applications that need to process multiple independent prompts with structured output in a single round trip, for example, extracting structured data from multiple documents simultaneously, reducing HTTP
overhead and simplifying result handling since all outputs arrive in one response.
Test Plan
I tested 4 cases:
0. Single conversation (non-batched): verified existing /v1/chat/completions behaviour is unchanged
JSONschema constraint, verified each choice parses to valid JSON matching the schema(yes|no)regex, verified each choice contains only yes or noTest Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.