-
Notifications
You must be signed in to change notification settings - Fork 430
Allow BatchPrefillPagedWrapper to call cudnn API #1384
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
Allow BatchPrefillPagedWrapper to call cudnn API #1384
Conversation
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.
Summary of Changes
Hello @Anerudhan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've implemented fixes to the benchmark attention wrapper, specifically targeting the CUDNN backend. My changes ensure that the batch prefill operations are correctly handled by accurately calculating and passing batch offset pointers and by using device-specific sequence length tensors. This improves the robustness and correctness of the CUDNN attention benchmark.
Highlights
- Batch Offset Calculation: I introduced a new variable, "qo_indptr_cudnn", which is crucial for correctly calculating the batch offsets required by the CUDNN attention wrapper. This ensures proper indexing for batched prefill operations.
- Device-Specific Tensor Usage: I updated the call to the CUDNN backend within "run_backend_wrapper" to use the device-specific sequence length tensors, "actual_seq_lens_q_device" and "actual_seq_lens_kv_device". This prevents potential issues with host-device mismatches.
- CUDNN Parameter Update: I added the "batch_offsets_q" and "batch_offsets_o" parameters to the CUDNN attention wrapper call, passing the newly computed "qo_indptr_cudnn". This enables the CUDNN backend to correctly handle the batching of queries and outputs.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. β©
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.
Code Review
This pull request introduces fixes for the cudnn
backend in the testBatchPrefillWithPagedKVCacheWrapper
benchmark. It correctly computes and passes the ragged tensor offsets for query and output. My review identifies a potential integer overflow issue in the offset calculation that could lead to incorrect benchmark results for large inputs. A fix is suggested to ensure 64-bit integer precision for the offsets.
538af25
to
2b5977e
Compare
2b5977e
to
220041c
Compare
c27d1fa
to
bd2ec06
Compare
bd2ec06
to
5ad0187
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.
Thank you @Anerudhan , the PR looks good to me!
self._max_q_len, | ||
self._max_kv_len, | ||
self._batch_size, | ||
assert self._plan_info is not None, "plan info is not initialized" |
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 assertion break trtllm-gen backend, pytest tests/test_trtllm_gen_context.py
failed
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.
fix in #1375 by check backend
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.
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.
@weireweire thanks for the fix!
paged_kv_indptr_host = paged_kv_indptr.to("cpu") | ||
paged_kv_last_page_len_host = paged_kv_last_page_len.to("cpu") | ||
if seq_lens is None: | ||
kv_lens_arr_host = get_seq_lens( | ||
paged_kv_indptr_host, paged_kv_last_page_len_host, page_size | ||
) | ||
else: | ||
kv_lens_arr_host = seq_lens.cpu().flatten() |
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.
Apply non_blocking
for these too?
seq_lens_q: Optional[torch.Tensor] | ||
A uint32 1D tensor indicating the q sequence length of each prompt. shape: ``[batch_size]``. | ||
If not provided, will be set to the same value as ``seq_lens``. |
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.
Comment that it's only used for cudnn attention?
<!-- .github/pull_request_template.md --> ## π Description <!-- What does this PR do? Briefly describe the changes and why theyβre needed. --> ## π Related Issues <!-- Link any related issues here --> ## π Pull Request Checklist Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete. ### β Pre-commit Checks - [ ] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [ ] I have installed the hooks with `pre-commit install`. - [ ] I have run the hooks manually with `pre-commit run --all-files` and fixed any reported issues. > If you are unsure about how to set up `pre-commit`, see [the pre-commit documentation](https://pre-commit.com/). ## π§ͺ Tests - [ ] Tests have been added or updated as needed. - [ ] All tests are passing (`unittest`, etc.). ## Reviewer Notes <!-- Optional: anything you'd like reviewers to focus on, concerns, etc. -->
π Description
π Related Issues
π Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
β Pre-commit Checks
pre-commit
by runningpip install pre-commit
(or used your preferred method).pre-commit install
.pre-commit run --all-files
and fixed any reported issues.π§ͺ Tests
unittest
, etc.).Reviewer Notes