-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[Frontend]: enable generator interface for offline inference #9780
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 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 do one of these:
🚀 |
I've been using this branch, and it seems like performance overhead created is minimal if the user implements async methods in the callback. I'm not sure if it would make sense to be able to pass an async function as the callback itself, or just let the user handle their own implementation. This is how I've gotten it to be performant: import asyncio
# start a new event loop
progress_loop = asyncio.new_event_loop()
pending_tasks = []
def run_event_loop():
asyncio.set_event_loop(progress_loop)
progress_loop.run_forever()
loop_thread = threading.Thread(target=run_event_loop, daemon=True)
loop_thread.start()
# define my callback function logic, run in the new event loop
def some_callback_function(payload):
task = asyncio.run_coroutine_threadsafe(some_async_function(payload), progress_loop)
pending_tasks.append(task)
async def some_async_function(payload):
await my_custom_logic(payload)
# generate outputs
try:
self.llm.generate(inputs, state_callback=some_callback_function)
finally:
for task in pending_tasks:
try:
task.result(timeout=1.0)
except Exception as e:
print(f"Error waiting for task: {e}")
### close the new event loop
progress_loop.call_soon_threadsafe(progress_loop.stop)
loop_thread.join(timeout=1.0)
progress_loop.close() We'd certainly want to write some documentation about how to implement this so as to not hurt performance. |
I’m still a bit curious about the primary use case. I understand what it can be used for. But what are you exactly using this for at the moment? Asking because
|
Thanks for responding here @simon-mo My current use case is simply exposing progress to an external interface. Currently, the only way to see progress is via tdqm, so it's not flexible for creating additional interfaces or exposing to external users. In the future, I think there is a strong case to "streaming" outputs to an interface as they're being generated, so users can terminate runs if responses don't seem right. Finally, I think there's a case to streaming them on the fly so responses can be cached in the case of pre-emption. To respond to your suggestions directly:
|
I had been thinking this would be good to add anyhow. It won't be breaking because we would add a |
|
I've modified the One consideration @simon-mo - the generator will not necessarily yield results in the same order as the inputs, correct? Given this is the case, we can either implement a buffer to handle this on behalf of the client (which might hurt performance) or just indicate that the user should handle this themselves if desired and document how to do so. cc: @njhill |
This pull request has merge conflicts that must be resolved before it can be |
Thanks @sethkimmel3. There's a couple of issues I think (which I hadn't considered when suggesting the stream arg):
|
Thanks @njhill - I'll do some work here considering these issues. |
This pull request has merge conflicts that must be resolved before it can be |
Hi @sethkimmel3, do you plan to continue working on this PR? I notice it's been over a month since the last activity here. |
Hey @hmellor - I do plan to continue this work; I'm not sure when. |
Ok, thanks for the update! |
I'm proposing the ability to add custom callback functions to the
generate
method for offline inference. This is helpful in longer running jobs when users want to programmatically track completion time, see results as they're generating, and so forth. Suggestions like #6154 seem to indicate a desire for such functionality.The interface is quite simple; it looks something like:
Some considerations:
n
generations to mitigate impacts on performance.encode
method, so users can similarly track progress of embedding generation.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.Adding or changing kernels
Each custom kernel needs a schema and one or more implementations to be registered with PyTorch.
Tensors
require meta-functions. Meta-functions should be implemented and registered in python so that dynamic dims can be handled automatically. See above documents for a description of meta-functions.torch.libary.opcheck()
to test the function registration and meta-function for any registered ops. Seetests/kernels
for examples.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!