Skip to content

[Bug]: torch version check in STFT #1886

Description

@grazder

Describe the bug

Here is check:

if version.parse(torch.__version__) <= version.parse("1.6.0"):

I don't understand the meaning of this because you have torch>=1.9 in the requirements

"torch>=1.9",

So this if seems useless

Expected behaviour

I expected that there would be no such check, because defined to support torch>=1.9.0

To Reproduce

Plus it is became a problem for scripting Fbank (my local error):

torch.jit.frontend.UnsupportedNodeError: try blocks aren't supported:
  File "/opt/conda/lib/python3.9/site-packages/packaging/version.py", line 48
    a valid PEP 440 version or a legacy version.
    """
    try:
    ~~~ <--- HERE
        return Version(version)
    except InvalidVersion:

because version is using try-catch

and error in colab:

import torch
from speechbrain.lobes.features import Fbank

fbank = Fbank(sample_rate=8000, n_fft=512, n_mels=64, left_frames=0, right_frames=0, deltas=False)
torch.jit.script(fbank)
RuntimeError: 
'__torch__.packaging.version.Version (of Python compilation unit at: 0x6dd2a30)' object has no attribute or method '_regex'. '_regex' is defined as a class attribute which currently is not supported. Consider converting this to an instance attribute.:
  File "/usr/local/lib/python3.9/dist-packages/packaging/version.py", line 195
    
        # Validate the version and parse it into pieces
        match = self._regex.search(version)
                ~~~~~~~~~~~ <--- HERE
        if not match:
            raise InvalidVersion(f"Invalid version: '{version}'")
'Version.__init__' is being compiled since it was called from '__torch__.packaging.version.Version'
  File "/usr/local/lib/python3.9/dist-packages/packaging/version.py", line 43
def parse(version: str) -> "Version":
                           ~~~~~~~~ <--- HERE
    """Parse the given version string.
'__torch__.packaging.version.Version' is being compiled since it was called from 'parse'
  File "/usr/local/lib/python3.9/dist-packages/packaging/version.py", line 43
def parse(version: str) -> "Version":
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    """Parse the given version string.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    >>> parse('1.0.dev1')
    ~~~~~~~~~~~~~~~~~~~~~
    <Version('1.0.dev1')>
    ~~~~~~~~~~~~~~~~~~~~~

    :param version: The version string to parse.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    :raises InvalidVersion: When the version string is not a valid version.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    """
    ~~~
    return Version(version)
    ~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
'parse' is being compiled since it was called from 'STFT.forward'
  File "/usr/local/lib/python3.9/dist-packages/speechbrain/processing/features.py", line 148
            x = x.reshape(or_shape[0] * or_shape[2], or_shape[1])
    
        if version.parse(torch.__version__) <= version.parse("1.6.0"):
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
            stft = torch.stft(
                x,

Without this check, the model scripts well

Versions

speechbrain=0.5.13
torch=1.13.1+cu116

Relevant log output

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions