[PT2E][X86] Extend reused-module fallback to nn.Conv2d (follow-up to #4480)#4482
Open
waynehacking8 wants to merge 1 commit into
Open
[PT2E][X86] Extend reused-module fallback to nn.Conv2d (follow-up to #4480)#4482waynehacking8 wants to merge 1 commit into
waynehacking8 wants to merge 1 commit into
Conversation
waynehacking8
requested review from
Xia-Weiwen,
jerryzh168 and
vkuzo
as code owners
June 13, 2026 07:36
🔗 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. |
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
force-pushed
the
fix-reused-conv-fusion
branch
from
June 19, 2026 06:02
30a7f54 to
1ee972b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #4480 (reused
nn.Linearfix), extending the same fix tonn.Conv2d. As @claude noted in the #4480 review, the conv annotation paths share the single-call-site assumption, so a reusednn.Conv2d(e.g. called inside an unrolled loop) under non-strict export still crashesprepare_pt2e:ValueError: conv partition has more than one output node(_annotate_conv2d)ValueError: Input partition has more than one output node(_get_output_nodes_of_partitions)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: iteratepartition.output_nodesand 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 andprepare_pt2esucceeds (node_occurrence2×q/dq-per-tensor + 2× weight dq, conv annotated at both sites, post-op unfused). Validated on torch 2.12 (CPU);ruff check/formatclean.This PR was written with the assistance of Claude (AI); I have reviewed and validated all changes on real hardware.