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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wav2Vec ImportError: Please build Cython components with: pip install --editable . or python setup.py build_ext --inplace #2106

Closed
zengchang233 opened this issue May 8, 2020 · 10 comments

Comments

@zengchang233
Copy link

馃悰 Bug

Hi, thanks for your nice work! When I pretrain wav2vec model by using aishell1 dataset, an import error occurred and the error information is the following

2020-05-08 14:44:42 | INFO | fairseq_cli.train | model wav2vec, criterion BinaryCrossEntropyCriterion
2020-05-08 14:44:42 | INFO | fairseq_cli.train | num. model params: 511808 (num. trained: 511808)
2020-05-08 14:44:42 | INFO | fairseq_cli.train | training on 4 GPUs
2020-05-08 14:44:42 | INFO | fairseq_cli.train | max tokens per GPU = 1500000 and max sentences per GPU = None
2020-05-08 14:44:42 | INFO | fairseq.trainer | no existing checkpoint found /root/zengchang/models/checkpoint_last.pt
2020-05-08 14:44:42 | INFO | fairseq.trainer | loading train data for epoch 1
Traceback (most recent call last):
  File "train.py", line 11, in <module>
    cli_main()
  File "/root/zengchang/fairseq/fairseq_cli/train.py", line 355, in cli_main
    nprocs=args.distributed_world_size,
  File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 171, in spawn
    while not spawn_context.join():
  File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 118, in join
    raise Exception(msg)
Exception:

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "/root/zengchang/fairseq/fairseq/data/data_utils.py", line 220, in batch_by_size
    from fairseq.data.data_utils_fast import batch_by_size_fast
ModuleNotFoundError: No module named 'fairseq.data.data_utils_fast'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 19, in _wrap
    fn(i, *args)
  File "/root/zengchang/fairseq/fairseq_cli/train.py", line 324, in distributed_main
    main(args, init_distributed=True)
  File "/root/zengchang/fairseq/fairseq_cli/train.py", line 104, in main
    extra_state, epoch_itr = checkpoint_utils.load_checkpoint(args, trainer)
  File "/root/zengchang/fairseq/fairseq/checkpoint_utils.py", line 157, in load_checkpoint
    epoch=1, load_dataset=True, **passthrough_args
  File "/root/zengchang/fairseq/fairseq/trainer.py", line 296, in get_train_iterator
    epoch=epoch
  File "/root/zengchang/fairseq/fairseq/tasks/fairseq_task.py", line 181, in get_batch_iterator
    required_batch_size_multiple=required_batch_size_multiple,
  File "/root/zengchang/fairseq/fairseq/data/data_utils.py", line 223, in batch_by_size
    'Please build Cython components with: `pip install --editable .` '
ImportError: Please build Cython components with: `pip install --editable .` or `python setup.py build_ext --inplace`

To Reproduce

The command I ran is the following

python train.py /disk1/speech/aishell1 --save-dir /root/zengchang/models/ --num-workers 6 --fp16 --max-update 400000 --save-interval 10 --no-epoch-checkpoints --arch wav2vec --task audio_pretraining --lr 1e-06 --min-lr 1e-09 --optimizer adam --max-lr 0.005 --lr-scheduler cosine --conv-feature-layers '[(64, 10, 5), (64, 8, 4), (64, 4, 2), (64, 4, 2), (64, 4, 2), (64, 1, 1), (64, 1, 1)]' --conv-aggregator-layers '[(64, 2, 1), (64, 3, 1), (64, 4, 1), (64, 5, 1), (64, 6, 1), (64, 7, 1), (64, 8, 1), (64, 9, 1), (64, 10, 1), (64, 11, 1), (64, 12, 1), (64, 13, 1)]' --skip-connections-agg --residual-scale 0.5 --log-compression --warmup-updates 500 --warmup-init-lr 1e-07 --criterion binary_cross_entropy --num-negatives 10 --max-sample-size 150000 --max-tokens 1500000 --skip-invalid-size-inputs-valid-test

Environment

  • fairseq Version 0.9.0 from Pypi
  • PyTorch Version 1.4.0
  • OS (e.g., Linux): CentOS 7.6
  • How you installed fairseq (pip, source): pip
  • Build command you used (if compiling from source):
  • Python version: 3.7.6
  • CUDA/cuDNN version: 10.0

Additional context

Do you have any idea about this error.

I also tried to install fairseq from source, but there is error like the following

