Skip to content

[diffusion] [NPU] support ring attention on NPU with FIA attention backend#20248

Closed
Makcum888e wants to merge 13 commits intosgl-project:mainfrom
Makcum888e:fia_attention_backend
Closed

[diffusion] [NPU] support ring attention on NPU with FIA attention backend#20248
Makcum888e wants to merge 13 commits intosgl-project:mainfrom
Makcum888e:fia_attention_backend

Conversation

@Makcum888e
Copy link
Copy Markdown
Contributor

@Makcum888e Makcum888e commented Mar 10, 2026

Motivation

ring attention requires return_softmax_lse but sdpa backend cannot support this option. Support of ring attention on NPU can be implemented using npu_fused_infer_attention_score.

Modifications

added new attention backend for NPU - FIA
added new function to platform interface default_ring_attention_backend to allow the platform to select the default backend

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly enhances the SGLang framework by enabling ring attention functionality on NPU devices. It achieves this by introducing a dedicated Fused Infer Attention (FIA) backend, which is crucial for handling the specific requirements of ring attention that existing backends like SDPA could not meet. The changes also include updates across various model configurations and the platform interface to seamlessly integrate and utilize this new NPU-optimized attention mechanism, ensuring better performance and compatibility for NPU-based diffusion models.

Highlights

  • NPU Ring Attention Support: Enabled support for ring attention on NPU (Neural Processing Unit) devices by integrating a new Fused Infer Attention (FIA) backend.
  • New FIA Attention Backend: Introduced a new attention backend, FIA (Fused Infer Attention), specifically designed for NPU, which supports the return_softmax_lse required for ring attention.
  • Platform Interface Enhancement: Added a new method default_ring_attention_backend to the platform interface, allowing platforms to specify their preferred default attention backend for ring attention.

🧠 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.

Changelog
  • python/sglang/multimodal_gen/configs/models/adapter/base.py
    • Added FIA to the list of supported attention backends.
  • python/sglang/multimodal_gen/configs/models/dits/base.py
    • Added FIA to the list of supported attention backends.
  • python/sglang/multimodal_gen/configs/models/encoders/base.py
    • Added FIA to the list of supported attention backends.
  • python/sglang/multimodal_gen/runtime/layers/attention/backends/fia.py
    • Added a new file defining the FIABackend and FIAImpl classes for NPU fused infer attention.
  • python/sglang/multimodal_gen/runtime/models/adapter/ltx_2_connector.py
    • Added FIA to the set of supported attention backends.
  • python/sglang/multimodal_gen/runtime/models/dits/causal_wanvideo.py
    • Added FIA to the set of supported attention backends.
  • python/sglang/multimodal_gen/runtime/models/dits/hunyuan3d.py
    • Added FIA to the set of supported attention backends in multiple LocalAttention initializations.
    • Included FIA in the _SUPPORTED_BACKENDS for SGLangAttentionWrapper.
  • python/sglang/multimodal_gen/runtime/models/dits/hunyuanvideo.py
    • Added FIA to the set of supported attention backends.
  • python/sglang/multimodal_gen/runtime/models/dits/qwen_image.py
    • Added FIA to the set of supported attention backends.
  • python/sglang/multimodal_gen/runtime/models/encoders/mistral_3.py
    • Added FIA to the set of supported attention backends.
  • python/sglang/multimodal_gen/runtime/models/encoders/qwen2_5vl.py
    • Added FIA to the set of supported attention backends.
  • python/sglang/multimodal_gen/runtime/platforms/interface.py
    • Added AttentionBackendEnum.FIA to the enum definition.
    • Introduced default_ring_attention_backend class method to specify the default backend for ring attention.
  • python/sglang/multimodal_gen/runtime/platforms/npu.py
    • Modified get_attn_backend_cls_str to return FIABackend when AttentionBackendEnum.FIA is selected.
    • Implemented default_ring_attention_backend to return "fia" as the default for NPU.
  • python/sglang/multimodal_gen/runtime/server_args.py
    • Updated _adjust_attention_backend to recognize "fia" as a supported backend for ring attention.
    • Modified the default ring attention backend selection to use current_platform.default_ring_attention_backend().
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
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 the FIA (Fused Infer Attention) backend to enable ring attention on NPU devices. The changes include adding the new FIA attention backend, implementing its logic as a wrapper around an NPU-specific operator, and integrating it into the platform interface and model configurations.

The implementation is mostly straightforward. However, I've identified a few issues that should be addressed:

  • A potential None value being passed for num_kv_heads in the new FIAImpl, which could lead to runtime errors.
  • Incorrect return type hints for the new default_ring_attention_backend method in both the platform interface and the NPU implementation.

I've provided specific comments and suggestions for these points. Once these are addressed, the changes look good.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 10, 2026
Makcum888e and others added 3 commits March 10, 2026 10:28
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ping1jing2
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@ping1jing2
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@ping1jing2
Copy link
Copy Markdown
Collaborator

duplicate #21383

@ping1jing2 ping1jing2 closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion documentation Improvements or additions to documentation npu run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants