DeepLearningExamples icon indicating copy to clipboard operation
DeepLearningExamples copied to clipboard

Import error due to inflect

Open uyuutosa opened this issue 2 years ago • 0 comments

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

  • Container version (e.g. pytorch:19.05-py3): nvcr.io/nvidia/pytorch:20.06-py3
  • GPUs in the system: (e.g. 8x Tesla V100-SXM2-16GB): 8xA100 80GB SXM4
  • CUDA driver version (e.g. 418.67): 525.105.17

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/[email protected]#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.

uyuutosa avatar Jul 02 '23 14:07 uyuutosa