(zeng) [root@iZbp12wrkn96xlow3hmb2wZ fairseq]# pip install --editable .
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Obtaining file:///root/zengchang/tools/fairseq
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /root/anaconda3/envs/zeng/bin/python3.7 /root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-gw98n38u/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i http://mirrors.cloud.aliyuncs.com/pypi/simple/ --trusted-host mirrors.cloud.aliyuncs.com -- setuptools wheel cython
       cwd: None
  Complete output (44 lines):
  Traceback (most recent call last):
    File "/root/anaconda3/envs/zeng/lib/python3.7/runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "/root/anaconda3/envs/zeng/lib/python3.7/runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/__main__.py", line 26, in <module>
      sys.exit(_main())
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
      command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
      module = importlib.import_module(module_path)
    File "/root/anaconda3/envs/zeng/lib/python3.7/importlib/__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
      from pip._internal.cli.req_command import RequirementCommand, with_cleanup
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 16, in <module>
      from pip._internal.index.package_finder import PackageFinder
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_internal/index/package_finder.py", line 21, in <module>
      from pip._internal.index.collector import parse_links
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_internal/index/collector.py", line 14, in <module>
      from pip._vendor import html5lib, requests
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_vendor/requests/__init__.py", line 114, in <module>
      from . import utils
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_vendor/requests/utils.py", line 25, in <module>
      from . import certs
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_vendor/requests/certs.py", line 15, in <module>
      from pip._vendor.certifi import where
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_vendor/certifi/__init__.py", line 1, in <module>
      from .core import contents, where
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip/_vendor/certifi/core.py", line 12, in <module>
      from importlib.resources import read_text
    File "/root/anaconda3/envs/zeng/lib/python3.7/importlib/resources.py", line 11, in <module>
      from typing import Iterable, Iterator, Optional, Set, Union   # noqa: F401
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/typing.py", line 1357, in <module>
      class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
    File "/root/anaconda3/envs/zeng/lib/python3.7/site-packages/typing.py", line 1005, in __new__
      self._abc_registry = extra._abc_registry
  AttributeError: type object 'Callable' has no attribute '_abc_registry'
  ----------------------------------------
ERROR: Command errored out with exit status 1: /root/anaconda3/envs/zeng/bin/python3.7 /root/anaconda3/envs/zeng/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-gw98n38u/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i http://mirrors.cloud.aliyuncs.com/pypi/simple/ --trusted-host mirrors.cloud.aliyuncs.com -- setuptools wheel cython Check the logs for full command output.
@zengchang233
Copy link
Author

zengchang233 commented May 8, 2020

Updated:

I uninstalled cython and downloaded cython source code from pypi, then used the command pip install --editable . to install cython on the server. After that, I used pip install --editable . command to install fairseq from source code and it succeeded. However, when I running the training command for wav2vec model, the error still exists.

@sullivan510
Copy link

Hi, I'm facing the same issue. What was the resolution to this?

@zengchang233
Copy link
Author

Hi, I'm facing the same issue. What was the resolution to this?

Assuming cython source code directory is /path/to/cython/directory, fairseq source code directory is /path/to/fairseq/directory.

Run the following commands step by step.

mv /path/to/cython/directory /path/to/fairseq/directory
cd /path/to/fairseq/directory/cython
pip install --editable .
cd /path/to/fairseq/directory
pip install --editable .

This way can solve my problem. Good luck!

@salvacarrion
Copy link

salvacarrion commented Mar 23, 2021

It didn't work for me (fairseq-1.0.0a0+1bba712)

Update:
I fixed it by uninstalling numpy and reinstalling fairseq. It seems that there is an incompatibility between versions

@skyprince999
Copy link

skyprince999 commented Apr 24, 2021

It didn't work for me (fairseq-1.0.0a0+1bba712)

Update:
I fixed it by uninstalling numpy and reinstalling fairseq. It seems that there is an incompatibility between versions

salvacarrion
What version did you install. Could you share some more details?

UPDATE:
This is as simple as

pip uninstall numpy 
pip install numpy

I had two versions of numpy installed in my OVH instance (1.17 & 1.18) when I re-install it installs the latest version (1.20) and it works!

@Helicqin
Copy link

Hi, I'm facing the same issue. What was the resolution to this?

Assuming cython source code directory is /path/to/cython/directory, fairseq source code directory is /path/to/fairseq/directory.

Run the following commands step by step.

mv /path/to/cython/directory /path/to/fairseq/directory
cd /path/to/fairseq/directory/cython
pip install --editable .
cd /path/to/fairseq/directory
pip install --editable .

This way can solve my problem. Good luck!

Hi, thanks for your solution. While I run pip install --editable . in /path/to/fairseq/directory/cython, an error occurs:

ERROR: Command errored out with exit status 1: /home/hadoop-aipnlp/cephfs/data/anaconda3/envs/fairseq/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/hadoop-aipnlp/cephfs/data/zhaolulu/Cython-0.25.2/setup.py'"'"'; __file__='"'"'/home/hadoop-aipnlp/cephfs/data/zhaolulu/Cython-0.25.2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.

facebook-github-bot pushed a commit that referenced this issue Jul 30, 2021
Summary:
Update HuBERT decode config yaml to make compatible with the new decoder config

Pull Request resolved: fairinternal/fairseq-py#2106

Reviewed By: alexeib

Differential Revision: D29967631

Pulled By: wnhsu

fbshipit-source-id: fe39c5126f50c3024022f8333e2f3aa97065cbfc
@RashmiNagpal0311
Copy link

Or you could run python setup.py build_ext --inplace from the root fairseq directory to build the Cython components. This worked for me as I faced similar issue.

@EmreOzkose
Copy link

I uninstall numpy and install v1.23.0. Then the problem is resolved

pip uninstall numpy
pip install numpy==1.23.0

@Luoyingfeng8
Copy link

I uninstall numpy and install v1.23.0. Then the problem is resolved

pip uninstall numpy
pip install numpy==1.23.0

Thank you! It work for me!

@yinghuozijin
Copy link

I uninstall numpy and install v1.23.0. Then the problem is resolved

pip uninstall numpy
pip install numpy==1.23.0

Thanks for your sharing. And it also work for me.

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

No branches or pull requests

9 participants