-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Speedup module imports #26308
Comments
I am indeed using main (specifically, |
The code I mentioned above is run directly in the header of transformers/src/transformers/trainer.py Lines 203 to 217 in e3a4bd2
|
Cc @younesbelkada I think you mentioned that accelerate is the bottleneck that we can’t get rid of no? |
Hi @apoorvkh |
Hey, thanks! I think that commit (huggingface/accelerate@5dec654) reduces the runtime for the import from 8-9 seconds to 3-4 seconds (on my machine). That is still not ideal but is certainly more tolerable. |
Thanks! # benchmark
python -X importtime -c "import transformers" 2> transformers-import-profile.log
# visualize
tuna <path to log file> |
For sure. That's a nice tool! Really quickly, I found that We can see the result for Also, for And we can compare to Seems like My point is that we sometimes just import these tools for typing purposes or in an interactive terminal for later use. From a developer perspective, it would be more convenient to have fast imports and move the time-consuming parts to the moment we actually want to init/use the modules (and are actually expecting to expend time). Thanks! |
from transformers import Trainer
)
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
Feature request
Can we please consider importing the deepspeed module when needed, rather than in the import header of
trainer.py
?Motivation
When
deepspeed
is installed,from transformers import Trainer
takes a long time!On my system that's 9 seconds!
I believe this import is the culprit. As we can see, it takes 8.5 seconds of the load time.
transformers/src/transformers/trainer.py
Line 217 in e3a4bd2
This is quite cumbersome, because all scripts that import Trainer (e.g. even for typing) are impacted!
Your contribution
Happy to submit a PR. We could make this a class variable or just import it directly at both places it's used.
transformers/src/transformers/trainer.py
Lines 2437 to 2439 in e3a4bd2
transformers/src/transformers/trainer.py
Lines 2508 to 2514 in e3a4bd2
The text was updated successfully, but these errors were encountered: