Skip to content

Mark quantized nodes in custom node metadata so fusion works after export (#25183) - #25183

Open
rezaasjd wants to merge 1 commit into
pytorch:mainfrom
rezaasjd:export-D132375392
Open

rezaasjd wants to merge 1 commit into
pytorch:mainfrom
rezaasjd:export-D132375392

Conversation

@rezaasjd

@rezaasjd rezaasjd commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fusion decides which ops to fuse from the quantizer's annotations, but torch.export does not carry quantization_annotation over to the exported graph: it copies only a fixed set of node metadata keys, and the annotation holds references to nodes of the original graph. Fusion also resolved per-channel qparams as get_attr constants, which export lifts to placeholders. So fusion could only run on the converted graph module, before export.

annotate_input_qspec_map and annotate_output_qspec in the fused_quant quantizer now wrap the torchao helpers and, when the qspec is live, also set QUANTIZED_KEY in node.meta["custom"], which export keeps. OpQuantizer.fuse gates on that flag instead of the annotation, so it gives the same answer on the converted graph and on a program exported from it. The per-channel qparams path in fuse_aten reads shapes from meta["val"] instead of resolving get_attr tensors, so it also works with lifted placeholders.

Differential Revision: D132375392

@pytorch-bot

pytorch-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 19b0199 with merge base 436abf7 (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 Nov 17, 2026
@meta-codesync

meta-codesync Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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

@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 Mark quantized nodes in custom node metadata so fusion works after export Mark quantized nodes in custom node metadata so fusion works after export (#25183) Nov 17, 2026
rezaasjd added a commit to rezaasjd/executorch that referenced this pull request Nov 17, 2026
…port (pytorch#25183)

Summary:

Fusion decides which ops to fuse from the quantizer's annotations, but torch.export does not carry quantization_annotation over to the exported graph: it copies only a fixed set of node metadata keys, and the annotation holds references to nodes of the original graph. Fusion also resolved per-channel qparams as get_attr constants, which export lifts to placeholders. So fusion could only run on the converted graph module, before export.

annotate_input_qspec_map and annotate_output_qspec in the fused_quant quantizer now wrap the torchao helpers and, when the qspec is live, also set QUANTIZED_KEY in node.meta["custom"], which export keeps. OpQuantizer.fuse gates on that flag instead of the annotation, so it gives the same answer on the converted graph and on a program exported from it. The per-channel qparams path in fuse_aten reads shapes from meta["val"] instead of resolving get_attr tensors, so it also works with lifted placeholders.

Differential Revision: D132375392
rezaasjd added a commit to rezaasjd/executorch that referenced this pull request Nov 17, 2026
…port (pytorch#25183)

Summary:

Fusion decides which ops to fuse from the quantizer's annotations, but torch.export does not carry quantization_annotation over to the exported graph: it copies only a fixed set of node metadata keys, and the annotation holds references to nodes of the original graph. Fusion also resolved per-channel qparams as get_attr constants, which export lifts to placeholders. So fusion could only run on the converted graph module, before export.

annotate_input_qspec_map and annotate_output_qspec in the fused_quant quantizer now wrap the torchao helpers and, when the qspec is live, also set QUANTIZED_KEY in node.meta["custom"], which export keeps. OpQuantizer.fuse gates on that flag instead of the annotation, so it gives the same answer on the converted graph and on a program exported from it. The per-channel qparams path in fuse_aten reads shapes from meta["val"] instead of resolving get_attr tensors, so it also works with lifted placeholders.

Differential Revision: D132375392
…port (pytorch#25183)

Summary:

Fusion decides which ops to fuse from the quantizer's annotations, but torch.export does not carry quantization_annotation over to the exported graph: it copies only a fixed set of node metadata keys, and the annotation holds references to nodes of the original graph. Fusion also resolved per-channel qparams as get_attr constants, which export lifts to placeholders. So fusion could only run on the converted graph module, before export.

annotate_input_qspec_map and annotate_output_qspec in the fused_quant quantizer now wrap the torchao helpers and, when the qspec is live, also set QUANTIZED_KEY in node.meta["custom"], which export keeps. OpQuantizer.fuse gates on that flag instead of the annotation, so it gives the same answer on the converted graph and on a program exported from it. The per-channel qparams path in fuse_aten reads shapes from meta["val"] instead of resolving get_attr tensors, so it also works with lifted placeholders.

Differential Revision: D132375392
rezaasjd added a commit to rezaasjd/executorch that referenced this pull request Nov 17, 2026
…port (pytorch#25183)

Summary:

Fusion decides which ops to fuse from the quantizer's annotations, but torch.export does not carry quantization_annotation over to the exported graph: it copies only a fixed set of node metadata keys, and the annotation holds references to nodes of the original graph. Fusion also resolved per-channel qparams as get_attr constants, which export lifts to placeholders. So fusion could only run on the converted graph module, before export.

annotate_input_qspec_map and annotate_output_qspec in the fused_quant quantizer now wrap the torchao helpers and, when the qspec is live, also set QUANTIZED_KEY in node.meta["custom"], which export keeps. OpQuantizer.fuse gates on that flag instead of the annotation, so it gives the same answer on the converted graph and on a program exported from it. The per-channel qparams path in fuse_aten reads shapes from meta["val"] instead of resolving get_attr tensors, so it also works with lifted placeholders.

Differential Revision: D132375392

This branch has not been deployed

No deployments
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant