Skip to content

[Re-land][jit kernel] Support per_token_group_quant_8bit jit kernel#19140

Merged
BBuf merged 5 commits intosgl-project:mainfrom
yuan-luo:jit_per_token_group_quant
Feb 26, 2026
Merged

[Re-land][jit kernel] Support per_token_group_quant_8bit jit kernel#19140
BBuf merged 5 commits intosgl-project:mainfrom
yuan-luo:jit_per_token_group_quant

Conversation

@yuan-luo
Copy link
Copy Markdown
Collaborator

@yuan-luo yuan-luo commented Feb 22, 2026

Motivation

#18905 was reverted due to CI failure, but this CI failure was not introduced by #18905. After confirmed with @hnyls2002 , reland this jit kernel.

Adopted the fix in #19118 and added @mmangkad as co-author.

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @yuan-luo, 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 focuses on re-introducing and integrating a Just-In-Time (JIT) compiled kernel for per-token group 8-bit quantization. The primary goal is to enhance the efficiency of quantization operations by leveraging a dedicated C++/CUDA implementation. This involves adding the kernel's source, creating its Python interface, and ensuring its functional correctness and performance through new testing and benchmarking infrastructure.

Highlights

  • Re-land of JIT Kernel: This pull request re-lands the per_token_group_quant_8bit JIT kernel, which was previously reverted due to an unrelated CI failure. The kernel supports 8-bit quantization for per-token groups.
  • New C++/CUDA Kernel Implementation: A new C++/CUDA kernel (per_token_group_quant_8bit.cuh) has been added, implementing the core logic for per-token group 8-bit quantization, including support for column-major scales and UE8M0 format.
  • Python Wrapper and Integration: A Python wrapper (per_token_group_quant_8bit.py) has been introduced to expose the new JIT kernel to the Python codebase, and the fp8_kernel.py module has been updated to conditionally utilize this JIT kernel.
  • Benchmarking and Testing: New benchmark and unit test files have been added to validate the performance and correctness of the per_token_group_quant_8bit JIT kernel against an existing Triton implementation across various configurations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/jit_kernel/benchmark/bench_per_token_group_quant_8bit.py
    • Added a new benchmark script to compare the performance of the SGLang JIT kernel against a Triton implementation for per-token group 8-bit quantization.
  • python/sglang/jit_kernel/csrc/gemm/per_token_group_quant_8bit.cuh
    • Added a new C++/CUDA kernel for per-token group 8-bit quantization, including logic for handling column-major scales and UE8M0 format.
  • python/sglang/jit_kernel/per_token_group_quant_8bit.py
    • Added a Python wrapper for the new JIT kernel, allowing it to be called from Python with appropriate tensor and parameter handling.
  • python/sglang/jit_kernel/tests/test_per_token_group_quant_8bit.py
    • Added comprehensive unit tests for the new JIT kernel, verifying its correctness against an existing Triton implementation across various configurations.
  • python/sglang/jit_kernel/utils.py
    • Updated the CPP_DTYPE_MAP to include fp8_e4m3_t and int8_t for C++ type mapping.
    • Removed an unnecessary blank line.
  • python/sglang/srt/layers/quantization/fp8_kernel.py
    • Modified the sglang_per_token_group_quant_fp8 function to conditionally use the new JIT kernel (sgl_per_token_group_quant_8bit_jit) when enable_v2 is false, otherwise falling back to the existing sgl_per_token_group_quant_8bit (non-JIT) implementation.
Activity
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
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

The pull request re-lands the JIT kernel for per_token_group_quant_8bit. The implementation is consistent with the repository's JIT infrastructure and provides a fallback path for the pre-compiled extension. I have identified a few issues that need to be addressed: missing support for torch.float8_e4m3fnuz in the JIT utility mapping which will break AMD support, and several hardcoded values in the test script that prevent it from correctly verifying different quantization configurations and dtypes. Additionally, there are minor cleanup and optimization opportunities in the CUDA kernel.

Comment thread python/sglang/jit_kernel/utils.py
Comment thread python/sglang/jit_kernel/tests/test_per_token_group_quant_8bit.py
DST_DTYPE* __restrict__ output_q,
scale_packed_t_t<kScaleUE8M0>* __restrict__ output_s,
const int group_size,
const int num_groups,
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

The num_groups parameter is unused in the kernel (as indicated by the (void)num_groups; on line 50). It should be removed from the signature.

Comment thread python/sglang/jit_kernel/csrc/gemm/per_token_group_quant_8bit.cuh
@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@yuan-luo yuan-luo marked this pull request as draft February 22, 2026 05:01
@yuan-luo yuan-luo force-pushed the jit_per_token_group_quant branch from 73ea775 to 7070576 Compare February 22, 2026 05:05
Co-authored-by: Mohammad Miadh Angkad <mangkad.bsdsba2027@aim.edu>
@yuan-luo yuan-luo marked this pull request as ready for review February 22, 2026 05:27
@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@yuan-luo yuan-luo requested a review from hnyls2002 February 22, 2026 05:38
@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

5 similar comments
@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@yuan-luo
Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@BBuf BBuf merged commit 7c9e8e2 into sgl-project:main Feb 26, 2026
945 of 1032 checks passed
masked_m,
enable_v2=enable_v2,
)
if enable_v2:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Todo: after remove per_token_group_quant_8bit kernels to jit_kernel, we should unify per_token_group_quant_8bit and per_token_group_quant_8bit_v2 to a single file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure. I'll follow up.

klhhhhh pushed a commit to klhhhhh/sglang that referenced this pull request Feb 26, 2026
…gl-project#19140)

Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Co-authored-by: Mohammad Miadh Angkad <mangkad.bsdsba2027@aim.edu>
hnyls2002 pushed a commit that referenced this pull request Mar 9, 2026
magicYang1573 pushed a commit to magicYang1573/sglang that referenced this pull request Mar 9, 2026
…gl-project#19140)

Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Co-authored-by: Mohammad Miadh Angkad <mangkad.bsdsba2027@aim.edu>
@yuan-luo yuan-luo deleted the jit_per_token_group_quant branch March 9, 2026 15:07
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
…gl-project#19140)

Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Co-authored-by: Mohammad Miadh Angkad <mangkad.bsdsba2027@aim.edu>
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
…gl-project#19140)

Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Co-authored-by: Mohammad Miadh Angkad <mangkad.bsdsba2027@aim.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quant LLM Quantization run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants