Problem with torch.onnx.export for nn.InstanceNorm2D

  • OS: MacOS Sierra
  • PyTorch version: 0.4.0a0+7588893 (I instaled the latest yesterday from the source)
  • How you installed PyTorch (conda, pip, source): source
  • Python version: Python 2.7.14 |Anaconda, Inc.|
  • CUDA/cuDNN version: No Cuda
  • GPU models and configuration: No GPU models
  • GCC version (if compiling from source): GCC 4.2.1 Compatible Clang 4.0.1

I was trying to use torch.onnx.export to export some pretrained pytorch models.

If I use the instanceNorm2D layer as following
nn.InstanceNorm2d(ngf,affine=True)
I get the following problem when doing torch.onnx.export

torch.onnx.export(model, (dummy_input, dummy_input), MODEL_DIR + “eye_G.proto”, verbose=True)
File “/anaconda2/lib/python2.7/site-packages/torch/onnx/init.py”, line 83, in export
_export(model, args, f, export_params, verbose, training, input_names, output_names)
File “/anaconda2/lib/python2.7/site-packages/torch/onnx/init.py”, line 138, in _export
_optimize_trace(trace, aten)
File “/anaconda2/lib/python2.7/site-packages/torch/onnx/init.py”, line 94, in _optimize_trace
torch._C._jit_pass_onnx(trace, aten)
File “/anaconda2/lib/python2.7/site-packages/torch/onnx/init.py”, line 180, in _run_symbolic_method
return symbolic_fn(*args)
File “/anaconda2/lib/python2.7/site-packages/torch/onnx/init.py”, line 396, in symbolic
symbolic_output = symbolic_fn(g, *symbolic_args, **kwargs)
File “/anaconda2/lib/python2.7/site-packages/torch/onnx/symbolic.py”, line 552, in instance_norm
if not weight:
RuntimeError: bool value of Tensor with more than one value is ambiguous

If I do nn.InstanceNorm2d(ngf,affine=False) or nn.InstanceNorm2d(ngf), then the export will succeed. Anybody know why?

That is rather weird. Could you try this commit https://github.com/pytorch/pytorch/commit/9388d3529326f063946772718a495877d681342a? Maybe my layer norm PR broke it.

I tried checking out that commit and rebuild pytorch and I am getting the following error.

x = torch.cat((self.pre_model(input1), self.pre_model(input2)), 1)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py”, line 355, in call

result = self._slow_forward(*input, **kwargs)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py”, line 345, in _slow_forward

result = self.forward(*input, **kwargs)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/container.py”, line 89, in forward

input = module(input)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py”, line 355, in call

result = self._slow_forward(*input, **kwargs)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py”, line 345, in _slow_forward

result = self.forward(*input, **kwargs)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/instancenorm.py”, line 24, in forward

eps=self.eps, affine=self.affine)

File “/anaconda2/lib/python2.7/site-packages/torch/nn/functional.py”, line 1209, in instance_norm

momentum=momentum, eps=eps, affine=affine)

File “/anaconda2/lib/python2.7/site-packages/torch/onnx/init.py”, line 392, in wrapper

"Passing Variable through kwargs is not supported"

AssertionError: Passing Variable through kwargs is not supported