Skip to content

[TorchTidy] Add pattern to detect if bias is enabled in conv2d followed by batchnorm2d#81941

Closed
davidchencsl wants to merge 10 commits intogh/davidchencsl/25/basefrom
gh/davidchencsl/25/head
Closed

[TorchTidy] Add pattern to detect if bias is enabled in conv2d followed by batchnorm2d#81941
davidchencsl wants to merge 10 commits intogh/davidchencsl/25/basefrom
gh/davidchencsl/25/head

Conversation

@davidchencsl
Copy link
Contributor

@davidchencsl davidchencsl commented Jul 21, 2022

Stack from ghstack (oldest at bottom):

Summary: For cuda models only, if we have nn.Conv2d followed by nn.Batchnorm2d, we don't actually need to use bias=True in Conv2d as the math will cancel out the effect of bias

Test Plan: Added test in test_profiler.py

Differential Revision: D38082643

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jul 21, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

As of commit 1455de3 (more details on the Dr. CI page):

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

davidchencsl added a commit that referenced this pull request Jul 21, 2022
by batchnorm2d

ghstack-source-id: 1093291
Pull Request resolved: #81941
@davidchencsl davidchencsl requested a review from robieta July 21, 2022 22:55
…nv2d followed"

by batchnorm2d

[ghstack-poisoned]
…nv2d followed"

by batchnorm2d

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 22, 2022
by batchnorm2d

ghstack-source-id: a377c59
Pull Request resolved: #81941
@davidchencsl
Copy link
Contributor Author

@davidchencsl has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@davidchencsl
Copy link
Contributor Author

@davidchencsl has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

…nv2d followed"

by batchnorm2d

Differential Revision: [D38082643](https://our.internmc.facebook.com/intern/diff/D38082643)

[ghstack-poisoned]
…nv2d followed"

by batchnorm2d

Differential Revision: [D38082643](https://our.internmc.facebook.com/intern/diff/D38082643)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 25, 2022
by batchnorm2d

ghstack-source-id: 2ad01ce
Pull Request resolved: #81941
@davidchencsl
Copy link
Contributor Author

@davidchencsl has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

…nv2d followed"

by batchnorm2d

Differential Revision: [D38082643](https://our.internmc.facebook.com/intern/diff/D38082643)

[ghstack-poisoned]
@davidchencsl
Copy link
Contributor Author

@davidchencsl has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

…nv2d followed"

by batchnorm2d

Differential Revision: [D38082643](https://our.internmc.facebook.com/intern/diff/D38082643)

[ghstack-poisoned]
@davidchencsl
Copy link
Contributor Author

@davidchencsl has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@robieta robieta left a comment

Choose a reason for hiding this comment

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

LGTM

@davidchencsl davidchencsl changed the title [TorchTidy] Add pattern to detect if bias is enabled in conv2d followed [TorchTidy] Add pattern to detect if bias is enabled in conv2d followed by batchnorm2d Jul 27, 2022
…nv2d followed by batchnorm2d"


Summary: For cuda models only, if we have nn.Conv2d followed by nn.Batchnorm2d, we don't actually need to use bias=True in Conv2d as the math will cancel out the effect of bias

Test Plan: Added test in test_profiler.py

Differential Revision: [D38082643](https://our.internmc.facebook.com/intern/diff/D38082643)

[ghstack-poisoned]
…nv2d followed by batchnorm2d"


Summary: For cuda models only, if we have nn.Conv2d followed by nn.Batchnorm2d, we don't actually need to use bias=True in Conv2d as the math will cancel out the effect of bias

Test Plan: Added test in test_profiler.py

Differential Revision: [D38082643](https://our.internmc.facebook.com/intern/diff/D38082643)

[ghstack-poisoned]
@github-actions
Copy link
Contributor

Hey @davidchencsl.
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.

@ZainRizvi
Copy link
Contributor

ZainRizvi commented Jul 28, 2022

Reverting this PR since it's failing on ROCm builds

See these logs for more details: https://github.com/pytorch/pytorch/runs/7557100340?check_suite_focus=true

cc @davidchencsl

@ZainRizvi
Copy link
Contributor

@pytorchmergebot revert -m "[NOSIGNAL] New test failed on ROCm builds"

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 28, 2022

❌ 🤖 pytorchbot command failed:

@pytorchbot revert: error: the following arguments are required: -c/--classification

usage: @pytorchbot revert -m MESSAGE -c
                          {nosignal,ignoredsignal,landrace,weird,ghfirst}

Try @pytorchbot --help for more info.

@ZainRizvi
Copy link
Contributor

@pytorchmergebot revert -m "New test failed on ROCm builds" -c nosignal

@pytorch pytorch deleted a comment from pytorch-bot bot Jul 28, 2022
@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here

@pytorchmergebot
Copy link
Collaborator

@davidchencsl your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request Jul 28, 2022
…d followed by batchnorm2d (#81941)"

This reverts commit 615f2fd.

Reverted #81941 on behalf of https://github.com/ZainRizvi due to New test failed on ROCm builds
davidchencsl added a commit that referenced this pull request Jul 28, 2022
…n conv2d followed by batchnorm2d

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 28, 2022
…s enabled in conv2d followed by batchnorm2d"

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 28, 2022
…detect if bias is enabled in conv2d followed by batchnorm2d"

Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 28, 2022
…s enabled in conv2d followed by batchnorm2d"

Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 28, 2022
…detect if bias is enabled in conv2d followed by batchnorm2d"

Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 28, 2022
…s enabled in conv2d followed by batchnorm2d"

Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 29, 2022
…detect if bias is enabled in conv2d followed by batchnorm2d"

Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 29, 2022
…s enabled in conv2d followed by batchnorm2d"

Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079)

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 29, 2022
…etect if bias is enabled in conv2d followed by batchnorm2d"

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Jul 29, 2022
… enabled in conv2d followed by batchnorm2d"

[ghstack-poisoned]
@facebook-github-bot facebook-github-bot deleted the gh/davidchencsl/25/head branch July 31, 2022 14:18
davidchencsl added a commit that referenced this pull request Aug 2, 2022
…etect if bias is enabled in conv2d followed by batchnorm2d"

[ghstack-poisoned]
davidchencsl added a commit that referenced this pull request Aug 2, 2022
… enabled in conv2d followed by batchnorm2d"

[ghstack-poisoned]
pytorchmergebot pushed a commit that referenced this pull request Aug 2, 2022
… conv2d followed by batchnorm2d (#82421)

Pull Request resolved: #82421
Approved by: https://github.com/robieta
event, lambda e: e.name().startswith("nn.Module: Conv2d"))
if not event:
return False
event = self.next_of(event)
Copy link
Collaborator

Choose a reason for hiding this comment

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

how would this work if forward is something like

x1=self.conv1(x)
x2=self.conv2(x)
x1=self.bn1(x1)
x2=self.bn2(x2)

Wouldn't next_of be just the next conv in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah. Right now I am going to narrow the scope of detection to Situation in nn.Sequential, or simpler scenarios, as we do not have tensor identities information (Only size and dtype) as of right now. But great point! I will add a todo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But if we do have that information, we can do something like:

event = next_used_event(event.output_tensor)

Copy link
Collaborator

Choose a reason for hiding this comment

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

tensor identities are needed for more robust pattern detection

facebook-github-bot pushed a commit that referenced this pull request Aug 3, 2022
… conv2d followed by batchnorm2d (#82421) (#82421)

Summary:
Pull Request resolved: #82421
Approved by: https://github.com/robieta

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/ae2e303de0795642b0c811f356e1024285e3ac00

Reviewed By: kit1980

Differential Revision: D38359670

Pulled By: davidchencsl

fbshipit-source-id: 5f3d8555775133dd3ed48b949f037a301137ae74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants