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

ValueError: transformers.models.auto.__spec__ is None. causing import errors #15212

Closed
lucymc12 opened this issue Jan 18, 2022 · 6 comments · Fixed by #15230
Closed

ValueError: transformers.models.auto.__spec__ is None. causing import errors #15212

lucymc12 opened this issue Jan 18, 2022 · 6 comments · Fixed by #15230

Comments

@lucymc12
Copy link

Environment info

  • transformers version: 4.15.0
  • Platform: Colaboratory
  • Python version: 3.7.12

Who can help

@LysandreJik

Information

Hello, this code was working last week but today I am getting a 'ValueError: transformers.models.auto.spec is None' error which is causing errors when trying to import other Libraries. I noted a similar issue #12904 but this has been resolved and closed last year.

Model I am using (Bert, XLNet ...): BERT

The problem arises when using: Transformers

My code:

# Import all libraries
import pandas as pd
import numpy as np
import re


# Huggingface transformers
import transformers
from transformers import BertModel,BertTokenizer,AdamW, get_linear_schedule_with_warmup
print(transformers.__version__)
print(transformers.models.auto.__spec__)

import torch
from torch import nn 
from torch.utils.data import DataLoader,Dataset,RandomSampler, SequentialSampler
import pytorch_lightning as pl
from pytorch_lightning.callbacks import ModelCheckpoint

from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, precision_recall_fscore_support

import seaborn as sns
from pylab import rcParams
import matplotlib.pyplot as plt
from matplotlib import rc
%matplotlib inline

RANDOM_SEED = 42
np.random.seed(RANDOM_SEED)
torch.manual_seed(RANDOM_SEED)

import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
device = torch.device("cpu")

The Output:

4.15.0
None
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-3e575e7ee253> in <module>()
     12 from torch import nn
     13 from torch.utils.data import DataLoader,Dataset,RandomSampler, SequentialSampler
---> 14 import pytorch_lightning as pl
     15 from pytorch_lightning.callbacks import ModelCheckpoint
     16 

10 frames
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/__init__.py in <module>()
     18 _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT)
     19 
---> 20 from pytorch_lightning.callbacks import Callback  # noqa: E402
     21 from pytorch_lightning.core import LightningDataModule, LightningModule  # noqa: E402
     22 from pytorch_lightning.trainer import Trainer  # noqa: E402

/usr/local/lib/python3.7/dist-packages/pytorch_lightning/callbacks/__init__.py in <module>()
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from pytorch_lightning.callbacks.base import Callback
     15 from pytorch_lightning.callbacks.device_stats_monitor import DeviceStatsMonitor
     16 from pytorch_lightning.callbacks.early_stopping import EarlyStopping

/usr/local/lib/python3.7/dist-packages/pytorch_lightning/callbacks/base.py in <module>()
     24 
     25 import pytorch_lightning as pl
---> 26 from pytorch_lightning.utilities.types import STEP_OUTPUT
     27 
     28 

/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/types.py in <module>()
     23 from torch.optim.lr_scheduler import _LRScheduler, ReduceLROnPlateau
     24 from torch.utils.data import DataLoader
---> 25 from torchmetrics import Metric
     26 
     27 _NUMBER = Union[int, float]

/usr/local/lib/python3.7/dist-packages/torchmetrics/__init__.py in <module>()
     12 _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT)
     13 
---> 14 from torchmetrics import functional  # noqa: E402
     15 from torchmetrics.aggregation import CatMetric, MaxMetric, MeanMetric, MinMetric, SumMetric  # noqa: E402
     16 from torchmetrics.audio import (  # noqa: E402

/usr/local/lib/python3.7/dist-packages/torchmetrics/functional/__init__.py in <module>()
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from torchmetrics.functional.audio.pit import permutation_invariant_training, pit, pit_permutate
     15 from torchmetrics.functional.audio.sdr import scale_invariant_signal_distortion_ratio, sdr, signal_distortion_ratio
     16 from torchmetrics.functional.audio.si_sdr import si_sdr

/usr/local/lib/python3.7/dist-packages/torchmetrics/functional/audio/__init__.py in <module>()
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from torchmetrics.functional.audio.pit import permutation_invariant_training, pit, pit_permutate  # noqa: F401
     15 from torchmetrics.functional.audio.sdr import (  # noqa: F401
     16     scale_invariant_signal_distortion_ratio,

/usr/local/lib/python3.7/dist-packages/torchmetrics/functional/audio/pit.py in <module>()
     22 from torchmetrics.utilities import _future_warning
     23 from torchmetrics.utilities.checks import _check_same_shape
---> 24 from torchmetrics.utilities.imports import _SCIPY_AVAILABLE
     25 
     26 # _ps_dict: cache of permutations

/usr/local/lib/python3.7/dist-packages/torchmetrics/utilities/imports.py in <module>()
     90 _TQDM_AVAILABLE: bool = _module_available("tqdm")
     91 _TRANSFORMERS_AVAILABLE: bool = _module_available("transformers")
---> 92 _TRANSFORMERS_AUTO_AVAILABLE = _module_available("transformers.models.auto")
     93 _PESQ_AVAILABLE: bool = _module_available("pesq")
     94 _SACREBLEU_AVAILABLE: bool = _module_available("sacrebleu")

/usr/local/lib/python3.7/dist-packages/torchmetrics/utilities/imports.py in _module_available(module_path)
     34     """
     35     try:
---> 36         return find_spec(module_path) is not None
     37     except AttributeError:
     38         # Python 3.6

/usr/lib/python3.7/importlib/util.py in find_spec(name, package)
    112         else:
    113             if spec is None:
--> 114                 raise ValueError('{}.__spec__ is None'.format(name))
    115             return spec
    116 

ValueError: transformers.models.auto.__spec__ is None

To reproduce

Steps to reproduce the behavior:

import transformers
print(transformers.__version__)
print(transformers.models.auto.__spec__)

4.15.0
None

Expected behavior

This code ran perfectly and all Libraries were imported last week. I made no changes to this code since but it produced the above error today.

@lando22
Copy link

lando22 commented Jan 19, 2022

Having the same issue too! Exact same reproducible code + transformers version.

@arinaruck
Copy link

Same issue with transformers 4.10.0, 4.10.2 and pytorch-lightning 1.3.5

@asawczyn
Copy link

I have the same issue :(

@asawczyn
Copy link

Installing torchmetrics==0.6.2 helped in my case.

@jkuball
Copy link
Contributor

jkuball commented Jan 19, 2022

Seems like this PR needs to be copied for this line of code.

@LorenzoMauri
Copy link

Installing torchmetrics==0.6.2 helped in my case.

On G.Colab I had the same issue with transformers==4.15.0 and pytorch_lightning==1.5.7 installed.

Solved by installing torchmetrics==0.6.2 .

Thank you

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.

6 participants