asteroid-team / asteroid-team/asteroid

error while converting complex models to onnx model (caused by view_as_complex)

Open
#529 6 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Python
Stars
2.6k
Forks
450
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug

While exporting to onnx some of the models (with complex operation).
There is error caused by no support of complex casting in the onnx ops set
torch.view_as_complex(input))

### To Reproduce
```
torch.onnx.export(model_dccrn, input_random, 'model_dccrn.onnx', verbose=True, opset_version=11)
```
Steps to reproduce the behavior (code sample and stack trace):

```
~/lib/miniconda3/lib/python3.9/site-packages/torch/onnx/symbolic_registry.py in get_registered_op(opname, domain, version)
114 else:
115 msg += "Please feel free to request support or submit a pull request on PyTorch GitHub."
--> 116 raise RuntimeError(msg)
117 return _registry[(domain, version)][opname]

RuntimeError: Exporting the operator view_as_complex to ONNX opset version 12 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.
```

### Expected behavior

The convertion should proceed without errors and end with proper onnx model.

### Environment

#### Package versions

Run `asteroid-versions` and paste the output here:

```
Asteroid 0.5.1
PyTorch 1.9.0
PyTorch-Lightning 1.3.8
```

#### Additional info

I know it is not set case in pytorch-onnx ops set

ONNX current operations:
- https://github.com/onnx/onnx/blob/master/docs/Operators.md
- in part for Cast
- > Casting to complex is not supported.

issues with errors:
- error with support view_as_complex for converting to onnx model
- view_as_complex https://pytorch.org/docs/stable/generated/torch.view_as_complex.html
- https://github.com/onnx/onnx/issues/3173
- https://github.com/pytorch/pytorch/issues/49793

However, we can propose a wrapper that is covering this convertion in such a way that onnx model will be created properly.


view_as_complex is implemented in ATen library
- https://github.com/pytorch/pytorch/blob/30e48bbeae545c3292c2ab3fed0cb2dba4a92fed/aten/src/ATen/native/ComplexHelper.h#L70
`
const auto new_strides = computeStrideForViewAsComplex(self.strides());
const auto complex_type = c10::toComplexType(self.scalar_type());
view_tensor(self, complex_type, new_storage_offset, new_sizes, new_strides);
`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with model_dccrn, torch.onnx.export, and the reported PyTorch 1.9.0 environment at opset 11. Read the linked PyTorch ComplexHelper implementation and the referenced ONNX and PyTorch issues to determine whether a compatible conversion is possible. Done means exporting the complex-operation model without errors and producing a valid ONNX model.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.