feature: added import complexity checker#45013
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Not super clear too me, this depends on the environment, no? I mean, say in our .[dev] environment which has almost everything, |
The test will do an when you install |
LysandreJik
left a comment
There was a problem hiding this comment.
Love it, and aligned with the direction. Thanks Tarek!
| """Check that `import transformers` does not pull in too many modules. | ||
|
|
||
| Traces the full import tree triggered by `import transformers` using a custom | ||
| ``importlib.abc.MetaPathFinder`` and counts every module that gets loaded. | ||
| If the count exceeds ``MAX_IMPORT_COUNT`` the check fails, signalling a | ||
| potential regression in import speed. | ||
|
|
||
| Usage: | ||
| python utils/check_import_complexity.py # CI check mode | ||
| python utils/check_import_complexity.py --display # show the full import tree |
| if is_torch_available(): | ||
| from torch import Tensor |
There was a problem hiding this comment.
quite surprised, there are fewer offending torch import statements than I would have thought!
0940ea4 to
b7fd8f6
Compare
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45013&sha=b7fd8f |
* added import complexity checker * lazy torch * lower the threashold * simplified checks * raise threshold
* added import complexity checker * lazy torch * lower the threashold * simplified checks * raise threshold
What does this PR do?
make chek-repothat willimport transformersand count the number of imported module.import transformersThe change will reduce the import time from ~1.5s to ~0.7s (+3000 modules to 619 modules)
The checker will error out when it goes over a threshold - for instance if our code imports a lib like
torchnot lazilyThis will prevent imports slowdowns regression.
Can be used directly to display the import counts and import tree: