Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate no-spatial mode of BN #1637

Merged
merged 6 commits into from
Jan 16, 2019
Merged

deprecate no-spatial mode of BN #1637

merged 6 commits into from
Jan 16, 2019

Conversation

liqunfu
Copy link
Collaborator

@liqunfu liqunfu commented Nov 20, 2018

Most AI frameworks do not have non-spatial mode for BN. For example, all 3 ops in Pytorch (torch.nn.BatchNorm1d, torch.nn.BatchNorm2d, torch.nn.BatchNorm3d) are spatial mode. In TF, BN is treaded in a flexible way that statistics are computed over dimensions whose size if 1. In all cases, what is needed is to specify dimensions over which statistics are computed. With this update, dimensions except the channel dimension are dimensions over which statistics are computed. We therefore deprecate the non-spatial mode.

Copy link
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Will this bring us any benefit besides less attribute? I would like to keep this potential for enabling non-spatial BN. Since it's available in CuDNN, this hint is useful to enable the special handling for non-spatial cases. We have an issue to track this optimization in Caffe2: pytorch/pytorch#14185

@liqunfu
Copy link
Collaborator Author

liqunfu commented Dec 4, 2018

@houseroad, the purpose of this PR is to simplify BN spec by removing the no-spatial mode. One can view BN in its most generic form as an op to compute statistics across a subset of the input tensor's dimensions. Dimensions not involved in statistics computation are grouped into a single dimension as channel. Therefore, it is unnecessary to call out spatial and non-spatial modes.
As state in this PR, no-spatial mode can be done by pre reshaping (to group all dimensions other than N into the channel dimension). There is no performance hit. CuDNN per-activation mode can be done similarly in spatial mode.

@liqunfu
Copy link
Collaborator Author

liqunfu commented Dec 20, 2018

@houseroad please any feedback? Thanks

@jspisak jspisak merged commit fd60104 into onnx:master Jan 16, 2019
@jspisak
Copy link
Contributor

jspisak commented Jan 16, 2019

LGTM!

shinh added a commit to shinh/onnx-chainer that referenced this pull request Jan 25, 2019
ONNX opset 9 removed `spatial` attribute of BatchNormalization.

onnx/onnx#1637

Since the default value of `spatial` has been True for the
whole time, just dropping the attribute would be the simplest
and the most robust fix to handle the update.
hariharans29 pushed a commit to hariharans29/onnx that referenced this pull request Aug 15, 2019
* deprecate spatial mode of BN

* merge with master

* deprecate no-spatial mode of BN - update TestCoverage.md
jcwchen pushed a commit to jcwchen/onnx that referenced this pull request Sep 23, 2020
* deprecate spatial mode of BN

* merge with master

* deprecate no-spatial mode of BN - update TestCoverage.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants