Skip to content

Cortex-M: fix quantized_linear bias on non-MVE targets#20045

Closed
rascani wants to merge 2 commits into
pytorch:mainfrom
rascani:cortex-m-fix-linear-bias-non-mve
Closed

Cortex-M: fix quantized_linear bias on non-MVE targets#20045
rascani wants to merge 2 commits into
pytorch:mainfrom
rascani:cortex-m-fix-linear-bias-non-mve

Conversation

@rascani

@rascani rascani commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

The AOT linear lowering folded the bias into the precomputed kernel_sum and passed None as the kernel's bias argument. The CMSIS-NN fully-connected kernel only reads kernel_sum on the MVE path; the DSP and scalar paths ignore kernel_sum and read the bias argument directly, so on those targets the bias was silently dropped and biased linears produced incorrect results.

Pass the int32 bias node through to the kernel in addition to folding it into kernel_sum. On any given build only one ISA path executes, so the bias is applied exactly once: MVE via kernel_sum, DSP/scalar via the bias argument.

Test Plan

Verified on the Corstone-300 FVP for cortex-m0plus.

Authored with Claude Code.

The AOT linear lowering folded the bias into the precomputed kernel_sum
and passed None as the kernel's bias argument. The CMSIS-NN
fully-connected kernel only reads kernel_sum on the MVE path; the DSP and
scalar paths ignore kernel_sum and read the bias argument directly, so on
those targets the bias was silently dropped and biased linears produced
incorrect results.

Pass the int32 bias node through to the kernel in addition to folding it
into kernel_sum. On any given build only one ISA path executes, so the
bias is applied exactly once: MVE via kernel_sum, DSP/scalar via the bias
argument. Verified on the Corstone-300 FVP for cortex-m0plus.

Authored with Claude Code.
@pytorch-bot

pytorch-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20045

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures

As of commit 6030050 with merge base 4c9c444 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 4, 2026
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@AdrianLundell AdrianLundell 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.

I would suggest that we set kernel_sum to None when bias is used and vice versa to not waste memory, what do you say?

@rascani

rascani commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

I would suggest that we set kernel_sum to None when bias is used and vice versa to not waste memory, what do you say?

Yes, absolutely. So much so I already did it in #19676 2 weeks ago. I'll close this one in favor of that one. 🙃

@rascani rascani closed this Jun 5, 2026
@rascani
rascani deleted the cortex-m-fix-linear-bias-non-mve branch June 23, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants