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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point exception and segfault for empty tensors to BatchNorm2d #29578

Closed
dashesy opened this issue Nov 11, 2019 · 2 comments
Closed

Floating point exception and segfault for empty tensors to BatchNorm2d #29578

dashesy opened this issue Nov 11, 2019 · 2 comments
Assignees
Labels
high priority module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@dashesy
Copy link
Contributor

dashesy commented Nov 11, 2019

馃悰 Bug

Intermediate empty tensors result in exceptions and segfault.

To Reproduce

import torch
import torch.nn as nn
gg = nn.BatchNorm2d(64).eval()
prob = torch.empty(size=(0, 64, 112, 112))
print(gg(prob))

Floating point exception

In the actual model BatchNorm2d is actually trained and then .eval is called. Segfault still happens.

Expected behavior

No segfault. Ideally please do support empty tensors.

I hit these issues with empty tensors during exporting/tracing, and cannot use jit.script because I want to export to ONNX.

Even thought exceptions such as

RuntimeError: non-empty 3D or 4D input tensor expected but got ndim: 4

are not that great, at least we can try-catch and work around it.

Environment

PyTorch version: 1.4.0.dev20191023
Is debug build: No
CUDA used to build PyTorch: 10.0

OS: Ubuntu 16.04.6 LTS
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
CMake version: version 3.14.0

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 1070
Nvidia driver version: 418.40.04
cuDNN version: /usr/local/lib/libcudnn.so.5.1.10

Versions of relevant libraries:
[pip] iristorch==0.0.43
[pip] numpy==1.17.2
[pip] torch==1.4.0.dev20191023
[pip] torchvision==0.5.0a0+558beab
[conda] Could not collect

Additional context

The empty tensor is an intermediate tensor, with dynamic batch size. Related to issue #15343 and #12013

cc @ezyang @gchanan @zou3519 @jerryzh168

@ngimel ngimel added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module and removed triage review labels Nov 11, 2019
@ezyang
Copy link
Contributor

ezyang commented Nov 11, 2019

@ngimel How come this one isn't going to triage review?

@ngimel ngimel added triage review and removed triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 11, 2019
@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Nov 18, 2019
facebook-github-bot pushed a commit that referenced this issue Nov 19, 2019
Summary:
Fix for #29578
Shape check is moved up as much as possible, because backends by and large don't correctly handle empty inputs, so check needs to be done before backend selection. That also automatically takes care of backward, because forward for empty input is automatically differentiable, so no backend-specific backward routines are ever called.
Pull Request resolved: #30035

Test Plan: tests for empty inputs are added.

Differential Revision: D18584427

Pulled By: ngimel

fbshipit-source-id: a42918f50eb1f6995921aafa92879cd42dd5e9e1
zdevito pushed a commit to zdevito/ATen that referenced this issue Nov 19, 2019
Summary:
Fix for pytorch/pytorch#29578
Shape check is moved up as much as possible, because backends by and large don't correctly handle empty inputs, so check needs to be done before backend selection. That also automatically takes care of backward, because forward for empty input is automatically differentiable, so no backend-specific backward routines are ever called.
Pull Request resolved: pytorch/pytorch#30035

Test Plan: tests for empty inputs are added.

Differential Revision: D18584427

Pulled By: ngimel

fbshipit-source-id: a42918f50eb1f6995921aafa92879cd42dd5e9e1
@zou3519
Copy link
Contributor

zou3519 commented Dec 2, 2019

I believe this has been fixed on master via #30035 (please let me know if that is not the case)

@zou3519 zou3519 closed this as completed Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

5 participants