Skip to content

Revert "Add fused FP8 KV cache write kernel for TRTLLM MHA backend"#14550

Closed
Qiaolin-Yu wants to merge 1 commit intomainfrom
revert-14093-fix-mha-fp8-kv-cache
Closed

Revert "Add fused FP8 KV cache write kernel for TRTLLM MHA backend"#14550
Qiaolin-Yu wants to merge 1 commit intomainfrom
revert-14093-fix-mha-fp8-kv-cache

Conversation

@Qiaolin-Yu
Copy link
Collaborator

Reverts #14093 because it breaks b200 ci

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Qiaolin-Yu, 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 completely rolls back a recent feature that aimed to optimize FP8 KV cache writes using a fused kernel for the TRTLLM MHA backend. The decision to revert was prompted by persistent failures observed in the B200 continuous integration environment. By removing the problematic code and restoring the system to its prior state, this change ensures stability and resolves the CI pipeline issues.

Highlights

  • Revert of Fused FP8 KV Cache Kernel: The pull request fully reverts the previous addition of a fused FP8 KV cache write kernel designed for the TRTLLM MHA backend.
  • CI Failure Resolution: This revert addresses a critical issue where the previously introduced fused FP8 kernel was causing continuous integration (CI) failures on B200 hardware.
  • Codebase Cleanup: All associated code, including the dedicated kernel implementation file (trtllm_fp8_kv_kernel.py), its integration logic within trtllm_mha_backend.py, and its unit tests, has been removed.
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.

@Qiaolin-Yu
Copy link
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions bot added the run-ci label Dec 6, 2025
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 reverts the addition of a fused FP8 KV cache write kernel for the TRTLLM MHA backend, which was reportedly causing CI failures on b200 systems. The revert has been executed correctly: the kernel implementation and its corresponding tests have been removed, and the TRTLLM MHA backend has been updated to remove all usage of the fused kernel, falling back to the previous implementation. Additionally, some minor refactoring and cleanup have been applied to python/sglang/srt/models/qwen3_moe.py, which improves code readability. The changes appear correct and complete for the stated purpose of the revert.

@harvenstar
Copy link
Collaborator

@Qiaolin-Yu Thanks for reverting. I reproduced the B200 Triton error locally with a minimal script, root cause is k_scale / v_scale being 0D tensors seen as pointer in the FP8 KV kernel.

A fix is already in progress. I am preparing a follow up PR with a corrected and
type-safe version of the fused kernel that passes the LLaMA-3.1 FP4 B200 test.

harvenstar added a commit to harvenstar/sglang that referenced this pull request Dec 6, 2025
Fix B200 CI failure that caused sgl-project#14093 to be reverted in sgl-project#14550.

Original issue discovered in CI run:
https://github.com/sgl-project/sglang/actions/runs/19985523381/job/57335123826?pr=14493

Root cause:
- layer.k_scale/v_scale are torch.nn.Parameter (0-D tensors)
- Triton interprets tensor arguments as pointers
- Expression '1.0 / k_scale' in kernel caused IncompatibleTypeError

Solution:
- Convert tensor scales to Python float in wrapper before kernel launch
- Handles None, Tensor, and scalar cases explicitly
- Preserves per-tensor scaling semantics

Testing:
- Added regression test test_fp8_kv_kernel_accepts_tensor_scales
- Verified on local environment with ATTN_BACKEND=trtllm_mha
- All 11 kernel tests pass, including new regression test
- test_llama31_fp4.py::TestLlama31FP4B200::test_gsm8k passes
harvenstar added a commit to harvenstar/sglang that referenced this pull request Dec 6, 2025
Fix B200 CI failure that caused sgl-project#14093 to be reverted in sgl-project#14550.

Original issue discovered in CI run:
https://github.com/sgl-project/sglang/actions/runs/19985523381/job/57335123826?pr=14493

Root cause:
- layer.k_scale/v_scale are torch.nn.Parameter (0-D tensors)
- Triton interprets tensor arguments as pointers
- Expression '1.0 / k_scale' in kernel caused IncompatibleTypeError

Solution:
- Convert tensor scales to Python float in wrapper before kernel launch
- Handles None, Tensor, and scalar cases explicitly
- Preserves per-tensor scaling semantics

Testing:
- Added regression test test_fp8_kv_kernel_accepts_tensor_scales
- Verified on local environment with ATTN_BACKEND=trtllm_mha
- All 11 kernel tests pass, including new regression test
- test_llama31_fp4.py::TestLlama31FP4B200::test_gsm8k passes
@Fridge003 Fridge003 closed this Dec 6, 2025
@zhyncs zhyncs deleted the revert-14093-fix-mha-fp8-kv-cache branch December 10, 2025 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants