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

schedule prefills considering padded shape #109

Conversation

tae-su-kim
Copy link

@tae-su-kim tae-su-kim commented Jul 18, 2024

This PR revises prefill scheduling to consider padded shapes of prefills, which is the actual shapes of input tensors for the graphs.

  • While trying to reduce VLLM_GRAPH_RESERVED_MEM as much as possible, we found out that the number of total tokens in a prefill batch can exceed max_num_batched_tokens.
  • It is because the prompt batch is padded in habana_model_runner(#L648) - it pads all prompts to max(find_bucket(max(seq_lens), self.prompt_seq_bucket_cfg), self.block_size).
  • Since the scheduler checks if the sum of actual prompt length exceeds max_num_batched_tokens or not, total number of tokens in a prefill batch after padding can significantly deviate from max_num_batched_tokens in certain cases.

Therefore, we propose to consider the shape of padded prompts during the scheduling process. With this scheduler, we can ensure that the shapes of all prompt batches reside in a pre-defined set of shapes.
I think the pros and cons of the change are as follows:

  • Pros: We can optimize VLLM_GRAPH_RESERVED_MEM further as no additional prefill compilation will happen. This reduces compilation overhead too. Zero pads for prompts tend to decrease since the number of zero pads are now considered during the scheduling.
  • Cons: Prefill batch size tends be limited and overall prefill throughput can be degraded. max_num_batched_tokens must be chosen carefully.

Initial benchmarks of ours are like this:

  • On habana_main, prefill only latency: 73.23 seconds -> 27.92 seconds
  • On habana_main, end-to-end latency: 890.68 seconds --> 739.16 seconds
prefill only: llama-3-8b, single gaudi-2, max-model-len 3072, **max-output-len 1**, max-seq-len 128, max_num_batched_tokens 3072, 1024 queries from OpenOrca, hpu_graph
end-to-end: llama-3-8b, single gaudi-2, max-model-len 3072, **max-output-len 1024**, max-seq-len 128, max_num_batched_tokens 3072, 1024 queries from OpenOrca, hpu_graph
  • On habana_next, prefill only latency: 74.42 seconds -> 32.61 seconds
  • On habana_next, end-to-end latency: 412.73 seconds -> 395.28 seconds
prefill only: llama-3-8b, single gaudi-2, max-model-len 3072, **max-output-len 1**, max-seq-len 128, **max_num_batched_tokens 6144**, 1024 queries from OpenOrca, hpu_graph
end-to-end: llama-3-8b, single gaudi-2, max-model-len 3072, **max-output-len 1024**, max-seq-len 128, **max_num_batched_tokens 6144**, 1024 queries from OpenOrca, hpu_graph

Note that actual throughput gain is limited in habana_next. We are still happy with that since we can be sure that additional prefill graph compilation won't happen.


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!

@tae-su-kim tae-su-kim force-pushed the private/taesu/fixed_scheduler branch from 7407c12 to fec2fd2 Compare July 19, 2024 01:38
@kzawora-intel kzawora-intel added the external Issues or PRs submitted by external users label Aug 29, 2024
kzawora-intel added a commit that referenced this pull request Oct 17, 2024
…imit prefill batch size (#394)

This PR adds following functionality that can be enabled via engine
flags:
- use_padding_aware_scheduling - vLLM scheduler will now calculate token
cost considering padded prefill shape (similar to
#109).
- max_num_prefill_seqs - padding-aware scheduler will perform an
additional check for prefill batch size and will effectively limit
prefill batch size at maximum of `max_num_prefill_seqs`. If unset, max
prefill batch size will be `max_num_seqs`.
Both features are generic and do not require HPU, although they may be
specialized for particular vendor's usage. Padding aware scheduling
includes padding function selector which selects HPU padding function
(considering currently used HPU buckets) if current device is HPU.
Otherwise, it will take a product of batch_size x max_seq_len.
@tae-su-kim
Copy link
Author

tae-su-kim commented Oct 18, 2024

Closing this PR as #394 implements requested feature.

@tae-su-kim tae-su-kim closed this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Issues or PRs submitted by external users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants