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

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

Closed
2 of 4 tasks
smyousaf1 opened this issue Feb 21, 2024 · 7 comments · Fixed by huggingface/notebooks#483 or #29947

Comments

@smyousaf1
Copy link

System Info

transformers_version -> (4.35.2)
Environment -> Google Colab

Who can help?

smyousaf1

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction


ImportError Traceback (most recent call last)
in <cell line: 1>()
----> 1 training_args = TrainingArguments(
2 output_dir="my_awesome_food_model",
3 remove_unused_columns=False,
4 evaluation_strategy="epoch",
5 save_strategy="epoch",

4 frames
/usr/local/lib/python3.10/dist-packages/transformers/training_args.py in _setup_devices(self)
1785 if not is_sagemaker_mp_enabled():
1786 if not is_accelerate_available(min_version="0.20.1"):
-> 1787 raise ImportError(
1788 "Using the Trainer with PyTorch requires accelerate>=0.20.1: Please run pip install transformers[torch] or pip install accelerate -U"
1789 )

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

Expected behavior

I expected it to Train but it produced an error in training segment.

@amyeroberts
Copy link
Collaborator

Hi @smyousaf1, have you tried upgrading the installed version of accelerate in your environment as indicated by the error message?

@aghie
Copy link

aghie commented Feb 29, 2024

I'm facing the same error on the colab example (with the pytorch implementation): https://huggingface.co/docs/transformers/tasks/sequence_classification .

The pip command for accelerate is missing, but after including it and installing accelerate, the error keeps showing up, not sure why. Seems like the tutorial could be outdated? I'm my local computer I managed to make it work.

@amyeroberts
Copy link
Collaborator

@aghie Are you refreshing the notebook session? If you're updating accelerate after already importing it (or it being used by another library) in the same session it will use still use the old version, incompatible version. You should start from a fresh notebook session and install accelerate in one of the first cells.

@aghie
Copy link

aghie commented Mar 1, 2024

Thanks @amyeroberts! I was trying that initially but kept getting the error, but it did work after I made a separate copy of the notebook.

Do you think it would be possible to update the tutorial? In its current form, it appears odd to run a pip command to install transformers and datasets, only to later find that modifying the notebook to include a second pip command for installing accelerate (and evaluate) is necessary. This only happen in the pytorch version.

@amyeroberts
Copy link
Collaborator

Sure! Would you like to open a PR to update to include installing accelerate and evaluate? This way you get the github contribution.

@MariaHei
Copy link
Contributor

Hi, I've replicated this issue in both of the notebooks mentioned above and I'd like to take on this issue :)

@amyeroberts
Copy link
Collaborator

@MariaHei Great!

In general, we prioritize based on PRs open, rather than comments on issues. If there's an issue without an open and active PR open, you're free to start work on it :) We find this prevents issues from becoming stale.

MariaHei added a commit to MariaHei/notebooks that referenced this issue Mar 28, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface/transformers#29174
MariaHei added a commit to MariaHei/notebooks that referenced this issue Mar 28, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface/transformers#29174
MariaHei added a commit to MariaHei/transformers that referenced this issue Mar 28, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface#29174
MariaHei added a commit to MariaHei/transformers that referenced this issue Mar 28, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface#29174
stevhliu pushed a commit that referenced this issue Mar 28, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves #29174
MariaHei added a commit to MariaHei/notebooks that referenced this issue Apr 2, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface/transformers#29174
amyeroberts pushed a commit to huggingface/notebooks that referenced this issue Apr 3, 2024
* Update installs in pytorch text+image classification notebooks

Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface/transformers#29174

* medusa (#485)

* Update installs in pytorch text+image classification notebooks

Trainer with PyTorch now requires accelerate to be installed.

Partly resolves huggingface/transformers#29174

* improve language in image_classification notebook

* remove changes to sagemaker NB

---------

Co-authored-by: Philipp Schmid <32632186+philschmid@users.noreply.github.com>
amyeroberts pushed a commit that referenced this issue Apr 8, 2024
….20.1 Fix (#29888)

* ImportError: Trainer with PyTorch requires accelerate>=0.20.1 Fix

Adding the evaluate and accelerate installs at the beginning of the cell to fix the issue

* ImportError Fix: Trainer with PyTorch requires accelerate>=0.20.1

* Import Error Fix

* Update installation.md

* Update quicktour.md

* rollback other lang changes

* Update _config.py

* updates for other languages

* fixing error

* Tutorial Update

* Update tokenization_utils_base.py

* Just use an optimizer string to pass the doctest?

---------

Co-authored-by: Matt <rocketknight1@gmail.com>
ArthurZucker pushed a commit that referenced this issue Apr 22, 2024
….20.1 Fix (#29888)

* ImportError: Trainer with PyTorch requires accelerate>=0.20.1 Fix

Adding the evaluate and accelerate installs at the beginning of the cell to fix the issue

* ImportError Fix: Trainer with PyTorch requires accelerate>=0.20.1

* Import Error Fix

* Update installation.md

* Update quicktour.md

* rollback other lang changes

* Update _config.py

* updates for other languages

* fixing error

* Tutorial Update

* Update tokenization_utils_base.py

* Just use an optimizer string to pass the doctest?

---------

Co-authored-by: Matt <rocketknight1@gmail.com>
itazap pushed a commit that referenced this issue May 14, 2024
Trainer with PyTorch now requires accelerate to be installed.

Partly resolves #29174
itazap pushed a commit that referenced this issue May 14, 2024
….20.1 Fix (#29888)

* ImportError: Trainer with PyTorch requires accelerate>=0.20.1 Fix

Adding the evaluate and accelerate installs at the beginning of the cell to fix the issue

* ImportError Fix: Trainer with PyTorch requires accelerate>=0.20.1

* Import Error Fix

* Update installation.md

* Update quicktour.md

* rollback other lang changes

* Update _config.py

* updates for other languages

* fixing error

* Tutorial Update

* Update tokenization_utils_base.py

* Just use an optimizer string to pass the doctest?

---------

Co-authored-by: Matt <rocketknight1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants