Skip to content

Conversation

Amir-19
Copy link
Contributor

@Amir-19 Amir-19 commented Oct 13, 2025

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

Summary of Changes

Hello @Amir-19, 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 introduces a comprehensive test suite for the blockwise_gemm functionality, leveraging the CUTLASS Cute DSL. The primary goal is to ensure the accuracy and proper functioning of mixed-precision general matrix multiplication, especially on NVIDIA's Hopper architecture, by comparing its output against a precise PyTorch-based reference.

Highlights

  • New Test for Blockwise GEMM with CUTLASS Cute DSL: A new test file test_cute_dsl_blockwise_gemm.py has been added to validate the blockwise_gemm implementation using the CUTLASS Cute DSL.
  • Mixed-Precision Testing: The test specifically covers mixed-precision GEMM operations, using float8_e4m3fn for input matrices, float32 for scale factors, bfloat16 for the output matrix, and float32 for accumulation.
  • Hopper Architecture Specific: The test is designed to run on NVIDIA SM100 (Hopper architecture), leveraging its specific capabilities for efficient mixed-precision computations.
  • Reference Implementation for Validation: The test includes a reference implementation using torch.einsum combined with custom scaling logic to verify the correctness of the blockwise_gemm kernel.
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 introduces a new test file for the blockwise GEMM cute DSL. The tests are well-structured, but there are several areas for improvement in terms of code clarity, style, and maintainability. I've identified some unused variables, a magic number that should be a constant, a debug print statement, and a violation of PEP 8 naming conventions. Addressing these points will make the new test code cleaner and easier to maintain.

l, m, n, cd_major == "m", get_cutlass_dtype(c_dtype), device=device
)
sfa_torch_cpu = cutlass_torch.matrix(
l, m, math.ceil(k / 128), True, get_cutlass_dtype(scale_dtype), device=device
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The magic number 128 is used in multiple places and appears to represent scale granularity. It should be defined as a constant at the module level, e.g., SCALE_GRANULARITY = 128, and used throughout the file to improve readability and maintainability. This constant should be used on lines 32, 36, 37, 205, 207, 210, 214, and 217.

Suggested change
l, m, math.ceil(k / 128), True, get_cutlass_dtype(scale_dtype), device=device
l, m, math.ceil(k / SCALE_GRANULARITY), True, get_cutlass_dtype(scale_dtype), device=device

Comment on lines +43 to +90
a_tensor, a_torch = cutlass_torch.cute_tensor_like(
a_torch_cpu,
get_cutlass_dtype(ab_dtype),
is_dynamic_layout=True,
assumed_align=16,
)
b_tensor, b_torch = cutlass_torch.cute_tensor_like(
b_torch_cpu,
get_cutlass_dtype(ab_dtype),
is_dynamic_layout=True,
assumed_align=16,
)
c_tensor, c_torch = cutlass_torch.cute_tensor_like(
c_torch_cpu,
get_cutlass_dtype(c_dtype),
is_dynamic_layout=True,
assumed_align=16,
)
sfa_tensor, sfa_torch = cutlass_torch.cute_tensor_like(
sfa_torch_cpu,
get_cutlass_dtype(scale_dtype),
is_dynamic_layout=True,
assumed_align=16,
)
sfb_tensor, sfb_torch = cutlass_torch.cute_tensor_like(
sfb_torch_cpu,
get_cutlass_dtype(scale_dtype),
is_dynamic_layout=True,
assumed_align=16,
)

return (
a_tensor,
a_torch,
b_tensor,
b_torch,
c_tensor,
c_torch,
sfa_tensor,
sfa_torch,
sfb_tensor,
sfb_torch,
a_torch_cpu,
b_torch_cpu,
c_torch_cpu,
sfa_torch_cpu,
sfb_torch_cpu,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The create_tensors function creates and returns several tensors that are not used in the test (a_tensor, b_tensor, c_tensor, sfa_tensor, sfb_tensor, and c_torch_cpu). This can be simplified by not creating or returning these unused variables, which improves code clarity and maintainability. The cute_tensor_like calls can be updated to assign the unused cute tensor to _, and the unused c_torch_cpu can be removed from the return tuple.

    _, a_torch = cutlass_torch.cute_tensor_like(
        a_torch_cpu,
        get_cutlass_dtype(ab_dtype),
        is_dynamic_layout=True,
        assumed_align=16,
    )
    _, b_torch = cutlass_torch.cute_tensor_like(
        b_torch_cpu,
        get_cutlass_dtype(ab_dtype),
        is_dynamic_layout=True,
        assumed_align=16,
    )
    _, c_torch = cutlass_torch.cute_tensor_like(
        c_torch_cpu,
        get_cutlass_dtype(c_dtype),
        is_dynamic_layout=True,
        assumed_align=16,
    )
    _, sfa_torch = cutlass_torch.cute_tensor_like(
        sfa_torch_cpu,
        get_cutlass_dtype(scale_dtype),
        is_dynamic_layout=True,
        assumed_align=16,
    )
    _, sfb_torch = cutlass_torch.cute_tensor_like(
        sfb_torch_cpu,
        get_cutlass_dtype(scale_dtype),
        is_dynamic_layout=True,
        assumed_align=16,
    )

    return (
        a_torch,
        b_torch,
        c_torch,
        sfa_torch,
        sfb_torch,
        a_torch_cpu,
        b_torch_cpu,
        sfa_torch_cpu,
        sfb_torch_cpu,
    )


sm_count = get_num_sm(device)

print(f"device: {device}")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This print statement appears to be for debugging and should be removed from the final test code to avoid polluting test output.

Comment on lines +161 to +179
(
a_tensor,
a_torch,
b_tensor,
b_torch,
c_tensor,
c_torch,
sfa_tensor,
sfa_torch,
sfb_tensor,
sfb_torch,
a_torch_cpu,
b_torch_cpu,
c_torch_cpu,
sfa_torch_cpu,
sfb_torch_cpu,
) = create_tensors(
l, m, n, k, a_major, b_major, c_major, ab_dtype, c_dtype, sf_dtype, device
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The destructuring of the return value from create_tensors should be updated to match the simplified function that no longer returns unused tensors.

    (
        a_torch,
        b_torch,
        c_torch,
        sfa_torch,
        sfb_torch,
        a_torch_cpu,
        b_torch_cpu,
        sfa_torch_cpu,
        sfb_torch_cpu,
    ) = create_tensors(
        l, m, n, k, a_major, b_major, c_major, ab_dtype, c_dtype, sf_dtype, device
    )

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.

1 participant