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

Bug: ImportError: cannot import name 'get_class_name' from partially initialized module 'openspeech.utils' #116

Closed
Jxu-Thu opened this issue Oct 23, 2021 · 4 comments · Fixed by #118

Comments

@Jxu-Thu
Copy link

Jxu-Thu commented Oct 23, 2021

Hi, Thanks for your great codes.

I followed the readme to install the packages.

Torch 1.6.0
CUDA 10.1
Python 3.8

Code Branch: Master

And Run

DATASET_PATH=data/LibriSpeech_raw
MANIFEST_FILE_PATH=data/LibriSpeech_raw/openspeech/libri_character_manifest.txt
VOCAB_PARH=data/LibriSpeech_raw/openspeech/libri_labels.csv

CUDA_VISIBLE_DEVICES=1 python ./openspeech_cli/hydra_train.py
dataset=librispeech
dataset.dataset_download=True
dataset.dataset_path=$DATASET_PATH
dataset.manifest_file_path=$MANIFEST_FILE_PATH
tokenizer=libri_character
model=conformer_transducer
vocab_path=$VOCAB_PARH
audio=fbank
lr_scheduler=warmup_reduce_lr_on_plateau
trainer=gpu-fp16
criterion=transducer

And encounterd errors as below:

File "./openspeech_cli/hydra_train.py", line 30, in
from openspeech.tokenizers import TOKENIZER_REGISTRY
File "openspeech-main/openspeech/init.py", line 23, in
import openspeech.criterion
File "openspeech-main/openspeech/criterion/init.py", line 70, in
module = importlib.import_module(f"openspeech.criterion.{file}.{python_file}")
File "/home/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "openspeech-main/openspeech/criterion/ctc/ctc.py", line 29, in
from ...tokenizers.tokenizer import Tokenizer
File "openspeech-main/openspeech/tokenizers/init.py", line 69, in
module = importlib.import_module(f"openspeech.tokenizers.{file}.{tokenizer_name}")
File "/home/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "openspeech/tokenizers/librispeech/subword.py", line 28, in
from openspeech.datasets.librispeech.preprocess.subword import SENTENCEPIECE_MODEL_NAME
File "openspeech-main/openspeech/datasets/init.py", line 60, in
module = importlib.import_module(f"openspeech.datasets.{file}.{data_module_name}")
File "python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "openspeech-main/openspeech/datasets/aishell/lit_data_module.py", line 31, in
from openspeech.data.audio.dataset import SpeechToTextDataset
File "openspeech-main/openspeech/data/init.py", line 71, in
module = importlib.import_module(f"openspeech.data.audio.{file}.{module_name}")
File "/home/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "openspeech-main/openspeech/data/audio/mfcc/mfcc.py", line 28, in
from ....utils import LIBROSA_IMPORT_ERROR
File "openspeech-main/openspeech/utils.py", line 33, in
from .models import OpenspeechModel
File "openspeech-main/openspeech/models/init.py", line 27, in
from .openspeech_encoder_decoder_model import OpenspeechEncoderDecoderModel
File "openspeech-main/openspeech/models/openspeech_encoder_decoder_model.py", line 29, in
from openspeech.utils import get_class_name
ImportError: cannot import name 'get_class_name' from partially initialized module 'openspeech.utils' (most likely due to a circular import) (openspeech-main/openspeech/utils.py)

@Jxu-Thu
Copy link
Author

Jxu-Thu commented Oct 23, 2021

I make sure that I have installed everything as follows:


conda create -n acent_asr python=3.8
source activate acent_asr
sudo apt-get install libsndfile1 -y
#conda install -c pytorch torchaudio -y
#conda install -c conda-forge librosa -y

pip install --ignore-installed llvmlite
pip install librosa
pip install torch-1.6.0+cu101-cp38-cp38-linux_x86_64.whl
pip install torchaudio==0.6.0
pip install sentencepiece
pip install pytorch-lightning
pip install hydra-core --upgrade

install rnnt

git clone https://github.com/1ytic/warp-rnnt
cd warp-rnnt/pytorch_binding
python setup.py install
cd ../..
git clone --recursive https://github.com/parlance/ctcdecode.git
cd ctcdecode && pip install .
cd -
pip install openspeech-core

#sudo mkdir /opt/miniconda/pkgs/
#sudo touch /opt/miniconda/pkgs/urls.txt
#pip install librosa --user

install apex

cd apex
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
cd -

pip install -e .


@Jxu-Thu
Copy link
Author

Jxu-Thu commented Oct 23, 2021

I try 0.2.1 and find the code can run. so the bug is caused in 0.3.0 version (Master)

@Jxu-Thu
Copy link
Author

Jxu-Thu commented Oct 23, 2021

After carefully checking the codes, I find that deleting

from .models import OpenspeechModel
from .modules import Linear

from the openspeech/utils.py enable the normal running.

Hope to fix the bug for other users :)

@upskyy
Copy link
Member

upskyy commented Oct 24, 2021

I'll fix the bug. Thank you !

upskyy added a commit that referenced this issue Oct 24, 2021
@upskyy upskyy mentioned this issue Oct 24, 2021
upskyy added a commit that referenced this issue Oct 24, 2021
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