-
Notifications
You must be signed in to change notification settings - Fork 529
misc: Add cuda graph tests for invariant FA2 #1704
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
base: main
Are you sure you want to change the base?
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 @Edenzzzz, 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!
This pull request addresses a potential bug related to CUDA graph compatibility for the invariant Flash Attention 2 prefill operation. It introduces new, comprehensive tests that capture and replay CUDA graphs for both full and invariant batch sizes, ensuring that the prefill mechanism behaves as expected under these conditions. This enhancement aims to improve the robustness and reliability of CUDA graph usage within the FlashInfer library.
Highlights
- New CUDA Graph Tests for Prefill: Introduced comprehensive CUDA graph capture and replay tests for
BatchPrefillWithPagedKVCacheWrapper
to ensure correctness and stability when using CUDA graphs with invariant batch sizes. - Test Parameter Adjustments: Modified test parameters including
batch_size
,invariant_bs
,kv_len
, andqo_len
in the prefill tests to cover a broader range of scenarios and validate invariant batch size behavior. - Debug Logging Added: A
printf
statement was added inscheduler.cuh
to output critical batch size calculation variables, aiding in debugging issues related topadded_batch_size
when CUDA graphs are enabled.
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 by creating a comment using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands on the current page.
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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
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 adds CUDA graph tests for invariant FA2 prefill operations. The changes are mostly in tests/test_batch_invariant_fa2.py
, where a new test block for CUDA graphs is added. The existing test functions test_batch_decode_tensor_cores
and test_batch_prefill_tensor_cores
seem to have had their implementations swapped, which makes the diff a bit confusing to follow but is functionally correct.
My review focuses on removing leftover debug code and improving the maintainability of the new test code.
- A
printf
statement, likely for debugging, should be removed frominclude/flashinfer/attention/scheduler.cuh
. - The new CUDA graph test in
tests/test_batch_invariant_fa2.py
has duplicated code for planning the attention wrapper. I've suggested refactoring this into a helper function to improve readability and reduce redundancy.
|
||
const size_t padded_batch_size = | ||
enable_cuda_graph ? std::max(max_batch_size_if_split, total_num_tiles_q) : new_batch_size; | ||
printf("new_batch_size: %d, total_num_tiles_q: %d, padded_batch_size: %d, kv_chunk_size: %ld\n", |
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.
We might not need the printf
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.
still debugging, this does not work now
# capture for full batch | ||
del o_tensor_cores, lse_tensor_cores | ||
g = torch.cuda.CUDAGraph() | ||
default_plan() |
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.
@yzh119 sorry for the false alarm, it works fine with cuda graph, just that I forgot to call default plan before capturing here
📌 Description
cc @yzh119
🔍 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