Skip to content

Add FuseQATConvBN to fuse_ops (#19442)#19442

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
ethansfng:export-D104497938
May 13, 2026
Merged

Add FuseQATConvBN to fuse_ops (#19442)#19442
meta-codesync[bot] merged 1 commit into
pytorch: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.

Reviewed By: DrJessop

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 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 5 Unrelated Failures

As of commit ee9d4df with merge base fe98297 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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.

@meta-codesync meta-codesync Bot changed the title Add FuseQATConvBN to fuse_ops Add FuseQATConvBN to fuse_ops (#19442) May 10, 2026
ethansfng added a commit to ethansfng/executorch that referenced this pull request 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
@ethansfng ethansfng force-pushed the export-D104497938 branch from d5c07d4 to 84d7498 Compare May 10, 2026 05:15
ethansfng added a commit to ethansfng/executorch that referenced this pull request 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
@ethansfng ethansfng force-pushed the export-D104497938 branch from 84d7498 to 472a5cd Compare May 10, 2026 18:49
ethansfng added a commit to ethansfng/executorch that referenced this pull request 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
@ethansfng ethansfng force-pushed the export-D104497938 branch 2 times, most recently from c5e9566 to 0ced839 Compare May 11, 2026 18:45
ethansfng added a commit to ethansfng/executorch that referenced this pull request May 11, 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
@ethansfng ethansfng force-pushed the export-D104497938 branch from 0ced839 to 51cb526 Compare May 12, 2026 18:28
ethansfng added a commit to ethansfng/executorch that referenced this pull request May 12, 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
ethansfng added a commit to ethansfng/executorch that referenced this pull request May 12, 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.

Reviewed By: DrJessop

Differential Revision: D104497938
@ethansfng ethansfng force-pushed the export-D104497938 branch from 51cb526 to b08ceb7 Compare May 12, 2026 21:43
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.

Reviewed By: DrJessop

Differential Revision: D104497938
@ethansfng ethansfng force-pushed the export-D104497938 branch from b08ceb7 to ee9d4df Compare May 12, 2026 22:39
@meta-codesync meta-codesync Bot merged commit 2ea50ac into pytorch:main May 13, 2026
171 of 177 checks passed
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.

2 participants