An error happend when I convert pytorch model to onnx
Labels: module: onnx, triaged

### 🐛 Describe the bug

Recently I have been experimenting with virtual try-on(VTON). Due to the performance requirements of the competition, I intend to convert the VTON pytorch model to onnx model, on one hand to reduce the model size and on the other hand to improve the running speed on CPU.
But there were some problems when I converted the model. The pytorch model's name is' gen.pth'(for generating the image after trying on clothes) and it takes two inputs, a tensor with shape [1, 9, 1024, 768] and a tensor with shape [1, 7, 1024, 768].

**Here is the code:**
```
dummy_input0 = torch.randn(1, 9, 1024, 768)
dummy_input1 = torch.randn(1, 7, 1024, 768)
with warnings.catch_warnings():
    warnings.filterwarnings("ignore")
    if not onnx_path.exists():
        torch.onnx.export(
            generator,
            (dummy_input0,
             dummy_input1),
            onnx_path,
        )
        print(f"ONNX model exported to {onnx_path}.")
    else:
        print(f"ONNX model {onnx_path} already exists.")
```


**Here is the error message:**
```
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call last)
> Cell In[9], line 8
>       6 warnings.filterwarnings("ignore")
>       7 if not onnx_path.exists():
> ----> 8     torch.onnx.export(
>       9         generator,
>      10         (dummy_input0,
>      11          dummy_input1),
>      12         onnx_path,
>      13     )
>      14     print(f"ONNX model exported to {onnx_path}.")
>      15 else:
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\__init__.py:350, in export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, custom_opsets, export_modules_as_functions)
>      74 r"""
>      75 Exports a model into ONNX format. If ``model`` is not a
>      76 :class:`torch.jit.ScriptModule` nor a :class:`torch.jit.ScriptFunction`, this runs
>    (...)
>     345     model to the file ``f`` even if this is raised.
>     346 """
>     348 from torch.onnx import utils
> --> 350 return utils.export(
>     351     model,
>     352     args,
>     353     f,
>     354     export_params,
>     355     verbose,
>     356     training,
>     357     input_names,
>     358     output_names,
>     359     operator_export_type,
>     360     opset_version,
>     361     do_constant_folding,
>     362     dynamic_axes,
>     363     keep_initializers_as_inputs,
>     364     custom_opsets,
>     365     export_modules_as_functions,
>     366 )
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\utils.py:163, in export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, custom_opsets, export_modules_as_functions)
>     145 def export(
>     146     model,
>     147     args,
>    (...)
>     160     export_modules_as_functions=False,
>     161 ):
> --> 163     _export(
>     164         model,
>     165         args,
>     166         f,
>     167         export_params,
>     168         verbose,
>     169         training,
>     170         input_names,
>     171         output_names,
>     172         operator_export_type=operator_export_type,
>     173         opset_version=opset_version,
>     174         do_constant_folding=do_constant_folding,
>     175         dynamic_axes=dynamic_axes,
>     176         keep_initializers_as_inputs=keep_initializers_as_inputs,
>     177         custom_opsets=custom_opsets,
>     178         export_modules_as_functions=export_modules_as_functions,
>     179     )
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\utils.py:1074, in _export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, fixed_batch_size, custom_opsets, add_node_names, onnx_shape_inference, export_modules_as_functions)
>    1071     dynamic_axes = {}
>    1072 _validate_dynamic_axes(dynamic_axes, model, input_names, output_names)
> -> 1074 graph, params_dict, torch_out = _model_to_graph(
>    1075     model,
>    1076     args,
>    1077     verbose,
>    1078     input_names,
>    1079     output_names,
>    1080     operator_export_type,
>    1081     val_do_constant_folding,
>    1082     fixed_batch_size=fixed_batch_size,
>    1083     training=training,
>    1084     dynamic_axes=dynamic_axes,
>    1085 )
>    1087 # TODO: Don't allocate a in-memory string for the protobuf
>    1088 defer_weight_export = (
>    1089     export_type is not torch.onnx.ExportTypes.PROTOBUF_FILE
>    1090 )
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\utils.py:731, in _model_to_graph(model, args, verbose, input_names, output_names, operator_export_type, do_constant_folding, _disable_torch_constant_prop, fixed_batch_size, training, dynamic_axes)
>     728 params_dict = _get_named_param_dict(graph, params)
>     730 try:
> --> 731     graph = _optimize_graph(
>     732         graph,
>     733         operator_export_type,
>     734         _disable_torch_constant_prop=_disable_torch_constant_prop,
>     735         fixed_batch_size=fixed_batch_size,
>     736         params_dict=params_dict,
>     737         dynamic_axes=dynamic_axes,
>     738         input_names=input_names,
>     739         module=module,
>     740     )
>     741 except Exception as e:
>     742     torch.onnx.log("Torch IR graph at exception: ", graph)
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\utils.py:308, in _optimize_graph(graph, operator_export_type, _disable_torch_constant_prop, fixed_batch_size, params_dict, dynamic_axes, input_names, module)
>     306     _C._jit_pass_onnx_set_dynamic_input_shape(graph, dynamic_axes, input_names)
>     307 _C._jit_pass_onnx_lint(graph)
> --> 308 graph = _C._jit_pass_onnx(graph, operator_export_type)
>     309 _C._jit_pass_onnx_lint(graph)
>     310 _C._jit_pass_lint(graph)
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\__init__.py:416, in _run_symbolic_function(*args, **kwargs)
>     413 def _run_symbolic_function(*args, **kwargs):
>     414     from torch.onnx import utils
> --> 416     return utils._run_symbolic_function(*args, **kwargs)
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\utils.py:1406, in _run_symbolic_function(g, block, n, inputs, env, operator_export_type)
>    1404     if op_name == "PythonOp":
>    1405         inputs = (n, *inputs)
> -> 1406     return symbolic_fn(g, *inputs, **attrs)
>    1407 elif ns == "onnx":
>    1408     # Clone node to trigger ONNX shape inference
>    1409     attrs = {k + "_" + n.kindOf(k)[0]: n[k] for k in n.attributeNames()}  # type: ignore[attr-defined]
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\symbolic_helper.py:234, in parse_args.<locals>.decorator.<locals>.wrapper(g, *args, **kwargs)
>     229 if len(kwargs) == 1:
>     230     assert "_outputs" in kwargs, (
>     231         f"Symbolic function {fn.__name__}'s '**kwargs' can only contain '_outputs' key at '**kwargs'. "
>     232         f"{FILE_BUG_MSG}"
>     233     )
> --> 234 return fn(g, *args, **kwargs)
> 
> File E:\Anaconda3\envs\openvino_env\lib\site-packages\torch\onnx\symbolic_opset9.py:1963, in instance_norm(g, input, weight, bias, running_mean, running_var, use_input_stats, momentum, eps, cudnn_enabled)
>    1961 if weight is None or symbolic_helper._is_none(weight):
>    1962     if channel_size is None:
> -> 1963         raise RuntimeError(
>    1964             "Unsupported: ONNX export of instance_norm for unknown " "channel size."
>    1965         )
>    1966     weight_value = torch.tensor([1.0] * channel_size).type(
>    1967         "torch." + input.type().scalarType() + "Tensor"
>    1968     )
>    1969     weight = g.op("Constant", value_t=weight_value)
> 
> RuntimeError: Unsupported: ONNX export of instance_norm for unknown channel size.
```

### Versions

```
E:\Anaconda3\envs\openvino_env\python.exe E:\fuchuang\openvino\openvino_notebooks-main\notebooks\102-viton-putorch-to-openvino\collet_env.py 
Collecting environment information...
PyTorch version: 1.12.1
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 家庭中文版
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A

Python version: 3.9.15 (main, Nov 24 2022, 14:39:17) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.22000-SP0
Is CUDA available: False
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060 Laptop GPU
Nvidia driver version: 512.78
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==1.13.0
[pip3] torchvision==0.14.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2021.4.0           haa95532_640  
[conda] mkl-service               2.4.0            py39h2bbff1b_0  
[conda] mkl_fft                   1.3.1            py39h277e83a_0  
[conda] mkl_random                1.2.2            py39hf11a4ad_0  
[conda] numpy                     1.23.4                   pypi_0    pypi
[conda] numpy-base                1.23.5           py39h4da318b_0  
[conda] pytorch                   1.12.1          cpu_py39h5e1f01c_0  
[conda] torch                     1.13.0                   pypi_0    pypi
[conda] torchvision               0.14.0                   pypi_0    pypi

Process finished with exit code 0
```