Add ORT_ENFORCE for swiglu_fusion==1 in QMoECPU to prevent out-of-bounds read#27748
Merged
Add ORT_ENFORCE for swiglu_fusion==1 in QMoECPU to prevent out-of-bounds read#27748
Conversation
…t out-of-bounds read Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
tianleiwu
March 18, 2026 20:50
View session
tianleiwu
approved these changes
Mar 18, 2026
apsonawane
approved these changes
Mar 18, 2026
This was referenced Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add an
ORT_ENFORCEcheck in theQMoECPUconstructor to requireswiglu_fusion == 1when using SwiGLU activation, preventing an out-of-bounds read.When
swiglu_fusion=0(the default),fc1_out_featuresis computed asinter_sizeinstead of2*inter_size. However,ApplySwiGLUActivationreads2*inter_sizevalues from the FC1 output buffer (viainput_data[2*i]foriin[0, inter_size)), causing an out-of-bounds read that produces NaN on Windows x86.This matches the existing validation already present in the
MoECPU operator (moe_cpu.cc:26-27).Motivation and Context
swiglu_fusion=1attribute. With the defaultswiglu_fusion=0, the SwiGLU activation reads past the allocated FC1 output buffer — an out-of-bounds read.MoECPU operator already enforcesswiglu_fusion == 1for SwiGLU; this change adds the same guard toQMoECPUfor consistency and safety.swiglu_fusion=2) is not implemented (throwsORT_NOT_IMPLEMENTED), andswiglu_fusion=0is invalid for SwiGLU, so onlyswiglu_fusion=1is valid.