Skip to content

[PT2E][X86] Extend reused-module fallback to nn.Conv2d (follow-up to #4480)#4482

Open
waynehacking8 wants to merge 1 commit into
pytorch:mainfrom
waynehacking8:fix-reused-conv-fusion
Open

[PT2E][X86] Extend reused-module fallback to nn.Conv2d (follow-up to #4480)#4482
waynehacking8 wants to merge 1 commit into
pytorch:mainfrom
waynehacking8:fix-reused-conv-fusion

Conversation

@waynehacking8

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #4480 (reused nn.Linear fix), extending the same fix to nn.Conv2d. As @claude noted in the #4480 review, the conv annotation paths share the single-call-site assumption, so a reused nn.Conv2d (e.g. called inside an unrolled loop) under non-strict export still crashes prepare_pt2e:

  • plain path → ValueError: conv partition has more than one output node (_annotate_conv2d)
  • fusion paths → ValueError: Input partition has more than one output node (_get_output_nodes_of_partitions)

Stacked on #4480. This branch is based on fix-4478-reused-linear-fusion because the new test relies on _test_quantizer(..., strict=False) introduced there. Until #4480 merges, the diff here also shows the linear commits; I'll rebase onto main (conv-only) once #4480 lands. Happy to instead fold this into #4480 if you'd prefer a single PR.

Modifications

Mirror the linear fix:

  • _annotate_conv2d_binary_unary / _annotate_conv2d_binary / _annotate_conv2d_unary: skip fusion when any partition has multiple output nodes, so a reused conv falls back to plain annotation.
  • _annotate_conv2d: iterate partition.output_nodes and annotate each call site instead of raising on multi-output partitions.

Test

Adds SharedConvModule + test_conv2d_reused_with_fusable_post_op, covering the unary (relu), binary (add) and binary+unary (add+relu) fusion guards plus the plain fallback.

Coverage is real, not just "passes": with the fix reverted the test crashes with Input partition has more than one output node; with it, each call site is annotated as plain conv and prepare_pt2e succeeds (node_occurrence 2×q/dq-per-tensor + 2× weight dq, conv annotated at both sites, post-op unfused). Validated on torch 2.12 (CPU); ruff check/format clean.


This PR was written with the assistance of Claude (AI); I have reviewed and validated all changes on real hardware.

@pytorch-bot

pytorch-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4482

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

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 13, 2026
Follow-up to the reused nn.Linear fix (pytorch#4480): the conv annotation paths
share the same single-call-site assumption, so a reused nn.Conv2d (e.g.
called inside an unrolled loop) under non-strict export still crashes
prepare_pt2e with "conv partition has more than one output node" (plain
path) or "Input partition has more than one output node" (fusion paths).

Mirror the linear fix:
- _annotate_conv2d_binary_unary / _annotate_conv2d_binary /
  _annotate_conv2d_unary: skip fusion when any partition has multiple
  output nodes, so the reused conv falls back to plain annotation.
- _annotate_conv2d: iterate partition.output_nodes and annotate each call
  site instead of raising on multi-output partitions.

Adds SharedConvModule and test_conv2d_reused_with_fusable_post_op covering
the unary (relu), binary (add) and binary+unary (add+relu) fusion guards
plus the plain fallback. Verified the coverage is real: reverting the fix
makes the test crash with "more than one output node"; with the fix each
call site is annotated as plain conv and prepare_pt2e succeeds.

Signed-off-by: Wayne Chiu <waynehacking8@gmail.com>
@waynehacking8
waynehacking8 force-pushed the fix-reused-conv-fusion branch from 30a7f54 to 1ee972b Compare June 19, 2026 06:02
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant