Search code examples
pythontensorflowmachine-learningnlphuggingface-transformers

Error running run_seq2seq.py Transformers training script


I am trying to train a seq2seq model. I ran the example code in Colab:

!git clone https://github.com/huggingface/transformers
!git clone https://github.com/huggingface/datasets
!pip install transformers
!pip install datasets
!python transformers/examples/seq2seq/run_seq2seq.py \
    --model_name_or_path t5-small \
    --do_train \
    --do_eval \
    --task summarization \
    --dataset_name xsum \
    --output_dir /tmp/tst-summarization \
    --per_device_train_batch_size=4 \
    --per_device_eval_batch_size=4 \
    --overwrite_output_dir \
    --predict_with_generate \
    --max_train_samples 500 \
    --max_val_samples 500

and got this error

I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
Traceback (most recent call last):
  File "transformers/examples/seq2seq/run_seq2seq.py", line 47, in <module>
    from transformers.file_utils import is_offline_mode
ImportError: cannot import name 'is_offline_mode' from 'transformers.file_utils' (/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py)

Any ideas?


Solution

  • The problem is that you clone the master branch of the repository and try to run the run_seq2seq.py script with a transformers version (4.3.3) that is behind that master branch.

    run_seq2seq.py was updated to import is_offline_mode on the 6th of march with this merge.

    All you need to do is to clone the branch that was used for your used transformers version:

    !git clone --branch v4.3.3-release https://github.com/huggingface/transformers
    

    P.S.: I do not think you need to clone the dataset library.