TrainingArgument does not work on colab

I was following chapter 3 of the NLP course on Fine-tuning a model with the Trainer API and when executing the command in colab

training_args = TrainingArguments(“test-trainer”)

I get:

ImportError Traceback (most recent call last)
in <cell line: 1>()
----> 1 training_args = TrainingArguments(output_dir=“test-trainer”)

4 frames
/usr/local/lib/python3.10/dist-packages/transformers/training_args.py in _setup_devices(self)
1670 if not is_sagemaker_mp_enabled():
1671 if not is_accelerate_available(min_version=“0.20.1”):
→ 1672 raise ImportError(
1673 “Using the Trainer with PyTorch requires accelerate>=0.20.1: Please run pip install transformers[torch] or pip install accelerate -U
1674 )

ImportError: Using the Trainer with PyTorch requires accelerate>=0.20.1: Please run pip install transformers[torch] or pip install accelerate -U


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
“Open Examples” button below.

I try to pip install the recommended ones but never work for me.
Help!

3 Likes

I experienced the same import error when running the following script from the hugging face transformer quick tour. Installing the 2 mentioned libraries did not resolve.

from transformers import TrainingArguments

training_args = TrainingArguments(
output_dir=“./pt_training”,
learning_rate=2e-5,
per_device_train_batch_size=8,
per_device_eval_batch_size=8,
num_train_epochs=2,
)

3 Likes

I encountered the same problem when I run the code below.

from transformers import TrainingArguments
training_args = TrainingArguments(“test-trainer”)

ERROR:Using the Trainer with PyTorch requires accelerate>=0.20.1: Please run pip install transformers[torch] or pip install accelerate -U

But installing the 2 mentioned libraries did not resolve.
I don’t know what to do now. Help!

For me help reset environment and install older transformers
!pip install transformers==4.17

3 Likes

!pip install transformers==4.17 did not resolve the import error. I forgot to mention I am running the code in Google Colab.

I’m getting the same error in the colab notebook for the NLP Course: Lesson 3 - Fine-tuning model with the Trainer API. In order to get around it you can:

  1. Run pip install accelerate -U in a cell
  2. In the top menu click RuntimeRestart Runtime
  3. Do not rerun any cells with !pip install in them
  4. Rerun all the other code cells and you should be good to go!

On a side note, be sure to turn on a GPU for this notebook by clicking EditNotebook SettingsGPU type - from the top menu. This was the next thing that got me : )

14 Likes

Has this concern been resolved?

Thanks for this, it worked for me.

Yess worked for me too! Thanks,

Thanks it worked but can you please explain this issue.

1 Like

Thank you. Because of the above workaround I fixed the error

Also works for me! Thank you!

This works in colab. Thanks a lot and greatly appreciate you!

This resolved the issue. Thanks!

Worked for me, thank you!