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

Error importing torchmetrics #770

Closed
daavoo opened this issue Jan 17, 2022 · 2 comments · Fixed by #772
Closed

Error importing torchmetrics #770

daavoo opened this issue Jan 17, 2022 · 2 comments · Fixed by #772
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Milestone

Comments

@daavoo
Copy link

daavoo commented Jan 17, 2022

🐛 Bug

When transformers.models.auto is imported somewhere before torchmetrics, the following error is raised: ValueError: transformers.models.auto.__spec__ is None.

I believe this is caused by how transformers lazyly adds this module to sys.modules combined to how torchmetrics checks for it's availability with _module_available.

This causes find_spec to raise an uncatched ValueError, introduced in #739 with _TRANSFORMERS_AUTO_AVAILABLE = _module_available("transformers.models.auto")

To Reproduce

Steps to reproduce the behavior:

  1. pip install transformers
  2. pip install torchmetrics
  3. python -c "from transformers.models import auto; from torchmetrics import Metric"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "envs/test-spec/lib/python3.7/site-packages/torchmetrics/__init__.py", line 14, in <module>
    from torchmetrics import functional  # noqa: E402
  File "envs/test-spec/lib/python3.7/site-packages/torchmetrics/functional/__init__.py", line 14, in <module>
    from torchmetrics.functional.audio.pit import permutation_invariant_training, pit, pit_permutate
  File "envs/test-spec/lib/python3.7/site-packages/torchmetrics/functional/audio/__init__.py", line 14, in <module>
    from torchmetrics.functional.audio.pit import permutation_invariant_training, pit, pit_permutate  # noqa: F401
  File "envs/test-spec/lib/python3.7/site-packages/torchmetrics/functional/audio/pit.py", line 24, in <module>
    from torchmetrics.utilities.imports import _SCIPY_AVAILABLE
  File "envs/test-spec/lib/python3.7/site-packages/torchmetrics/utilities/imports.py", line 92, in <module>
    _TRANSFORMERS_AUTO_AVAILABLE = _module_available("transformers.models.auto")
  File "envs/test-spec/lib/python3.7/site-packages/torchmetrics/utilities/imports.py", line 36, in _module_available
    return find_spec(module_path) is not None
  File "envs/test-spec/lib/python3.7/importlib/util.py", line 117, in find_spec
    raise ValueError('{}.__spec__ is None'.format(name))
ValueError: transformers.models.auto.__spec__ is None

Expected behavior

No exception being raised.

Environment

  • PyTorch Version (e.g., 1.0): 1.10.1'
  • OS (e.g., Linux): MacOS
  • How you installed PyTorch (conda, pip, source): pip
  • Python version: 3.7, 3.8, 3.9, 3.10
@daavoo daavoo added bug / fix Something isn't working help wanted Extra attention is needed labels Jan 17, 2022
@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@Borda Borda added this to the v0.7 milestone Jan 17, 2022
@Borda
Copy link
Member

Borda commented Jan 17, 2022

that is interesting, I can replicate it and it is about this combination in a single python call, in contrast, if I call them separately everything works fine:

python -c "from transformers.models import auto"
python -c "from torchmetrics import Metric"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants