NVIDIA / DeepLearningExamples

State-of-the-Art Deep Learning scripts organized by models - easy to train and deploy with reproducible accuracy and performance on enterprise-grade infrastructure.
13.32k stars 3.19k forks source link

Import error due to inflect #1322

Open uyuutosa opened 1 year ago

uyuutosa commented 1 year ago

Related to Tacotron2/Pytorch

Describe the bug When I run train.py on PyTorch/SpeechSynthesis/Tacotron2/, following error occured:

Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)
Traceback (most recent call last):
  File "train.py", line 44, in <module>
    import data_functions
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/data_functions.py", line 29, in <module>
    from tacotron2.data_function import TextMelCollate
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/data_function.py", line 33, in <module>
    from tacotron2.text import text_to_sequence
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/__init__.py", line 3, in <module>
    from tacotron2.text import cleaners
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/cleaners.py", line 16, in <module>
    from .numbers import normalize_numbers
  File "/workspace/benchmark/SpeechSynthesis/Tacotron2/tacotron2/text/numbers.py", line 3, in <module>
    import inflect
  File "/opt/conda/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/opt/conda/lib/python3.8/site-packages/pydantic/typing.py)

To Reproduce

When I attempted to execute the following command in conjunction with these instructions, the aforementioned error occurred.

bash scripts/train_tacotron2.sh

Expected behavior train.py works without ImportError.

Environment

Based on my investigation, it seems that this error has emerged due to a lack of backward compatibility between Pydantic 2.0 and Inflect. The issue was highlighted in this GitHub discussion and the proposed solution was to use a specific version of pydantic (1.10.10). As a result, I was able to fix the error by adding pydantic==1.10.10 to the requirements.txt file, immediately after the inflect entry, like this:

matplotlib
numpy
inflect
pydantic==1.10.10 # added
librosa
scipy
resampy==0.3.1
git+https://github.com/NVIDIA/dllogger@v0.1.0#egg=dllogger

However, to manage the version dependency more effectively, I suggest using a dependency management tool like Poetry, as it can be challenging to handle this solely through requirements.txt.