Repository: pytorch
Issue: Caffe2: operator_test/instance_norm_test.py::TestInstanceNorm::test_instance_norm_gradients test case fails with "RuntimeError: dim() called on undefined TensorError from operator"
Labels: caffe2

## 🐛 Bug

The `operator_test/instance_norm_test.py::TestInstanceNorm::test_instance_norm_gradients` test case fails with a RuntimeError about ` test case fails intermittently

## To Reproduce

Steps to reproduce the behavior:

1. Install Caffe2
2. Run `python caffe2/python/operator_test/instance_norm_test.py TestInstanceNorm`

The test fails on `test_instance_norm_gradients` with the following error:

```
ERROR: test_instance_norm_gradients (__main__.TestInstanceNorm)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "instance_norm_test.py", line 54, in test_instance_norm_gradients
    dc=hu.gcs['dc'],
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/hypothesis/core.py", line 1046, in wrapped_test
    state.run()
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/hypothesis/core.py", line 814, in run
    falsifying_example.__expected_traceback,
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/hypothesis/core.py", line 587, in execute
    result = self.test_runner(data, run)
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/hypothesis/executors.py", line 58, in default_new_style_executor
    return function(data)
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/hypothesis/core.py", line 578, in run
    return test(*args, **kwargs)
  File "instance_norm_test.py", line 54, in test_instance_norm_gradients
    dc=hu.gcs['dc'],
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/hypothesis/core.py", line 525, in test
    result = self.test(*args, **kwargs)
  File "instance_norm_test.py", line 92, in test_instance_norm_gradients
    threshold=0.01)
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/hypothesis_test_util.py", line 458, in assertGradientChecks
    input_device_options=input_device_options
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/gradient_checker.py", line 281, in CheckSimple
    outputs_with_grads
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/gradient_checker.py", line 200, in GetLossAndGrad
    workspace.RunOperatorsOnce(grad_ops)
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/workspace.py", line 199, in RunOperatorsOnce
    success = RunOperatorOnce(op)
  File "/home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/workspace.py", line 190, in RunOperatorOnce
    return C.run_operator_once(StringifyProto(operator))
RuntimeError: dim() called on undefined TensorError from operator: 
input: "input" input: "scale" input: "bias" input: "output_grad" output: "input_grad" output: "scale_grad" output: "bias_grad" name: "" type: "InstanceNormGradient" arg { name: "order" s: "NCHW" } arg { name: "epsilon" f: 1e-06 } device_option { device_type: 1 } is_gradient_op: true (dim at ../c10/core/UndefinedTensorImpl.cpp:24)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x6d (0x7f7bffeae80d in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libc10.so)
frame #1: c10::UndefinedTensorImpl::dim() const + 0xc3 (0x7f7bffea7aa3 in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libc10.so)
frame #2: void c10::TensorImpl::Resize<int, int>(int, int) + 0x160 (0x7f7c11980680 in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libcaffe2.so)
frame #3: caffe2::InstanceNormGradientOp<float, caffe2::CUDAContext>::RunOnDeviceWithOrderNCHW() + 0x821 (0x7f7c02d097e1 in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libcaffe2_gpu.so)
frame #4: <unknown function> + 0x27a449c (0x7f7c02d0a49c in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libcaffe2_gpu.so)
frame #5: <unknown function> + 0x267cb28 (0x7f7c02be2b28 in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libcaffe2_gpu.so)
frame #6: caffe2::Workspace::RunOperatorOnce(caffe2::OperatorDef const&) + 0x4a (0x7f7c11617f7a in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/../../torch/lib/libcaffe2.so)
frame #7: <unknown function> + 0x4fd9d (0x7f7c138e4d9d in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/caffe2_pybind11_state_gpu.cpython-36m-x86_64-linux-gnu.so)
frame #8: <unknown function> + 0x4ff17 (0x7f7c138e4f17 in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/caffe2_pybind11_state_gpu.cpython-36m-x86_64-linux-gnu.so)
frame #9: <unknown function> + 0x8dd0e (0x7f7c13922d0e in /home/cphofer/anaconda3/envs/pytorch_env/lib/python3.6/site-packages/caffe2/python/caffe2_pybind11_state_gpu.cpython-36m-x86_64-linux-gnu.so)
<omitting python frames>
```

## Expected behavior

The test case should pass

## Environment

### x86

PyTorch version: 1.1.0
Is debug build: No
CUDA used to build PyTorch: 10.1.168

OS: Red Hat
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
CMake version: version 2.8.12.2

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration:
GPU 0: Tesla V100-PCIE-16GB
GPU 1: Tesla V100-PCIE-16GB

Nvidia driver version: 418.40.04
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] numpy==1.14.6
[pip] torch==1.1.0
[pip] torchvision==0.2.2
[conda] blas 1.0 mkl
[conda] magma 2.5.0
[conda] mkl 2018.0.3
[conda] mkl_fft 1.0.6
[conda] mkl_random 1.0.1
[conda] pytorch 1.1.0

### Power

PyTorch version: 1.1.0
Is debug build: No
CUDA used to build PyTorch: 10.1.168

OS: Red Hat Enterprise Linux Server 7.6 (Maipo)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
CMake version: Could not collect

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.1.105
GPU models and configuration: 
GPU 0: Tesla V100-SXM2-16GB
GPU 1: Tesla V100-SXM2-16GB
GPU 2: Tesla V100-SXM2-16GB
GPU 3: Tesla V100-SXM2-16GB

Nvidia driver version: 418.67
cuDNN version: 7.5.1

Versions of relevant libraries:
[pip] numpy==1.14.5
[pip] torch==1.1.0
[pip] torchvision==0.2.2
[conda] magma                     2.5.0
[conda] pytorch                   1.1.0