Skip to content

MatmulNBits prepacking scales fix - #27412

Merged
hariharans29 merged 11 commits into
mainfrom
hari/scales_prepack
Feb 24, 2026
Merged

MatmulNBits prepacking scales fix#27412
hariharans29 merged 11 commits into
mainfrom
hari/scales_prepack

Conversation

@hariharans29

Copy link
Copy Markdown
Member

Description

Fix incorrect scales element count while pre-packing scales while we processing the B input in the Prepack() method of MatmulNBits operator

Motivation and Context

Fix potential crash due to incorrect element count

Copilot AI 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.

Pull request overview

This PR fixes a critical bug in the MatMulNBits operator's PrePack method for the MLFloat16 specialization. The bug occurs when prepacking the B input tensor (weights) and scales need to be converted from MLFloat16 to float32. The code was incorrectly using the B tensor's size instead of the scales tensor's size for buffer allocation and conversion, which could lead to buffer overruns or underruns depending on the relative sizes of B and scales tensors.

Changes:

  • Fixed incorrect size calculation when prepacking scales for MLFloat16 MatMulNBits operator
  • Changed from using B tensor size to scales tensor size for scales conversion buffer allocation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

guschmue
guschmue previously approved these changes Feb 23, 2026
tianleiwu
tianleiwu previously approved these changes Feb 23, 2026
@hariharans29
hariharans29 dismissed stale reviews from tianleiwu and guschmue via 9d40b7d February 23, 2026 18:42
guschmue
guschmue previously approved these changes Feb 23, 2026
tianleiwu
tianleiwu previously approved these changes Feb 23, 2026

@github-actions github-actions 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.

You can commit the suggested changes from lintrunner.

Comment thread onnxruntime/test/contrib_ops/matmul_4bits_test.cc

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

hariharans29 and others added 5 commits February 23, 2026 11:43
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

4 participants