-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
[Core][Bugfix][Perf] Refactor Server to Avoid AsyncLLMEngine
#8092
Conversation
Like benchmark_throughput but using AsyncLLMEngine rather than LLM
👋 Hi! Thank you for contributing to the vLLM project. Once the PR is approved and ready to go, please make sure to run full CI as it is required to merge (or just use auto-merge). To run full CI, you can do one of these:
🚀 |
AsyncLLMEngine
AsyncLLMEngine
AsyncLLMEngine
AsyncLLMEngine
AsyncLLMEngine
AsyncLLMEngine
AsyncLLMEngine
cc @KuntaiDu |
request=RPCUtilityRequest.DO_LOG_STATS, | ||
socket=self.input_socket) | ||
|
||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: actually set these
await self._send_one_way_rpc_request( | ||
request=RPCUtilityRequest.CHECK_HEALTH, socket=self.input_socket) | ||
|
||
# Await acknowledgement from MPLLMEngine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a genuinely open question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It indeed seems not ideal. Either of the following approaches make more sense to me (but we probably don't have to fix it in this PR).
- Make sure the response is corresponding to the right sender by matching request ID.
- Cache the health check result in an interval (e.g., 10 seconds) and decouple client health check requests and the actual health checks.
ray_utils.assert_ray_available() | ||
|
||
# TODO: better abstraction? | ||
executor_class = AsyncLLMEngine._get_executor_cls(engine_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: make this generic
|
||
if not self.engine_use_ray: | ||
engine_class = self._engine_class | ||
elif self.worker_use_ray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is worker_use_ray
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the same as --distributed_executor_backend=ray
raise NotImplementedError("Not supported yet!") | ||
return engine_class(*args, **kwargs) | ||
|
||
def run_background_loop(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inner loop?
How should we make this propogate exceptions and do things like have the BackgroundLoopDeadError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it even worth pulling over the LoopDead
logic from the async llm engine?
IIUC that's all there to prevent misconfiguration errors from putting the engine into a state where it only ever responds with an exception, but it looks like it's done pretty bluntly where any exception at all from the model executor will kill the loop. If we want to keep that behavior, we could simply raise from here and exit (after notifying the clients of the exception), and let the frontend die as well.
response = VLLM_RPC_SUCCESS_STR | ||
elif request == RPCStartupRequest.CLIENT_IS_READY: | ||
response = VLLM_RPC_SUCCESS_STR | ||
# Breakout of loop once client is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a break ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't break here because we need to response the client in the next 2 lines? We'll get out of the while loop anyways due to client_is_ready = True
self.stream_outputs(request_outputs) | ||
|
||
def wait_for_new_input(self): | ||
while self.input_socket.poll(timeout=POLLING_TIMEOUT_MS) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do something else here?
# Block until there is a new request. | ||
if not self.engine.has_unfinished_requests(): | ||
self.wait_for_new_input() | ||
|
||
# Handle any new input from the input socket. | ||
self.maybe_handle_new_input() | ||
|
||
# Engine step. | ||
request_outputs = self.engine.step() | ||
|
||
# Stream results to output socket. | ||
self.stream_outputs(request_outputs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to handle error propogatation, maybe we should add a try-except
here, and send the exception back?
@robertgshaw2-neuralmagic @njhill great find about the asyncio overheads being the root cause! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, some small comments
stream=stream, | ||
logprobs=3) | ||
max_tokens=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you need to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will revert before merge. I just use this as a simple test example for myself in dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
def cleanup(self): | ||
"""Cleanup zeromq state on shutdown.""" | ||
self.input_socket.close() | ||
self.output_socket.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need also to close the health socket here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed :)
usage_context=usage_context, | ||
ipc_path=ipc_path) | ||
|
||
engine.run_background_loop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand from the code, the loop that it is running here is not actually run in "the background".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mp_llm_engine
runs in the background. I could change the name of the loop
await self._send_one_way_rpc_request( | ||
request=RPCUtilityRequest.CHECK_HEALTH, socket=self.input_socket) | ||
|
||
# Await acknowledgement from MPLLMEngine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It indeed seems not ideal. Either of the following approaches make more sense to me (but we probably don't have to fix it in this PR).
- Make sure the response is corresponding to the right sender by matching request ID.
- Cache the health check result in an interval (e.g., 10 seconds) and decouple client health check requests and the actual health checks.
response = VLLM_RPC_SUCCESS_STR | ||
elif request == RPCStartupRequest.CLIENT_IS_READY: | ||
response = VLLM_RPC_SUCCESS_STR | ||
# Breakout of loop once client is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't break here because we need to response the client in the next 2 lines? We'll get out of the while loop anyways due to client_is_ready = True
socket.send_multipart((identity, pickle.dumps(e)), | ||
copy=False) | ||
|
||
def run_engine_loop(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible and beneficial to use async functions for all the function calls in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I gathered from this PR description is that this new engine implementation is running in a process without the use of any asyncio event loops, it's just a serial loop taking inputs over zmq and passing them to an LLMEngine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, there is no asyncio at all in this design
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. I'm just wondering whether making the following functions async could further help with performance:
self.maybe_handle_new_input()
request_outputs = self.engine.step()
self.stream_outputs(request_outputs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good point. I have a follow up PR #8125 that makes maybe_handle_new_input() and stream_outputs() async with GPU forward pass and it indeed helps. Maybe we will integrate the changes there immediately into this PR, but not sure yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the async behavior of sockets to this PR (and closed 8125)
# Conflicts: # vllm/entrypoints/openai/api_server.py # vllm/entrypoints/openai/rpc/client.py
@@ -21,6 +21,9 @@ | |||
from vllm.config import ModelConfig | |||
from vllm.engine.arg_utils import AsyncEngineArgs | |||
from vllm.engine.async_llm_engine import AsyncLLMEngine | |||
# yapf: enable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You accidentally copied this line over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks for pointing this.
This PR is transferred to #8157 |
We are addressing all review comments from here in here #8157 |
SUMMARY:
OpenAI
server, but still saw significant slowdown running inAsyncLLMEngine
rather thanLLMEngine
on H100, including when we ran "headless" (e.g. with nouvicorn
server).asyncio
event loop inAsyncLLMEngine
was the root cause of the slowdownAsyncLLMEngine
withMPLLMEngine
.MPLLMEngine
works similarly toAsyncLLMEngine
(i.e. it runs a background loop, accepts new requests, and streams requests back to the clients). We usezeromq
as the message passing protocol rather than pulling fromqueues
and pushing togenerators
RPCClient
, avoiding all issues withToo Many Open Files
Summary Performance vs Offline:
main
multistep
42.9
33.3
pr
multistep
42.9
40.3
main
single-step
34.8
14.9
pr
single-step
34.8
31.6
NOTE: the
multistep
performance on main is "less-bad" because we currently only stream 1/8 tokens. Once we enable incremental streaming, the performance will be closer to -50% on main.NOTE: there is still some remaining performance to get by switching the inner loop to using protobufs
Multistep Performance
1xH100 PERFORMANCE BASELINE:
1xH100 SERVING PERFORMANCE
SUMMARY
main
42.9
main
mp
33.3
main
--disable-frontend-multiprocessing
28.9
pr
mp
40.3
pr
--disable-frontend-multiprocessing
27.9
Single-Step Performance
1xH100 PERFORMANCE BASELINE:
1xH100 SERVING PERFORMANCE
SUMMARY
main
34.8
main
mp
14.9
pr
mp
31.6
TODOS:
abort
|HWM
?)MPLLMEngine
co-authored by @njhill
FIX #7920
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:
format.sh
to format your code.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:
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.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!