Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version.parse(string) throws an error while comparing versions #25669

Closed
1 of 4 tasks
riteshghorse opened this issue Aug 22, 2023 · 4 comments
Closed
1 of 4 tasks

version.parse(string) throws an error while comparing versions #25669

riteshghorse opened this issue Aug 22, 2023 · 4 comments

Comments

@riteshghorse
Copy link
Contributor

riteshghorse commented Aug 22, 2023

System Info

In the activations.py, it uses version.parse to compare the torch version which can lead to subtle error as mentioned below.

When using version.parse(str), it returns a Version object which is then sent to regex matching here. This throws an error stating

match = self._regex.search(version)
TypeError: expected string or bytes-like object

This was discovered when importing the latest pipeline of text to audio pipeline

File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/pipelines/__init__.py", line 73, in <module>
    from .text_to_audio import TextToAudioPipeline
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/pipelines/text_to_audio.py", line 22, in <module>
    from ..models.speecht5.modeling_speecht5 import SpeechT5HifiGan
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/models/speecht5/modeling_speecht5.py", line 27, in <module>
    from ...activations import ACT2FN
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/activations.py", line 250, in <module>
    mish = get_activation("mish")
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/activations.py", line 238, in get_activation
    return ACT2FN[activation_string]
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/activations.py", line 210, in __getitem__
    return cls(**kwargs)
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/activations.py", line 161, in __init__
    if version.parse(torch.__version__) < version.parse("1.9.0"):
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/packaging/version.py", line 52, in parse
    return Version(version)
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/packaging/version.py", line 196, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

Who can help?

@Narsil

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from packaging import version

version.parse(torch.__version__)

Expected behavior

instead we should do

from packaging.version import Version

Version(torch.__version__)
@ArthurZucker
Copy link
Collaborator

Hey! Thanks for reporting. Could you share a reproducer as well?

from transformers import TextToAudioPipeline

does not throw an error so curious as how you got this?

@riteshghorse
Copy link
Contributor Author

I got it in our PyDocs Precommit check

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/sphinx/ext/autodoc/importer.py", line 154, in import_module
    __import__(modname)
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/apache_beam/ml/inference/huggingface_inference.py", line 39, in <module>
    from transformers import Pipeline
  File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 1120, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_PythonDocs_Phrase/src/sdks/python/test-suites/tox/pycommon/build/srcs/sdks/python/target/.tox-py38-docs/py38-docs/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 1132, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
expected string or bytes-like object

Full link here: https://ci-beam.apache.org/job/beam_PreCommit_PythonDocs_Phrase/108/consoleText

@riteshghorse
Copy link
Contributor Author

riteshghorse commented Aug 23, 2023

actually version.parse will work just as fine but won't solve the issue here

@riteshghorse
Copy link
Contributor Author

The problem was on our end. We were mocking the torch import in autodoc which led to torch.__version__ interpreted as None and threw the error RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback): expected string or bytes-like object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants