Search code examples
pythonpipartificial-intelligencehuggingface-transformers

Can't import AdapterTrainer


I'm trying text classification with adapters in google colab and faced a lot of problems with libs.

!pip install -U adapter-transformers 

from transformers import TrainingArguments, AdapterTrainer, EvalPrediction

gives an error:

RuntimeError: Failed to import transformers.adapters.trainer because of the following error (look up to see its traceback):
Failed to import transformers.trainer_seq2seq because of the following error (look up to see its traceback):
cannot import name 'default_hp_search_backend' from 'transformers.integrations' (/usr/local/lib/python3.10/dist-packages/transformers/integrations/__init__.py)

Most confusing part is that I already ran this notebook earlier.

I've tried a lot of manipulations with libraries:

installed using git, deleted and installed different parts.


Solution

  • You probably already have transformers installed. adapter-transformers⚠️ is a fork of the transformers library and can't be installed in the same environment:

    adapter-transformers is a direct fork of transformers. This means our package includes all the awesome features of HuggingFace’s original package, plus the adapter implementation. As both packages share the same namespace, they ideally should not be installed in the same environment.

    Note: The adapter-transformers package is deprecated and replaced by the adapters package. Install it using :

    pip install adapters
    

    You need to import the AdapterTrainer from adapters instead of transformers (transitioning) :

    from transformers import TrainingArguments, EvalPrediction
    from  adapters import AdapterTrainer
    

    See see here for more informations.