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 is_tracing to wrap torch.jit.is_tracing in different versions. #1187

Merged
merged 3 commits into from
Jul 13, 2021

Conversation

mzr1996
Copy link
Member

@mzr1996 mzr1996 commented Jul 9, 2021

Motivation

Head needs different behaviors in test and export, so we need to use torch.jit.is_tracing to judge different situations.

But torch.jit.is_tracing has a bug in PyTorch 1.6.0, so we need a wrapper to support trace judgement.

Modification

Add a helper function in mmcv/utils, and add unit tests.

BC-breaking (Optional)

No

Use cases (Optional)

import torch
from mmcv.utils import is_tracing

def foo(x):
    if is_tracing():
        return x
    else:
        return x.tolist()

>>> x = torch.ones(3)
>>> foo(x)
[1.0, 1.0, 1.0]
>>> traced_foo = torch.jit.trace(foo, (torch.rand(1), ))
>>> traced_foo(x)
tensor([1., 1., 1.])

@codecov
Copy link

codecov bot commented Jul 9, 2021

Codecov Report

Merging #1187 (6a43133) into master (4a9f834) will decrease coverage by 0.02%.
The diff coverage is 59.09%.

❗ Current head 6a43133 differs from pull request most recent head cb5ebd8. Consider uploading reports for the commit cb5ebd8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1187      +/-   ##
==========================================
- Coverage   67.99%   67.96%   -0.03%     
==========================================
  Files         159      160       +1     
  Lines       10426    10446      +20     
  Branches     1897     1901       +4     
==========================================
+ Hits         7089     7100      +11     
- Misses       2968     2973       +5     
- Partials      369      373       +4     
Flag Coverage Δ
unittests 67.96% <59.09%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
mmcv/utils/trace.py 54.54% <54.54%> (ø)
mmcv/utils/parrots_wrapper.py 59.37% <55.55%> (-1.34%) ⬇️
mmcv/utils/__init__.py 88.88% <100.00%> (+0.65%) ⬆️
mmcv/version.py 92.30% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a9f834...cb5ebd8. Read the comment docs.

mmcv/utils/trace.py Outdated Show resolved Hide resolved
@mzr1996 mzr1996 requested a review from ZwwWayne July 12, 2021 04:59
@ZwwWayne ZwwWayne merged commit 6659c38 into open-mmlab:master Jul 13, 2021
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