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

Avoid torchscript export for Metric forward #4428

Merged
merged 9 commits into from
Nov 3, 2020

Conversation

ananthsub
Copy link
Contributor

@ananthsub ananthsub commented Oct 29, 2020

What does this PR do?

Fixes #4416
https://pytorch.org/docs/stable/generated/torch.jit.unused.html#torch.jit.unused

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@ananthsub ananthsub marked this pull request as draft October 29, 2020 16:04
@codecov
Copy link

codecov bot commented Oct 29, 2020

Codecov Report

Merging #4428 into master will increase coverage by 3%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #4428    +/-   ##
=======================================
+ Coverage      90%     93%    +3%     
=======================================
  Files         116     116            
  Lines        8742    8718    -24     
=======================================
+ Hits         7845    8075   +230     
+ Misses        897     643   -254     

@SkafteNicki
Copy link
Member

Maybe add this test to tests\metrics\test_metric_lightning.py:

def test_scriptable(tmpdir):
    class TestModel(BoringModel):
        def __init__(self):
            super().__init__()
            self.metric = SumMetric()
            self.sum = 0.0

        def training_step(self, batch, batch_idx):
            x = batch
            self.metric(x.sum())
            self.sum += x.sum()
            self.log("sum", self.metric, on_epoch=True, on_step=False)
            return self.step(x)
    model = TestModel()

    script_model = torch.jit.script(model)
    # test that we can still do inference
    output = script_model(torch.randn(10, 32))

@ananthsub ananthsub force-pushed the jit-ignore-metric-forward branch from 3f5f1b9 to ac00fcc Compare November 3, 2020 06:48
@ananthsub ananthsub marked this pull request as ready for review November 3, 2020 06:57
@ananthsub ananthsub marked this pull request as draft November 3, 2020 07:08
@ananthsub ananthsub force-pushed the jit-ignore-metric-forward branch from 6523a09 to d8ff339 Compare November 3, 2020 07:11
@ananthsub ananthsub marked this pull request as ready for review November 3, 2020 07:19
@ananthsub ananthsub marked this pull request as draft November 3, 2020 07:33
@ananthsub ananthsub marked this pull request as ready for review November 3, 2020 07:46
@Borda Borda added the feature Is an improvement or enhancement label Nov 3, 2020
@Borda Borda added the Metrics label Nov 3, 2020
@Borda Borda added this to the 1.1 milestone Nov 3, 2020
Copy link
Member

@SkafteNicki SkafteNicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Borda Borda modified the milestones: 1.1, 1.0.x Nov 3, 2020
@Borda Borda added the ready PRs ready to be merged label Nov 3, 2020
@Borda
Copy link
Member

Borda commented Nov 3, 2020

the time-outed test came from the master...

@Borda Borda merged commit 5d08559 into Lightning-AI:master Nov 3, 2020
Borda pushed a commit that referenced this pull request Nov 3, 2020
* Update metric.py

* add test

* Update CHANGELOG.md

* Update test_metric_lightning.py

* Update test_metric_lightning.py

Co-authored-by: Jirka Borovec <[email protected]>
(cherry picked from commit 5d08559)
Borda pushed a commit that referenced this pull request Nov 4, 2020
* Update metric.py

* add test

* Update CHANGELOG.md

* Update test_metric_lightning.py

* Update test_metric_lightning.py

Co-authored-by: Jirka Borovec <[email protected]>
(cherry picked from commit 5d08559)
rohitgr7 pushed a commit that referenced this pull request Nov 21, 2020
* Update metric.py

* add test

* Update CHANGELOG.md

* Update test_metric_lightning.py

* Update test_metric_lightning.py

Co-authored-by: Jirka Borovec <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't TorchScript LightningModule when using Metric
5 participants