Skip to content

Fix sgl-kernel per_token_quant fp8 kernel scale shared_memory bug#16886

Merged
Fridge003 merged 6 commits intomainfrom
fix_sgl_kernel_per_token_quant_fp8
Jan 13, 2026
Merged

Fix sgl-kernel per_token_quant fp8 kernel scale shared_memory bug#16886
Fridge003 merged 6 commits intomainfrom
fix_sgl_kernel_per_token_quant_fp8

Conversation

@BBuf
Copy link
Copy Markdown
Collaborator

@BBuf BBuf commented Jan 11, 2026

Motivation

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 @BBuf, 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 critical bug in the FP8 quantization kernel by correcting the scope of the scale variable. This ensures proper per-warp/per-token scaling, which is essential for accurate FP8 quantization, and enhances code quality by using const for immutable variables.

Highlights

  • FP8 Quantization Kernel Fix: The scale variable within the per_token_quant_fp8_kernel was incorrectly declared as __shared__. This has been corrected to a const float (register variable) to ensure it is per-warp/per-thread, which is crucial as a single shared variable would be erroneous when a CTA handles multiple warps/tokens.
  • Variable Declaration Improvement: The scale_inv variable was also updated to be const, reflecting its immutable nature after initialization and improving code correctness.

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

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

This pull request fixes a critical race condition in the per_token_quant_fp8_kernel. In this kernel, each warp processes a separate token, but the scale variable was declared in __shared__ memory, causing warps within the same block to overwrite each other's data. The change correctly scopes scale to be a register variable, ensuring each warp works with its own data. This resolves the correctness issue. The change also makes scale and scale_inv const, which is a good practice for read-only variables.

@BBuf BBuf changed the title Fix sgl-kernel per_token_quant fp8 kernel Fix sgl-kernel per_token_quant fp8 kernel bug Jan 11, 2026
@BBuf BBuf changed the title Fix sgl-kernel per_token_quant fp8 kernel bug Fix sgl-kernel per_token_quant fp8 kernel scale shared_memory bug Jan 11, 2026
@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 11, 2026

/tag-and-rerun-ci

@BBuf BBuf added the run-ci label Jan 11, 2026
@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 11, 2026

@yuan-luo It's bug caused by #8130 , please have a simple review.

@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 11, 2026

/rerun-failed-ci

1 similar comment
@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 12, 2026

/rerun-failed-ci

@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 12, 2026

/rerun-failed-ci

@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Jan 12, 2026
@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 12, 2026

/rerun-failed-ci

2 similar comments
@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 12, 2026

/rerun-failed-ci

@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 12, 2026

/rerun-failed-ci

@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 13, 2026

/tag-and-rerun-ci

@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Jan 13, 2026

/rerun-failed-ci

1 similar comment
@Fridge003
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@Fridge003
Copy link
Copy Markdown
Collaborator

Fridge003 commented Jan 13, 2026

Let's merge this PR: https://github.com/sgl-project/sglang/actions/runs/20940583427/job/60239535266?pr=16886

unit-test-backend-4-gpu(0) is flaky and possibly caused by broken weights on disk. We are tracking it

@Fridge003 Fridge003 merged commit 2ab3ed3 into main Jan 13, 2026
13 of 16 checks passed
@Fridge003 Fridge003 deleted the fix_sgl_kernel_per_token_quant_fp8 branch January 13, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file high priority quant LLM Quantization run-ci sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants