Skip to content

Gate FuseQATConvBN behind is_qat=True; opt in from QAT deployments#19601

Open
ethansfng wants to merge 1 commit into
pytorch:mainfrom
ethansfng:export-D105061752
Open

Gate FuseQATConvBN behind is_qat=True; opt in from QAT deployments#19601
ethansfng wants to merge 1 commit into
pytorch:mainfrom
ethansfng:export-D105061752

Conversation

@ethansfng
Copy link
Copy Markdown
Contributor

Summary:
The FuseQATConvBN pass added in D104497938 ran unconditionally inside apply_pre_edge_transform_passes. Its _prep_conv_biases step delegates to the shared _quantize_fused_conv_bias helper, which iterates every conv in the graph and asserts each conv input is dequantize_per_tensor — an invariant that only holds inside the conv-BN simulation chain prepare_qat_pt2e inserts. PTQ graphs trip the assert (T271158088).

Two failure modes seen in the wild:

  • test_quantized_w8a32_conv1d_out_2 uses CadenceW8A32MixedQuantizer so activations stay float32; the conv input is the placeholder, not a dequant.
  • test_conv2d_out_7 is channel_last=True, so the conv input is aten.permute, not a dequant; the helper only unwraps unsqueeze variants.

Add an is_qat: bool = False parameter to apply_pre_edge_transform_passes and only include FuseQATConvBN when True. Plumb through quantize_pt2/get_fake_quant_model and forward from the modai recipe lambda so ar_*_qat_et_recipe factories actually opt in.

QAT-trained models lowered via blobgen need a way to reach the QAT recipe. Add is_qat: bool to Packaging and have Rt700Hifi4Deployment pass train=self.packaging.is_qat to get_recipe_with_custom_settings. Models like activity_classification_artemis should set "is_qat": True in their defs.bzl packaging block.

Differential Revision: D105061752

Summary:
The FuseQATConvBN pass added in D104497938 ran unconditionally inside `apply_pre_edge_transform_passes`. Its `_prep_conv_biases` step delegates to the shared `_quantize_fused_conv_bias` helper, which iterates every conv in the graph and asserts each conv input is `dequantize_per_tensor` — an invariant that only holds inside the conv-BN simulation chain `prepare_qat_pt2e` inserts. PTQ graphs trip the assert (T271158088).

Two failure modes seen in the wild:
- `test_quantized_w8a32_conv1d_out_2` uses `CadenceW8A32MixedQuantizer` so activations stay float32; the conv input is the placeholder, not a dequant.
- `test_conv2d_out_7` is `channel_last=True`, so the conv input is `aten.permute`, not a dequant; the helper only unwraps `unsqueeze` variants.

Add an `is_qat: bool = False` parameter to `apply_pre_edge_transform_passes` and only include `FuseQATConvBN` when True. Plumb through `quantize_pt2`/`get_fake_quant_model` and forward from the modai recipe lambda so `ar_*_qat_et_recipe` factories actually opt in.

QAT-trained models lowered via blobgen need a way to reach the QAT recipe. Add `is_qat: bool` to `Packaging` and have `Rt700Hifi4Deployment` pass `train=self.packaging.is_qat` to `get_recipe_with_custom_settings`. Models like `activity_classification_artemis` should set `"is_qat": True` in their `defs.bzl` packaging block.

Differential Revision: D105061752
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 14, 2026

🔗 Helpful Links

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

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:

❌ 3 New Failures, 1 Unrelated Failure

As of commit 3c17a1d with merge base 7cd209d (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job 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 14, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 14, 2026

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

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

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