Skip to content
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] Adding Strict Priority Scheduling #48

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Conversation

apatke
Copy link

@apatke apatke commented Jun 17, 2024

FILL IN THE PR DESCRIPTION HERE

Motivation

Currently, vLLM supports first-come-first-served scheduling based on the arrival time of requests. This PR aims to add priorities to requests such that high-priority requests are prioritized better than lower-priority ones in the scheduler. Prioritization has also been mentioned previously in discussion e.g. https://github.com/vllm-project/vllm/issues/3058.



Implementation

There are two major changes implemented:


  1. Addition of a new policy SP (strict priority) to the policy factory in addition to FCFS.
    Adds a user-defined priority variable to sequence. All requests in the running queue and the waiting queue are sorted first based on this priority. If there is a tie, it falls back to the FCFS policy.

  2. Force preemption of request from the running queue back into the waiting queue.
    If there are requests in the running queue whose priority is lower than the requests in the waiting queue, they are forcefully preempted out back into the waiting queue to allow immediate execution of the higher priority request. This force preemption does not use KV cache swapping for now (can be extended in the future).



Evaluation

Evaluation conducted with the benchmark_prioritization.py with Llama-7B and A10 GPU. Requests are randomly assigned low or high priority with equal probability.

  1. Throughput is not impacted significantly in this policy
Request Throughput Token Generation
FCFS 1.26 requets/s 650 tokens/s
SP 1.32 requests/s 672 tokens/s

There is no significant difference in throughput between FCFS and SP policy.

  1. Latency for high priority requests is reduced
High Priority - FCFS Low Priority - FCFS High Priority - SP Low Priority - SP
p50 61s 44s 28s 79s
p75 74s 78s 43s 95s
p90 104s 97s 64s 113s
p99 141s 145s 83s 143s
  1. Head of line blocking time reduction

    Head-of-line blocking time also reduces from waiting for ~100 decode iterations to 1 iteration for the request at the front of the waiting queue. This corresponds to a decrease from 3s to 0.03s.

FIX #xxxx (link existing issues this PR will resolve)

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:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to 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:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an 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.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

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!

@saurabhjha1
Copy link

@njhill please help us review.

vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
Copy link
Contributor

@maxdebayser maxdebayser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about the swapping to evaluate how complicated it would be to add that but apart from that I think this makes sense. I left some comments with suggestions to make the code more generic to allow for the addition of other policies without changing the scheduler code.

@maxdebayser
Copy link
Contributor

Actually, maybe instead of adding the priority argument directly a scheduling_metadata dict could be passed instead so that custom scheduling schemes can be supported in the future.

@apatke apatke force-pushed the main branch 4 times, most recently from 143b54e to 98c200b Compare June 19, 2024 18:15
apatke added 14 commits June 19, 2024 20:31
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>
@apatke
Copy link
Author

apatke commented Jun 19, 2024

Thanks for the suggestions. Two changes were made to make the implementation more generalizable: (1) Priority is now under the sched_metadata dict , and (2) Helper functions are added in the policy class (e.g. specifying whether policy supports forced preemption).

Signed-off-by: Archit Patke <[email protected]>
Signed-off-by: Archit Patke <[email protected]>

def _add_request(
self,
inputs: PromptInputs,
params: Union[SamplingParams, PoolingParams],
lora_request: Optional[Union[List[LoRARequest], LoRARequest]] = None,
sched_metadata: Optional[Dict[str, Optional[int]]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can include both priority score and user ID.

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @apatke this is great!

I'd suggest to open it as a PR to upstream vLLM for others to review. You could prefix with [RFC] too.

It would be great to also include a link to the preprint if/when it's publicly available.

Comment on lines +32 to +36
def forces_preemption(self) -> bool:
raise NotImplementedError

def sort_waiting(self) -> bool:
raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could just return False by default

arrival_time: float,
lora_request: Optional[LoRARequest],
trace_headers: Optional[Dict[str, str]] = None,
sched_metadata: Optional[Dict[str, Optional[int]]] = None) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a dataclass or typed dict, i.e. for now with a single priority: int field.

Also not sure about the name sched_metadata, but can't think of a better one rn :)

vllm/core/scheduler.py Outdated Show resolved Hide resolved
@FerranAgulloLopez
Copy link

FerranAgulloLopez commented Jul 3, 2024

Hello:) I was reviewing the proposed changes for the new policy, they look very good!

I have some suggestions and questions for future extensions:

  1. It would be nice to have the sched_metadata parameter enter through the openAI API as well
  2. It would be nice to have the policy parameter enter through the CLI (engine/arg_utils.py) as well
  3. In case that a specific policy needs more input parameters for configuration, what would be the right way to proceed in terms of implementation? For example, if implementing a policy based on VTC we would need to configure parameters weight_input_tokens and weight_output_tokens.
  4. In case that a specific policy needs to add more logging through the prometheus endpoint, what would be the right way to proceed in terms of implementation? For example, in VTC, we would like to show the evolution of the user cost counters. I was thinking of adding a new method in the Policy class, i.e., alternative_logging() that is called by the scheduler and llm_engine every time the default logs are executed

What do you think about these suggestions/questions/comments? I can proceed with their implementation if they seem good to you as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants