Skip to content

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

Merged
merged 2 commits into from
Aug 11, 2025

Conversation

Anerudhan
Copy link
Collaborator

πŸ“Œ 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

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • [x ] 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.

πŸ§ͺ Tests

  • Tests have been added or updated as needed.
  • All tests are passing (unittest, etc.).

Reviewer Notes

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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

  1. 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. ↩

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@Anerudhan Anerudhan force-pushed the update/BatchPrefillPagedWrapper branch 3 times, most recently from 538af25 to 2b5977e Compare August 7, 2025 06:53
@Anerudhan Anerudhan marked this pull request as ready for review August 7, 2025 06:54
@Anerudhan Anerudhan changed the title Fixes to the benchmark attention wrapper Allow BatchPrefillPagedWrapper to call cudnn API Aug 7, 2025
@Anerudhan Anerudhan force-pushed the update/BatchPrefillPagedWrapper branch from 2b5977e to 220041c Compare August 9, 2025 05:45
@Anerudhan Anerudhan force-pushed the update/BatchPrefillPagedWrapper branch from c27d1fa to bd2ec06 Compare August 11, 2025 16:51
@Anerudhan Anerudhan force-pushed the update/BatchPrefillPagedWrapper branch from bd2ec06 to 5ad0187 Compare August 11, 2025 20:13
Copy link
Collaborator

@yzh119 yzh119 left a 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!

@yzh119 yzh119 merged commit eebb92d into flashinfer-ai:main Aug 11, 2025
2 checks passed
self._max_q_len,
self._max_kv_len,
self._batch_size,
assert self._plan_info is not None, "plan info is not initialized"
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

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!

Comment on lines +1684 to +1691
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()
Copy link
Contributor

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?

Comment on lines +1617 to +1619
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``.
Copy link
Contributor

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?

yzh119 pushed a commit that referenced this pull request Aug 13, 2025
<!-- .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.
-->
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.

4 participants