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

[Enhance] Remove unnecessary calls and lazily import to speed up import performance #837

Merged
merged 6 commits into from
Jan 13, 2023

Conversation

zhouzaida
Copy link
Collaborator

@zhouzaida zhouzaida commented Dec 19, 2022

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Speed the performance when calling import mmengine.runner.

Using pyinstrument to test the difference in performance.

  • Before this PR

image

  • After this PR

image

Modification

  1. Remove unnecessary calls to speed import performance

    BuildExtension, CppExtension, CUDAExtension = _get_extension()

    The above line heavily slows the import performance and this line is not necessary. Therefore, remove this line.

  2. Layily import torchvision, matplotlib, and pkg_resources to speed the import performance.

BC-breaking (Optional)

No

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@zhouzaida zhouzaida requested a review from HAOCHENYE as a code owner December 19, 2022 08:03
@zhouzaida zhouzaida marked this pull request as draft December 19, 2022 08:03
@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Base: 78.66% // Head: 78.74% // Increases project coverage by +0.08% 🎉

Coverage data is based on head (79d3768) compared to base (fe26c65).
Patch coverage: 48.71% of modified lines in pull request are covered.

❗ Current head 79d3768 differs from pull request most recent head 9ef6e17. Consider uploading reports for the commit 9ef6e17 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #837      +/-   ##
==========================================
+ Coverage   78.66%   78.74%   +0.08%     
==========================================
  Files         128      128              
  Lines        9348     9374      +26     
  Branches     1848     1859      +11     
==========================================
+ Hits         7354     7382      +28     
+ Misses       1679     1678       -1     
+ Partials      315      314       -1     
Flag Coverage Δ
unittests 78.74% <48.71%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmengine/optim/optimizer/zero_optimizer.py 52.17% <0.00%> (-4.97%) ⬇️
mmengine/registry/build_functions.py 80.20% <ø> (ø)
mmengine/registry/default_scope.py 100.00% <ø> (ø)
mmengine/structures/base_data_element.py 93.65% <ø> (ø)
mmengine/utils/dl_utils/parrots_wrapper.py 44.77% <ø> (-3.76%) ⬇️
mmengine/visualization/vis_backend.py 84.49% <ø> (ø)
mmengine/runner/checkpoint.py 51.75% <10.71%> (+7.79%) ⬆️
mmengine/model/weight_init.py 35.63% <33.33%> (+0.12%) ⬆️
mmengine/visualization/utils.py 69.04% <42.85%> (-4.45%) ⬇️
mmengine/utils/package_utils.py 47.05% <50.00%> (-2.95%) ⬇️
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@zhouzaida zhouzaida changed the title [Enhance] Remove unnecessary calls to speed import performance [Enhance] Remove unnecessary calls and lazily import to speed import performance Dec 21, 2022
@zhouzaida zhouzaida marked this pull request as ready for review January 3, 2023 08:29
@HAOCHENYE HAOCHENYE added this to the 0.5.0 milestone Jan 12, 2023
@zhouzaida zhouzaida merged commit c89d4ef into open-mmlab:main Jan 13, 2023
@zhouzaida zhouzaida deleted the speed-import-performance branch January 13, 2023 02:17
@HAOCHENYE HAOCHENYE changed the title [Enhance] Remove unnecessary calls and lazily import to speed import performance [Enhance] Remove unnecessary calls and lazily import to speed up import performance May 25, 2023
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.

2 participants