Skip to content

feat: enable SwiGluQuant fusion for Qwen3 MLP #1847

Open
nie-linfeng wants to merge 1 commit into
xLLM-AI:mainfrom
nie-linfeng:feat/enable-swiglu-quant-all-paths
Open

feat: enable SwiGluQuant fusion for Qwen3 MLP #1847
nie-linfeng wants to merge 1 commit into
xLLM-AI:mainfrom
nie-linfeng:feat/enable-swiglu-quant-all-paths

Conversation

@nie-linfeng

@nie-linfeng nie-linfeng commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

Enable the DequantSwigluQuant fused ACLNN operator for Qwen3 decoder MLP across prefill and decode paths. This fuses SwiGLU activation and quantization into a single kernel, eliminating intermediate BF16 tensor round-trips between SwiGluForwardKernel and ElewiseQuant.

Performance benefits

Single operator profit of about 3us, whole network quantification of 30 layers-down proj profit of about 0.1ms

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the Qwen3 decoder loader to cast the projection offset and scale tensors to float32, and enables SwiGLU quantization in the NPU decoder layer implementation. The reviewer noted a risk of an uninitialized member variable where enableSwigluQuant is not explicitly set to false when quantization is disabled, which could lead to undefined behavior, and suggested initializing it to false by default.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

static_cast<int>(LinearTypeV2::W8A8);
p.linearQuantType[atb_speed::common::DOWN_LINEAR_INDEX] =
static_cast<int>(LinearType::INT);
p.enableSwigluQuant = true;

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.

high

Uninitialized Member Variable Risk

In C++, external library structs like atb_speed::qwen::QwenLayerParam may not default-initialize all of their member variables (such as enableSwigluQuant) to false in their default constructors.

If quantize_type_ is not "w8a8", or if down_proj_quantized() is false, enableSwigluQuant is never explicitly set to false in init_layer(). This can leave the field with garbage/random memory values, potentially enabling the SwiGluQuant fusion unexpectedly and causing runtime crashes or incorrect outputs.

To prevent this undefined behavior, please explicitly initialize enableSwigluQuant to false in param_from_args (or initialize_quantization_parameters):

void NpuQwen3DecoderLayerImpl::param_from_args(
    atb_speed::qwen::QwenLayerParam& param,
    const ModelArgs& args,
    const ParallelArgs& parallel_args,
    bool isPrefill) {
  // ... existing initializations ...
  param.enableSwigluQuant = false;
  // ...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@nie-linfeng nie-linfeng changed the title feat: enable SwiGluQuant fusion for Qwen3 MLP on NPU feat: enable SwiGluQuant fusion for Qwen3 MLP Jun 29, 2026
@nie-linfeng nie-linfeng force-pushed the feat/enable-swiglu-quant-all-paths branch from 71f02d1 to 6e38598 Compare June 29, 2026 08:58

@xiao-yu-chen xiao-yu-chen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please attach test performance benefits.

Enable SwiGluQuant fusion for Qwen3 MLP on NPU:
- Fix down_proj offset/scale dtype to Float32 for quantization
- Enable SwiGluQuant for W8A8 quantize type in Qwen3 decoder
@nie-linfeng nie-linfeng force-pushed the feat/enable-swiglu-quant-all-paths branch from d5b786a to 5ef2391 Compare June 30, 2026 09:15
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