Skip to content

Single sourced QuantizationSFLayout#1531

Closed
cyx-6 wants to merge 4 commits intoflashinfer-ai:mainfrom
cyx-6:single-source
Closed

Single sourced QuantizationSFLayout#1531
cyx-6 wants to merge 4 commits intoflashinfer-ai:mainfrom
cyx-6:single-source

Conversation

@cyx-6
Copy link
Copy Markdown
Collaborator

@cyx-6 cyx-6 commented Aug 21, 2025

📌 Description

Unified the QuantizationSFLayout to single sourced enum class.

🔍 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
Copy Markdown
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 @cyx-6, 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 aims to improve code maintainability and consistency by single-sourcing the QuantizationSFLayout enum. Previously, this enum was defined in multiple locations, leading to potential discrepancies and increased overhead for updates. By centralizing its definition into a new header file and updating all references, the change ensures a unified and consistent representation of quantization scale factor layouts across the codebase, simplifying future modifications and reducing the risk of errors.

Highlights

  • Enum Centralization: The QuantizationSFLayout enum, previously duplicated across multiple C++ and Python files, has been centralized into a single C++ header file (include/flashinfer/fp4_layout.cuh).
  • Code Refactoring: Existing C++ files now reference the single-sourced QuantizationSFLayout using using declarations, removing redundant local definitions.
  • Cross-Language Alignment: The Python definition of QuantizationSFLayout has been updated to align with the new C++ enum, including new members like SWIZZLED_8x4 and adjusted integer values.
  • Configuration Updates: Default values for QuantizationSFLayout in relevant structs and test cases have been updated to reflect the new, more specific enum members (e.g., SWIZZLED_128x4).
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. 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
Copy Markdown
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 does a great job of single-sourcing the QuantizationSFLayout enum, which significantly improves code maintainability by removing duplication. The changes are applied consistently across both C++ and Python code.

I have a couple of minor suggestions for code improvement. Additionally, I've noticed a potential issue in the test files (tests/test_trtllm_allreduce_fusion.py and tests/test_trtllm_moe_allreduce_fusion.py). It appears they still reference the old comm.QuantizationSFLayout.SWIZZLED member, which has been removed in this PR. This will likely cause the tests to fail and should be corrected to use the new enum members.

Comment on lines +93 to +97
SWIZZLED_128x4 = 0
SWIZZLED_8x4 = 1
# Block scale factors are stored in linear layout (row-major). This is used in some trtllm-gen
# kernels standard.
LINEAR = 1
LINEAR = 2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better type safety and to follow modern Python practices, consider changing this class to an enum.IntEnum. This would make the code more robust and expressive. You would need to add from enum import IntEnum at the top of the file and change the class definition to class QuantizationSFLayout(IntEnum):.

Comment thread include/flashinfer/fp4_layout.cuh Outdated
// kernels standard.
LINEAR
};
}; No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

It's a common convention and good practice to end files with a newline character. This can prevent issues with some tools and compilers. Please add a newline at the end of the file.

yzh119 added a commit that referenced this pull request Aug 21, 2025
<!-- .github/pull_request_template.md -->

## 📌 Description

Currently comm modules and moe modules are not compiled in aot
unittests, which results in lots of issues such as #1371 #1410, and
#1530.
This PR adds these modules to aot UT to make sure we capture the
potential compilation error of these modules.

#1531 (a bugfix) changes were ported into this PR to test together.

## 🔍 Related Issues

#1371, #1410, #1530, #1531

## 🚀 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

- [x] 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`.
- [x] 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

- [x] Tests have been added or updated as needed.
- [ ] All tests are passing (`unittest`, etc.).

## Reviewer Notes

cc @nvpohanh @weireweire

---------

Co-authored-by: Yaxing Cai <yaxingc@nvidia.com>
Co-authored-by: Zihao <zihaoy@nvidia.com>
Co-authored-by: Zihao Ye <expye@outlook.com>
@yzh119
Copy link
Copy Markdown
Collaborator

yzh119 commented Aug 21, 2025

Merged into #1528

@yzh119 yzh119 closed this Aug 21, 2025
@cyx-6 cyx-6 deleted the single-source branch February 3, 2026 08:05
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