Skip to content

TorchDynamo: Add convolution unary fusion for cpu in inference mode - #87063

Closed
XiaobingSuper wants to merge 15 commits into
gh/XiaobingSuper/19/basefrom
gh/XiaobingSuper/19/head
Closed

TorchDynamo: Add convolution unary fusion for cpu in inference mode#87063
XiaobingSuper wants to merge 15 commits into
gh/XiaobingSuper/19/basefrom
gh/XiaobingSuper/19/head

Conversation

@XiaobingSuper
XiaobingSuper requested a review from jansel as a code owner October 17, 2022 06:54
@pytorch-bot

pytorch-bot Bot commented Oct 17, 2022

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit a8853c0:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Comment thread torch/_inductor/ir.py Outdated
Comment thread torch/_inductor/ir.py Outdated
Comment thread torch/_inductor/overrides.py Outdated
Comment on lines +128 to +129
def fuse_conv_unary_eval(conv: nn.Module, unary: nn.Module):
assert not (conv.training), "Fusion only for eval!"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why marking it as "eval" and requiring it not for "training"? The fusion can apply to forward graph and backward graph generated by AOTAutograd as long as the pattern matches per fuse_fx, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the current path, we do the fusion path before AOTAutograd, which doesn't have forward graph and backward graph. But if we do the fusion after AOTAutograd(at fw_compiler), the AOTAutograd will decompose some ops to many smaller ops, such as Gelu, it will be hard to do the fusion.

Comment thread torch/_inductor/overrides.py Outdated
Comment on lines +159 to +161
eval_mode = all(not n.training for n in [conv, unary])
if not eval_mode:
continue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, why eval only?

Comment thread torch/_inductor/lowering.py Outdated
Comment on lines +894 to +897
else:
log.warning(
"Register OneDNN fusion ops is failed which OneDNN is not enabled at build step"
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have to warn here since the fx graph won't contain the corresponding aten ops and users don't have to care about the absence of the registration.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, changed.

…ence mode"

cc jansel lezcano fdrocha mlazos soumith voznesenskym yanboliang

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 24, 2022
@github-actions

Copy link
Copy Markdown
Contributor

Hey @XiaobingSuper.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

chunyuan-w added a commit that referenced this pull request Dec 9, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 9, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 13, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 13, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 15, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
pytorchmergebot pushed a commit that referenced this pull request Dec 15, 2022
#90265)

An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu

Pull Request resolved: #90265
Approved by: https://github.com/jgong5, https://github.com/jansel
chunyuan-w added a commit that referenced this pull request Dec 19, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 19, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 19, 2022
…on for cpu in inference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Dec 19, 2022
…ference mode"



An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in #87063.

The fusion OP is implemented in #90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
@facebook-github-bot
facebook-github-bot deleted the gh/XiaobingSuper/19/head branch June 8, 2023 15:00
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
pytorch#90265)

An FX transformation is added to fuse ConvTranspose2d with eltwise OPs in torchinductor for CPU in inference mode, following the implementation in pytorch#87063.

The fusion OP is implemented in pytorch#90264 and will be treated as an extern kernel call in torchinductor.

The fusion of ConvTranspose2d with the below OPs is supported:

- relu
- sigmoid
- tanh
- hardswish
- leaky_relu
- hardtanh
- gelu

Pull Request resolved: pytorch#90265
Approved by: https://github.com/jgong5, https://github.com/jansel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants