[TorchTidy] Add pattern to detect if bias is enabled in conv2d followed by batchnorm2d#81941
[TorchTidy] Add pattern to detect if bias is enabled in conv2d followed by batchnorm2d#81941davidchencsl wants to merge 10 commits intogh/davidchencsl/25/basefrom
Conversation
by batchnorm2d [ghstack-poisoned]
🔗 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. |
…nv2d followed" by batchnorm2d [ghstack-poisoned]
…nv2d followed" by batchnorm2d [ghstack-poisoned]
|
@davidchencsl has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
1 similar comment
|
@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 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 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 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
…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]
|
Hey @davidchencsl. |
|
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 |
|
@pytorchmergebot revert -m "[NOSIGNAL] New test failed on ROCm builds" |
|
❌ 🤖 pytorchbot command failed: Try |
|
@pytorchmergebot revert -m "New test failed on ROCm builds" -c nosignal |
|
@pytorchbot successfully started a revert job. Check the current status here |
|
@davidchencsl your PR has been successfully reverted. |
…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
…n conv2d followed by batchnorm2d [ghstack-poisoned]
…s enabled in conv2d followed by batchnorm2d" [ghstack-poisoned]
…detect if bias is enabled in conv2d followed by batchnorm2d" Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079) [ghstack-poisoned]
…s enabled in conv2d followed by batchnorm2d" Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079) [ghstack-poisoned]
…detect if bias is enabled in conv2d followed by batchnorm2d" Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079) [ghstack-poisoned]
…s enabled in conv2d followed by batchnorm2d" Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079) [ghstack-poisoned]
…detect if bias is enabled in conv2d followed by batchnorm2d" Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079) [ghstack-poisoned]
…s enabled in conv2d followed by batchnorm2d" Differential Revision: [D38254079](https://our.internmc.facebook.com/intern/diff/D38254079) [ghstack-poisoned]
…etect if bias is enabled in conv2d followed by batchnorm2d" [ghstack-poisoned]
… enabled in conv2d followed by batchnorm2d" [ghstack-poisoned]
…etect if bias is enabled in conv2d followed by batchnorm2d" [ghstack-poisoned]
… enabled in conv2d followed by batchnorm2d" [ghstack-poisoned]
… 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
But if we do have that information, we can do something like:
event = next_used_event(event.output_tensor)
There was a problem hiding this comment.
tensor identities are needed for more robust pattern detection
… 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
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