asteroid-team / asteroid-team/asteroid

BaseEncoderMaskerDecoder instance cannot be converted to TorchScript?

Open
#646 2 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

When trying to convert a pre-trained instance of `BaseEncoderMaskerDecoder` to TorchScript a `RuntimeError` is thrown, seemingly because of incompatible code inside `asteroid`'s `Conv1DBlocks` class.

### To Reproduce

Run this bit of code where `asteroid` v0.6.0 is installed:
```
from asteroid.models.base_models import BaseEncoderMaskerDecoder

model = BaseEncoderMaskerDecoder.from_pretrained("JorisCos/ConvTasNet_Libri3Mix_sepnoisy_16k")
model_scripted = torch.jit.script(model)
```

### Expected behavior
`model_scripted` should contain the TorchScript equivalent of the model.

### Actual behavior
A `RuntimeError` is raised from the last line of code:
```
Previous return statement returned a value of type Tensor but this return statement returns a value of type Tuple[Tensor, Tensor]:
File "C:\dev\github\SilentiumIsrael\ResearchML\.venv\lib\site-packages\asteroid\masknn\convolutional.py", line 97
return res_out
skip_out = self.skip_conv(shared_out)
return res_out, skip_out
~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
```

Examining https://github.com/asteroid-team/asteroid/blob/v0.6.0/asteroid/masknn/convolutional.py#L90 indeed shows two `return` statements each returning a different type.

### Environment

#### Package versions

```
Asteroid 0.6.0
PyTorch 1.9.0+cpu
PyTorch-Lightning 1.7.7
```

#### Additional info

Reproduced on Windows with Python 3.9.6.

Contributor guide

Open the contributing guide

Research direction

Start with asteroid/masknn/convolutional.py around line 90 and reproduce the provided torch.jit.script(model) call using the listed package versions. Inspect the two return paths in Conv1DBlocks and verify that the reported RuntimeError is resolved when the pre-trained BaseEncoderMaskerDecoder can be scripted successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.