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

Fairseq Import Error #217

Closed
JefferyO opened this issue Aug 29, 2022 · 4 comments
Closed

Fairseq Import Error #217

JefferyO opened this issue Aug 29, 2022 · 4 comments

Comments

@JefferyO
Copy link

Hi,

Thanks for your great work! I followed the README to run run_scripts/caption/evaluate_caption.sh and encountered the following error:

Traceback (most recent call last):
  File "../../evaluate.py", line 13, in <module>
    from fairseq import distributed_utils, options, tasks, utils
  File "/usr/home/workspace/OFA/fairseq/fairseq/tasks/__init__.py", line 15, in <module>
    from .fairseq_task import FairseqTask, LegacyFairseqTask  # noqa
  File "/usr/home/workspace/OFA/fairseq/fairseq/tasks/fairseq_task.py", line 13, in <module>
    from fairseq import metrics, search, tokenizer, utils
ImportError: cannot import name 'metrics' from 'fairseq' (unknown location)

The Fairseq is installed with the one provided in your repo as required, however, when I changed to the official release (e.g. 0.12.2, which I understand is not appropriate as you have modified fairseq for OFA specifically, just for testing), the error disappeared.

So I'm wondering have you ever encountered any similar issue or if I stupidly missed anything when setting things up?

FYI, my git clone status:

git show HEAD
commit c8313b9e8e4cf4f4df693e96848d337ed74ab68d (HEAD -> main, origin/main, origin/HEAD)

Your answer will be very appreciated!

@JustinLin610
Copy link
Member

I met this once, and it attributes to my installation. Maybe you should be make sure the old one is totally uninstalled before you install our version of Fairseq.

@JefferyO
Copy link
Author

Thanks for the reply! I tried to uninstall everything and reinstall them, but the same error still emerged. However, when I tried to install a non-editable version of the repo-embedded fairseq, it worked error-free. Will stick to this solution atm, probably get back to this when necessary (e.g. want to make further modifications to the fairseq scripts)

@spetryk
Copy link

spetryk commented Sep 3, 2022

TL;DR: Changing the pip version to 21.2.4 might help.

I was having the same issue. I was especially confused, because I had been running OFA scripts within a conda env I created a month or so ago, and everything was working fine. Yet I recently created a new conda env, followed the OFA installation instructions again, and ran into the same error that JefferyO described.

After lots of uninstalling & reinstalling with various settings, I think the issue for me was the version of pip - at the moment, the latest pip version is 22.1.2, yet the version I used previously was 21.2.4. I changed the version, uninstalled fairseq & re-installed the requirements.txt, and now running evaluate_caption.sh works with the correct imports. I'm not sure why this worked; I didn't try to dig any further once it was working. I also didn't try the non-editable version.

Specifically, here are the steps I ran, within the OFA repo:

conda create --name ofa python=3.7.4    # I initially used python=3.9.12, but found that switching to 3.7.4 as recommended didn't matter for this error in particular
conda activate ofa
pip --version    # 22.1.2
pip install -r requirements.txt
cd run_scripts/caption
sh evaluate_caption.sh     # Errors out with fairseq metrics import error

python -m pip install pip==21.2.4
pip uninstall fairseq
cd ../../
pip install -r requirements.txt
cd run_scripts/caption
sh evaluate_caption.sh    # No longer any import errors

And my current git clone status:

git show HEAD
commit cd96d5c44b189b47c6fe8cff27068d7b1c9ae072 (HEAD -> main, origin/main, origin/HEAD)

Hope this helps!

@JefferyO
Copy link
Author

JefferyO commented Sep 3, 2022

Hey @spetryk , thanks so much for the suggestions! I think I was in the same condition as my pip version was also 22.1.2. And after downgrading to pip==21.2.4 and reinstalling everything following your steps, it works for me!

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

No branches or pull requests

4 participants