Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ int64_t GetEffectiveBlockSize(const Node& dq_node, int64_t block_size_for_non_bl
const auto& dq_attrs = dq_node.GetAttributes();
const auto bs_iter = dq_attrs.find("block_size");
if (bs_iter != dq_attrs.end() && bs_iter->second.i() > 0) {
return bs_iter->second.i();
// Mirror the kMaxBlockSize guard from ComputeEffectiveBlockSize. Without this cap, a
// model-supplied block_size >= 2^32 truncates to 0 in the MLAS int32 transpose argument,
// causing a divide-by-zero at CreateSession. The selector rejects such models, but guard
// here too so any future selector bypass cannot reach MLAS with an unsafe value.
constexpr int64_t kMaxBlockSize = 256;
Comment thread
apsonawane marked this conversation as resolved.
Resolved
const int64_t block_size = bs_iter->second.i();
return (block_size <= kMaxBlockSize) ? block_size : kMaxBlockSize;
Comment thread
apsonawane marked this conversation as resolved.
Resolved
}

// Derive K from the weight input shape if available. Shape information may be missing even
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ static bool ValidateDQForMatMulNBits(const Graph& graph, const Node& dq_node) {
}

auto block_size = block_size_iter->second.i();
if (block_size < 16 || ((block_size - 1) & block_size)) {
// Must be a power-of-two in [16, 256]. Values beyond 256 would overflow int32 in the
// MLAS transpose kernel (static_cast<int>(block_size) == 0 for block_size >= 2^32),
// causing a divide-by-zero (SIGFPE) at CreateSession time.
Comment thread
apsonawane marked this conversation as resolved.
Resolved
if (block_size < 16 || block_size > 256 || ((block_size - 1) & block_size)) {
Comment thread
apsonawane marked this conversation as resolved.
Resolved
return false;
Comment thread
apsonawane marked this conversation as resolved.
Resolved
}

Expand Down
Loading