-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Bugfix] Adds outlines performance improvement #5006
[Bugfix] Adds outlines performance improvement #5006
Conversation
d839241
to
476f6ab
Compare
476f6ab
to
4a9e16a
Compare
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 is great! Thank you for the wonderful work debugging and optimization. Just a small concern about the shape of mask.
from outlines.fsm.fsm import CFGFSM, FSM, RegexFSM | ||
from outlines.fsm.json_schema import build_regex_from_schema | ||
from pydantic import BaseModel | ||
from torch import Tensor, from_numpy, full_like, int64 |
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.
stylistically we would like to keep the torch
namespace so we are using torch.Tensor
etc...
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.
Sweet on it
allowed_tokens_tensor = self.allowed_tokens_cache[state] | ||
|
||
if self.mask is None: | ||
self.mask = full_like(scores, -math.inf) |
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.
Originally the shape is (scores.shape[-1], )
which is not the full shape of scores
.
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.
Oh good catch thank you!
@lynkz-matt-psaltis I would suggest using PyTorch profiler (using |
allowed_tokens_tensor = allowed_tokens_tensor.to( | ||
scores.device, dtype=int64, non_blocking=True) |
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.
non_blocking
has no impact unless the CPU tensor is using pinned memory
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.
Thanks @Yard1 that is very true :)
Epic thanks! I've never done any torch work before so that feedback is golden. |
84d8828
to
5f3eef8
Compare
You can use the Also https://pytorch.org/docs/stable/notes/cuda.html#asynchronous-execution is a great read :) |
5f3eef8
to
d0dd805
Compare
Amazing! Thanks @Yard1. Can I just say you've all been such a welcoming community love it and huge shout out to everyone contributing!!! |
7848018
to
6eb8382
Compare
6eb8382
to
29d0b2d
Compare
Using state directly for the cache key wasn't sufficient - Some tests were failing for some FSMs. I swapped to a tuple on the returned array which is stable but reduces performance to around 400% increase instead of 1600% due to the hashing computational costs. I noticed that Outlines has moved to a Guide structure and the transition has been implemented here: #4109. I'm thinking I'd be better off putting something on top of this PR so its all aligned for an outlines update? Thoughts? |
Since the update has been done (thx! @br3no) is there update to this PR and I would assume it still applies? |
@lynkz-matt-psaltis I guess #5053 is the replacement? |
Kind of - I've been exploring going further with this branch against latest outlines by optimising further. Some of these required outlines changes so I'm worried about the sequencing & coordination aspects of those changes going in. Given the direction of this conversation and the potential for further api signature changes, that may not be as big an issue now. I can look at either:
Any advice? |
This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you! |
This pull request has been automatically closed due to inactivity. Please feel free to reopen if you intend to continue working on it. Thank you! |
This addresses concurrency performance issues when using Outlines leading to high CPU usage and a reduction in batching throughput. Timings showed ~1600% performance increase but I would very much appreciate validation of this method!
Overall approach:
Fixes #3567
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!