Skip to content

Conversation

Edenzzzz
Copy link
Contributor

@Edenzzzz Edenzzzz commented Sep 17, 2025

📌 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

  • 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.

🧪 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 @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, and qo_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 in scheduler.cuh to output critical batch size calculation variables, aiding in debugging issues related to padded_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

  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 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 from include/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",
Copy link
Collaborator

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

Copy link
Contributor Author

@Edenzzzz Edenzzzz Sep 17, 2025

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()
Copy link
Contributor Author

@Edenzzzz Edenzzzz Sep 18, 2025

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

@Edenzzzz Edenzzzz changed the title Bugfix: Add cuda graph tests for invariant FA2 misc: Add cuda graph tests for invariant FA2 Sep 18, 2025
@Edenzzzz
Copy link
Contributor Author

Tests pass now
image

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.

2 participants