Skip to content

fix: cuda graph issue while running longcat_flash#14007

Merged
zhyncs merged 8 commits intosgl-project:mainfrom
tianhaoz95:fix/cuda-graph-issue
Nov 26, 2025
Merged

fix: cuda graph issue while running longcat_flash#14007
zhyncs merged 8 commits intosgl-project:mainfrom
tianhaoz95:fix/cuda-graph-issue

Conversation

@tianhaoz95
Copy link
Contributor

Motivation

Currently when we run longcat_flash it will error out with:

[2025-11-25 13:35:50 TP3 EP3] Scheduler hit an exception: Traceback (most recent call last):
  File "/home/zhoutianhao03/projects/sglang/python/sglang/srt/managers/scheduler.py", line 2712, in run_scheduler_process
  ...
  File "/home/zhoutianhao03/projects/sglang/python/sglang/srt/layers/communicator.py", line 187, in fetch_qkv_latent
    assert self.attn_inputs_ is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

this is because in #10568 set_attn_inputs() is skipped when qkv_latent_func == None, and later fetch_qkv_latent() will assert on this and fail.

Modifications

Make sure qkv_latent_func is set.

Accuracy Tests

After the change the following launch command runs and output normal tokens:

python3 -m sglang.launch_server \
    --trust-remote-code \
    --model $MODEL_PATH \
    --tp 8 \
    --ep-size 8 \
    --skip-server-warmup \
    --cuda-graph-bs 1 2 3 4 5 6 7 8 \
    --host 0.0.0.0 \
    --port 8080

gsm8k:

Accuracy: 0.950
Invalid: 0.000
Latency: 31.601 s
Output throughput: 386.859 token/s

Benchmarking and Profiling

gsm8k:

Accuracy: 0.950
Invalid: 0.000
Latency: 31.601 s
Output throughput: 386.859 token/s

same as when i revert to before it was broken:

Accuracy: 0.950
Invalid: 0.000
Latency: 34.700 s
Output throughput: 354.785 token/s

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tianhaoz95, 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 longcat_flash model that caused an AssertionError during execution due to an uninitialized QKV latent function. By ensuring qkv_latent_func is correctly passed during block initialization, the PR restores proper functionality to longcat_flash while validating that performance metrics remain consistent or show minor improvements.

Highlights

  • Bug Fix for longcat_flash: Resolves an AssertionError that occurred when running longcat_flash due to qkv_latent_func being None, which prevented fetch_qkv_latent() from executing correctly.
  • qkv_latent_func Initialization: Ensures that the qkv_latent_func parameter is properly set during the initialization of Block instances within the longcat_flash model, specifically for both standard and Mixture-of-Experts (MoE) blocks.
  • Performance Validation: Confirms that the fix allows longcat_flash to run successfully and maintains or slightly improves accuracy and throughput metrics, as validated by gsm8k benchmarks.
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 correctly fixes a CUDA graph issue in longcat_flash by ensuring the qkv_latent_func is passed during the initialization of LayerCommunicator. This prevents an AssertionError that occurred because attention inputs were not being set. The fix is straightforward, consistent with its usage in other models, and is well-supported by the provided test results. The changes look good to me.

@Kangyan-Zhou
Copy link
Collaborator

/tag-and-rerun-ci

@zhyncs zhyncs merged commit 685b9d8 into sgl-project:main Nov 26, 2025
127 of 143 checks passed
harvenstar pushed a commit to harvenstar/sglang that referenced this pull request Dec 4, 2025
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