-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Fix/async chat serving #2727
Merged
simon-mo
merged 13 commits into
vllm-project:main
from
schoennenbeck:fix/async_chat_serving
May 3, 2024
Merged
Fix/async chat serving #2727
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
64060f3
Fixed chat serving init in async case
schoennenbeck 4f37b97
Formatting
schoennenbeck 40fa66e
Smaller model in test
schoennenbeck deb2636
Formatting
schoennenbeck c35d173
Better compatibility to old modality
schoennenbeck 3ea2d5e
Use mock-engine in test
schoennenbeck 17fd021
Merge branch 'main' into fix/async_chat_serving
schoennenbeck 0b5f1b3
Switched to arbitrary awaitable in post-init
schoennenbeck b94b75e
isort
schoennenbeck 9716a8e
Forgot formatting
schoennenbeck def3d4e
Merge branch 'main' into fix/async_chat_serving
schoennenbeck c0b79d6
Format merged files
schoennenbeck 8e8db99
Fixed tests
schoennenbeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import asyncio | ||
from dataclasses import dataclass | ||
|
||
from vllm.entrypoints.openai.serving_chat import OpenAIServingChat | ||
|
||
MODEL_NAME = "openai-community/gpt2" | ||
CHAT_TEMPLATE = "Dummy chat template for testing {}" | ||
|
||
|
||
@dataclass | ||
class MockModelConfig: | ||
tokenizer = MODEL_NAME | ||
trust_remote_code = False | ||
tokenizer_mode = "auto" | ||
max_model_len = 100 | ||
tokenizer_revision = None | ||
|
||
|
||
@dataclass | ||
class MockEngine: | ||
|
||
async def get_model_config(self): | ||
return MockModelConfig | ||
|
||
|
||
async def _async_serving_chat_init(): | ||
serving_completion = OpenAIServingChat(MockEngine(), | ||
served_model_names=[MODEL_NAME], | ||
response_role="assistant", | ||
chat_template=CHAT_TEMPLATE) | ||
return serving_completion | ||
|
||
|
||
def test_async_serving_chat_init(): | ||
serving_completion = asyncio.run(_async_serving_chat_init()) | ||
assert serving_completion.tokenizer is not None | ||
assert serving_completion.tokenizer.chat_template == CHAT_TEMPLATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 line is faulty. There is no code that actually initializes
self.tokenizer = None
beforeself._load_chat_template
is called. You might want to instead usehasattr
to check the existence of the attribute.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.
@DarkLight1337 You are right. Until two weeks ago
ServingEngine
setself.tokenizer = None
in its__init__
but that changed in this commit.The tests still pass because by the time
_load_chat_template
is awaited the tokenizer is now already there (which was the idea behind this in the first place). How do you want to handle 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.
I could open another PR simply replacing
while self.tokenizer is None
bywhile getattr(self, "tokenizer", None) is 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.
I guess inside
tests/async_engine/test_chat_template.py
, you can use anotherMockServingChat
that doesn't have thechat_template
attribute. However, I am doubtful about the value of such a test since it does not depend onOpenAIServing.__init__
, making it useless if another commit changes the logic.IMO It would be more useful to test a situation where the tokenizer takes considerably longer to load, making it more likely that the chat template will be accessed before the engine has fully loaded.
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.
Honestly, I think the current design is not that great as it puts
async
logic into__init__
. It would be better if__init__
requirestokenizer
andchat_template
upfront so that developers are encouraged to place theasync
logic outside of the constructor.To maintain the same functionality as the current
__init__
, we can have a separate asyncstaticmethod
factory that does bothasync
and initialization.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 agree with that sentiment. The only reason
_post_init
is async in the first place is thatengine.get_model_config
is async and in turn this is only async in order to enable the engine-workers to use ray. So 95% of the code is already synchronous and the remaining 5% are only artificially asynchronous to enable ray workers.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.
Loading the chat_template used to be synchronous (before this PR) but this didn't mesh with the async code in the
ServingEngine
's__init__
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.
If you don't mind, I'll work on a PR regarding this issue. This should make it no longer necessary to test the async behaviour of
_load_chat_template
, so the relevant tests will be removed.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.
Feel free to open a PR, but I'm not sure what you mean regarding the tests. As long as
OpenAIServingChat
can still be initiated in an async function I'm fine with everything ;)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 mean that the chat template tests will be reverted to sync functions as opposed to async.
Edit: I have opened #4674, feel free to take a look.