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

[Feature] Add configurations to support torch.compile in Runner #976

Merged
merged 12 commits into from Mar 12, 2023

Conversation

C1rN09
Copy link
Collaborator

@C1rN09 C1rN09 commented Mar 2, 2023

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

Support torch.compile introduced in PyTorch 2.0

Modification

Check for compile keyword in config dict. If not None, will call torch.compile according to its options.

BC-breaking (Optional)

No

Use cases (Optional)

Add a single line (or a few lines) in your config file.

Basic Use Cases

# recommended
compile = True
# equivalent to the following code
# self.model.train_step = torch.compile(self.model.train_step)

Advanced Use Cases

You can pass arguments to torch.compile, as described in PyTorch Documentation

compile = dict(
    backend='inductor',
    mode='reduce-overhead'
)
# equivalent to the following code
# self.model.train_step = torch.compile(
#     self.model.train_step,
#     backend='eager',
#     mode='reduce-overhead'
# )

Due to a PyTorch mkldnn issue, we will not compile val_step and test_step unless the issue has been fixed.

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.

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@b1b1f53). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head abe4283 differs from pull request most recent head 0c79866. Consider uploading reports for the commit 0c79866 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #976   +/-   ##
=======================================
  Coverage        ?   76.61%           
=======================================
  Files           ?      139           
  Lines           ?    10954           
  Branches        ?     2190           
=======================================
  Hits            ?     8392           
  Misses          ?     2201           
  Partials        ?      361           
Flag Coverage Δ
unittests 76.61% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out 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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@C1rN09 C1rN09 marked this pull request as ready for review March 3, 2023 07:04
mmengine/runner/runner.py Outdated Show resolved Hide resolved
mmengine/runner/runner.py Outdated Show resolved Hide resolved
mmengine/runner/runner.py Outdated Show resolved Hide resolved
@zhouzaida zhouzaida added this to the 0.7.0 milestone Mar 5, 2023
@zhouzaida zhouzaida linked an issue Mar 6, 2023 that may be closed by this pull request
HAOCHENYE
HAOCHENYE previously approved these changes Mar 6, 2023
zhouzaida
zhouzaida previously approved these changes Mar 7, 2023
@zhouzaida zhouzaida self-requested a review March 8, 2023 11:06
mmengine/runner/runner.py Outdated Show resolved Hide resolved
mmengine/runner/runner.py Outdated Show resolved Hide resolved
mmengine/runner/runner.py Outdated Show resolved Hide resolved
mmengine/runner/runner.py Outdated Show resolved Hide resolved
mmengine/runner/runner.py Outdated Show resolved Hide resolved
zhouzaida
zhouzaida previously approved these changes Mar 8, 2023
@zhouzaida zhouzaida self-requested a review March 8, 2023 16:35
@zhouzaida zhouzaida merged commit 0d25625 into open-mmlab:main Mar 12, 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.

[Feature] pytorch-2.0
4 participants