[NPU] bugfix for import sgl-kernel error#21200
[NPU] bugfix for import sgl-kernel error#21200sglang-npu-bot merged 2 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello, 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 that prevented NPU models from functioning correctly. The fix involves modifying an import statement to ensure that a specific kernel module is only loaded when not running on an NPU, thereby preventing import errors that previously caused system failures. Highlights
🧠 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 AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a bug where importing an sglang kernel caused failures on NPU devices. The fix involves making the import of transfer_kv_all_layer_mla conditional, so it only occurs on non-NPU platforms. While this correctly handles the import issue, it introduces a risk of a NameError if the function is called on an NPU. I've suggested a change to define a placeholder function for the NPU case, which will provide a more explicit NotImplementedError and make the code more robust against accidental usage.
| if not is_npu(): | ||
| from sgl_kernel.kvcacheio import transfer_kv_all_layer_mla |
There was a problem hiding this comment.
This change makes the import of transfer_kv_all_layer_mla conditional. While this fixes the import error on NPU devices, it leaves transfer_kv_all_layer_mla undefined when running on an NPU. If any code in this file calls this function without a corresponding if not is_npu(): guard, it will raise a NameError at runtime.
To make the code more robust and provide a clearer error, I suggest defining a placeholder function for the NPU case. This will ensure the name is always defined and will raise a NotImplementedError if it's ever called on an NPU, making debugging easier.
if not is_npu():
from sgl_kernel.kvcacheio import transfer_kv_all_layer_mla
else:
def transfer_kv_all_layer_mla(*args, **kwargs):
raise NotImplementedError("transfer_kv_all_layer_mla is not supported on NPU")|
/tag-and-rerun-ci |
|
/tag-and-rerun-ci |
|
/tag-and-rerun-ci |
Motivation
previously, due to the incorrect import of sglang kernel, all model cases of NPU failed.


after:
Modifications
as follows
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci