Skip to content

[NPU] bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops#13980

Merged
iforgetmyname merged 6 commits intosgl-project:mainfrom
ZhengdQin:dsv3_bug_fix
Dec 3, 2025
Merged

[NPU] bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops#13980
iforgetmyname merged 6 commits intosgl-project:mainfrom
ZhengdQin:dsv3_bug_fix

Conversation

@ZhengdQin
Copy link
Copy Markdown
Collaborator

@ZhengdQin ZhengdQin commented Nov 26, 2025

NPU batch_matmul_transpose ops need w_vc to be contiguous.

Motivation

Bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops

Modifications

Accuracy Tests

Before fix bug:
image
After fix bug:
image

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ZhengdQin, 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 resolves a bug where the w_vc tensor was not consistently contiguous, which is a critical requirement for NPU batch_matmul_transpose operations. The change introduces a conditional check to ensure w_vc is contiguous specifically when an NPU is detected, thereby enhancing compatibility and stability for NPU-accelerated computations.

Highlights

  • NPU Compatibility Fix: Ensured that the w_vc tensor is explicitly made contiguous when operating within an NPU (Neural Processing Unit) environment. This addresses a specific requirement for NPU batch_matmul_transpose operations, preventing potential errors or performance issues.
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.

@ZhengdQin ZhengdQin changed the title bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops [Ascend] bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops Nov 26, 2025
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 addresses a bug where w_vc needs to be contiguous for NPU batch_matmul_transpose operations. The change correctly adds a .contiguous() call for NPU devices. I've suggested a small refactoring to improve efficiency for the NPU case by avoiding an intermediate tensor copy, while keeping the logic for other backends unchanged.

Comment thread python/sglang/srt/models/deepseek_v2.py
@iforgetmyname
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci label Dec 2, 2025
@iforgetmyname iforgetmyname self-assigned this Dec 2, 2025
@ping1jing2 ping1jing2 self-assigned this Dec 2, 2025
@ping1jing2
Copy link
Copy Markdown
Collaborator

pls add your comparison between the bug before and after this modifcations

@iforgetmyname iforgetmyname changed the title [Ascend] bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops [NPU] bug fix: w_vc need contiguous for NPU batch_matmul_transpose ops Dec 3, 2025
@iforgetmyname iforgetmyname merged commit d122e32 into sgl-project:main Dec 3, 2025
112 of 138 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants