Skip to content

Add FuseQATConvBN to fuse_ops (#19442)#19442

Open
ethansfng wants to merge 1 commit intopytorch:mainfrom
ethansfng:export-D104497938
Open

Add FuseQATConvBN to fuse_ops (#19442)#19442
ethansfng wants to merge 1 commit intopytorch:mainfrom
ethansfng:export-D104497938

Conversation

@ethansfng
Copy link
Copy Markdown
Contributor

@ethansfng ethansfng commented May 10, 2026

Summary:

Adds a FuseQATConvBN which folds the QAT Conv-BN simulation chain (conv → q → dq → div(scale) → add(orig_bias) → batch_norm) inserted by prepare_qat_pt2e into the conv's quantized bias and removes the chain.

The pass runs in two steps inside a single call():

  1. Bias prep — for each conv, create a zero-filled quantized bias if missing, or quantize a float bias as per-tensor int32. Required so step 2 has a quantized bias slot to write the BN correction into.
  2. Fold — for each matched chain, compute the BN correction
    C = (orig_bias - running_mean) * bn_weight / sqrt(running_var + eps) + bn_bias
    and absorb it into the conv's quantized bias in place. Erase the chain + batch_norm.

Differential Revision: D104497938

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 10, 2026

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 84d7498 with merge base a49171d (image):

NEW FAILURE - The following job has failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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 May 10, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 10, 2026

@ethansfng has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104497938.

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

Summary:

Adds a FuseQATConvBN which folds the QAT Conv-BN simulation chain (`conv → q → dq → div(scale) → add(orig_bias) → batch_norm`) inserted by `prepare_qat_pt2e` into the conv's quantized bias and removes the chain.

The pass runs in two steps inside a single `call()`:
  1. Bias prep — for each conv, create a zero-filled quantized bias if missing, or quantize a float bias as per-tensor int32. Required so step 2 has a quantized bias slot to write the BN correction into.
  2. Fold — for each matched chain, compute the BN correction
       C = (orig_bias - running_mean) * bn_weight / sqrt(running_var + eps) + bn_bias
     and absorb it into the conv's quantized bias in place. Erase the chain + batch_norm.

Differential Revision: D104497938
@meta-codesync meta-codesync Bot changed the title Add FuseQATConvBN to fuse_ops Add FuseQATConvBN to fuse_ops (#19442) May 10, 2026
@ethansfng ethansfng force-pushed the export-D104497938 branch from d5c07d4 to 84d7498 Compare May 10, 2026 05:15
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. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant