Skip to content

Add RemoveBNTrackingMutationsPass (#19980)#19980

Open
JakeStevens wants to merge 2 commits into
pytorch:mainfrom
JakeStevens:export-D107395650
Open

Add RemoveBNTrackingMutationsPass (#19980)#19980
JakeStevens wants to merge 2 commits into
pytorch:mainfrom
JakeStevens:export-D107395650

Conversation

@JakeStevens
Copy link
Copy Markdown
Contributor

@JakeStevens JakeStevens commented Jun 3, 2026

Summary:

run_decompositions({}) in core PyTorch re-introduces num_batches_tracked mutable buffer outputs even when batch_norm uses training=False. This happens because the AOTAutograd functionalization pass unconditionally captures BatchNorm's num_batches_tracked as a mutable buffer. The to_edge_transform_and_lower path avoids this, but the separate to_edge() path hits it.

Add a pass to remove_ops.py that strips num_batches_tracked buffer mutations from ExportedPrograms. We use the full ExportedProgramPassBase instead of just ExportPass so that we have access to the full program and signature, as we remove part of the input/output spec.

Add tests for a pass that removes num_batches_tracked buffer mutations from the edge program.

Differential Revision: D107395650

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Jun 3, 2026

🔗 Helpful Links

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

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

✅ No Failures

As of commit 78e6ebc with merge base 1b7008b (image):
💚 Looks good so far! There are no failures yet. 💚

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

meta-codesync Bot commented Jun 3, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

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 RemoveBNTrackingMutationsPass Add RemoveBNTrackingMutationsPass (#19980) Jun 3, 2026
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Jun 3, 2026
Summary:

`run_decompositions({})` in core PyTorch re-introduces `num_batches_tracked` mutable buffer outputs even when `batch_norm` uses `training=False`. This happens because the AOTAutograd functionalization pass unconditionally captures `BatchNorm`'s `num_batches_tracked` as a mutable buffer. The `to_edge_transform_and_lower` path avoids this, but the separate `to_edge()` path hits it.

Add a pass to `remove_ops.py` that strips `num_batches_tracked` buffer mutations from ExportedPrograms. We use the full ExportedProgramPassBase instead of just ExportPass so that we have access to the full program and signature, as we remove part of the input/output spec.

Add tests for a pass that removes `num_batches_tracked` buffer mutations from the edge program.

Differential Revision: D107395650
@JakeStevens JakeStevens force-pushed the export-D107395650 branch 2 times, most recently from ea88f57 to af800b7 Compare June 3, 2026 19:16
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Jun 3, 2026
Summary:

`run_decompositions({})` in core PyTorch re-introduces `num_batches_tracked` mutable buffer outputs even when `batch_norm` uses `training=False`. This happens because the AOTAutograd functionalization pass unconditionally captures `BatchNorm`'s `num_batches_tracked` as a mutable buffer. The `to_edge_transform_and_lower` path avoids this, but the separate `to_edge()` path hits it.

Add a pass to `remove_ops.py` that strips `num_batches_tracked` buffer mutations from ExportedPrograms. We use the full ExportedProgramPassBase instead of just ExportPass so that we have access to the full program and signature, as we remove part of the input/output spec.

Add tests for a pass that removes `num_batches_tracked` buffer mutations from the edge program.

Differential Revision: D107395650
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Jun 3, 2026
Summary:

`run_decompositions({})` in core PyTorch re-introduces `num_batches_tracked` mutable buffer outputs even when `batch_norm` uses `training=False`. This happens because the AOTAutograd functionalization pass unconditionally captures `BatchNorm`'s `num_batches_tracked` as a mutable buffer. The `to_edge_transform_and_lower` path avoids this, but the separate `to_edge()` path hits it.

Add a pass to `remove_ops.py` that strips `num_batches_tracked` buffer mutations from ExportedPrograms. We use the full ExportedProgramPassBase instead of just ExportPass so that we have access to the full program and signature, as we remove part of the input/output spec.

Add tests for a pass that removes `num_batches_tracked` buffer mutations from the edge program.

Differential Revision: D107395650
Summary:
Add `ConvBNReluBasePattern` and concrete patterns (`Conv1dBNReluPattern0/1`, `Conv2dBNReluPattern0/1`) that match the 3-op `conv → batch_norm → relu` chain in QAT graphs.

The existing `ConvReluBasePattern` only matches `conv → relu` (2-op), but in QAT graphs BatchNorm sits between conv and relu, preventing fusion. This produces separate `quantized_relu` and `requantize` ops in the lowered graph instead of a single fused quantized conv.

The new patterns are registered only in `CadenceFusedConvReluQuantizer` (not default/wakeword), ordered before the 2-op patterns so the 3-op match takes priority.

Differential Revision: D107396240
Summary:

`run_decompositions({})` in core PyTorch re-introduces `num_batches_tracked` mutable buffer outputs even when `batch_norm` uses `training=False`. This happens because the AOTAutograd functionalization pass unconditionally captures `BatchNorm`'s `num_batches_tracked` as a mutable buffer. The `to_edge_transform_and_lower` path avoids this, but the separate `to_edge()` path hits it.

Add a pass to `remove_ops.py` that strips `num_batches_tracked` buffer mutations from ExportedPrograms. We use the full ExportedProgramPassBase instead of just ExportPass so that we have access to the full program and signature, as we remove part of the input/output spec.

Add tests for a pass that removes `num_batches_tracked` buffer mutations from the edge program.

Differential Revision: D107395650
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