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

[core] Import tensorflow inside relevant methods in trainer_utils #26106

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

younesbelkada
Copy link
Contributor

@younesbelkada younesbelkada commented Sep 12, 2023

What does this PR do?

Imports tensorflow inside relevant methods in trainer_utils.
When Deepspeed and accelerate are available in your env, it will try to import transformers all the way down to https://github.com/huggingface/transformers/blob/main/src/transformers/trainer_utils.py#L49

Leading to considerable slowdowns in import time

Screenshot 2023-09-12 at 10 48 50

This PR imports tensorflow inside the relevant methods so that it will never get globally imported by transformers anymore.
If this patch gets applied, there is no speedup, however this can be fixed by lazy loading TF in accelerate itself:

Screenshot 2023-09-12 at 10 49 26

cc @amyeroberts @patrickvonplaten @pacman100 @muellerzr @SunMarc

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 12, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

@younesbelkada younesbelkada merged commit 18abc75 into huggingface:main Sep 12, 2023
@younesbelkada younesbelkada deleted the finish-lazy-import branch September 12, 2023 09:49
parambharat pushed a commit to parambharat/transformers that referenced this pull request Sep 26, 2023
…huggingface#26106)

import tensorflow inside relevant methods in trainer_utils
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 this pull request may close these issues.

3 participants