Skip to content

feat: bugfix and accuracy fix for stablelm2_1_6b#15932

Merged
iforgetmyname merged 1 commit intosgl-project:ifmn/eagle-dp-attnfrom
McZyWu:ifmn/eagle-dp-attn
Dec 28, 2025
Merged

feat: bugfix and accuracy fix for stablelm2_1_6b#15932
iforgetmyname merged 1 commit intosgl-project:ifmn/eagle-dp-attnfrom
McZyWu:ifmn/eagle-dp-attn

Conversation

@McZyWu
Copy link
Copy Markdown
Contributor

@McZyWu McZyWu commented Dec 27, 2025

Motivation

accuracy fix for stablelm-2-1-6b for npu, previously it was 0.0

Modifications

as follows

Accuracy Tests

0.2

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @McZyWu, 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 introduces a critical bugfix and accuracy improvement for the stablelm-2-1-6b model, specifically addressing its performance on NPU. The core change involves an adjustment to the rotary embedding logic, enabling a more robust and accurate computation path, particularly when torch.compile is utilized. This modification directly resolves a previous state of zero accuracy, bringing it to a measurable 0.2.

Highlights

  • Rotary Embedding Logic Update: Modified the forward_npu function in rotary_embedding.py to extend the conditions under which self.forward_native is called. The forward_native method will now also be invoked if the SGLANG_ENABLE_TORCH_COMPILE environment variable is set to true, in addition to the existing bfloat16 and float dtype conditions.
  • Accuracy Improvement for stablelm-2-1-6b on NPU: This change specifically targets and resolves an accuracy issue for the stablelm-2-1-6b model when running on NPU, improving its reported accuracy from 0.0 to 0.2.

🧠 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 introduces a fix for an accuracy issue with stablelm-2-1-6b on NPU devices. The change modifies the forward_npu method in RotaryEmbedding to fall back to the native PyTorch implementation when SGLANG_ENABLE_TORCH_COMPILE is enabled. This seems to be a necessary workaround for issues with the NPU-specific kernel when using torch.compile. The change is logical, but I have a suggestion to improve code readability.

Comment on lines +298 to 299
if (query.dtype == torch.bfloat16 and self.cos_sin_cache.dtype == torch.float) or get_bool_env_var("SGLANG_ENABLE_TORCH_COMPILE"):
return self.forward_native(positions, query, key, offsets)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and maintainability, it's good practice to extract complex conditions into descriptive boolean variables. This makes the logic clearer at a glance.

Suggested change
if (query.dtype == torch.bfloat16 and self.cos_sin_cache.dtype == torch.float) or get_bool_env_var("SGLANG_ENABLE_TORCH_COMPILE"):
return self.forward_native(positions, query, key, offsets)
is_unsupported_dtype = query.dtype == torch.bfloat16 and self.cos_sin_cache.dtype == torch.float
is_torch_compile_enabled = get_bool_env_var("SGLANG_ENABLE_TORCH_COMPILE")
if is_unsupported_dtype or is_torch_compile_enabled:
return self.forward_native(positions, query, key, offsets)

@iforgetmyname iforgetmyname merged commit 5abd4ae into sgl-project:ifmn/eagle-dp-attn Dec 28, 2025
1 check passed
Liwansi added a commit to iforgetmyname/sglang that referenced this pull request Dec 29, 2025
…glang into eagle-sche

* 'ifmn/eagle-dp-attn' of https://github.com/sgl-project/sglang: (22 commits)
  dp scheduler enhance support with chunked prefill (sgl-project#16071)
  modify suffix decoding
  CI dependency update (sgl-project#16063)
  fix rotary_embedding init npu (sgl-project#16011)
  feat: bugfix and accuracy fix for stablelm2_1_6b (sgl-project#15932)
  Update model and feature support for Ascend NPU (sgl-project#16005)
  Bugfix for Llama4 (sgl-project#15929)
  Bugfix for ds-vl2 (sgl-project#15894)
  gme qwen vl runners fix (sgl-project#15899)
  add profiling in scheduler (sgl-project#15876)
  llama use triton rope op (sgl-project#15855)
  suffix decoding adapt npu
  suffix decoding adapt npu
  Add suffix decoding speculative algorithm from feature 13553
  cherry sgl-project#15434: qwen3 vl performance update
  cherry sgl-project#15597: fix Qwen3-VL-30B-A3B-Instruct accuracy loss
  [Schedule] bug fix for schedule enhancer (sgl-project#15834)
  minilb support roundrobin (sgl-project#15824)
  fix torchair compile issue
  cherry sgl-project#15187: lora fix
  ...

# Conflicts:
#	python/sglang/srt/managers/scheduler.py
#	python/sglang/srt/managers/scheduler_enhancer.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants