feat: enable SwiGluQuant fusion for Qwen3 MLP #1847
Conversation
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
// ...
}71f02d1 to
6e38598
Compare
xiao-yu-chen
left a comment
There was a problem hiding this comment.
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
d5b786a to
5ef2391
Compare
Description
Enable the
DequantSwigluQuantfused 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 betweenSwiGluForwardKernelandElewiseQuant.Performance benefits
Single operator profit of about 3us, whole network quantification of 30 layers-down proj profit of about 0.1ms