Skip to content

Conversation

@daavoo
Copy link
Contributor

@daavoo daavoo commented Nov 15, 2022

Ensure logic inside live.end is only called once.

This is mainly for Studio to get a "completed" event when using the frameworks

@daavoo daavoo requested a review from dberenbaum November 15, 2022 17:59
@daavoo daavoo self-assigned this Nov 15, 2022
@daavoo daavoo added the A: frameworks Area: ML Framework integration label Nov 15, 2022

Choose a reason for hiding this comment

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

Minor: Could you use the @functools.cache decorator on def end(self): instead of adding self._ended?

Copy link
Contributor Author

@daavoo daavoo Nov 21, 2022

Choose a reason for hiding this comment

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

Depending on what we agree in #364 (comment)

@dberenbaum
Copy link

How should this type of scenario work?

with Live() as live:

  live.log_params(...)
  
  model.fit(DVCLiveCallback(live=live))
  
  # Post-training logs
  live.log_image(...)

@daavoo
Copy link
Contributor Author

daavoo commented Nov 21, 2022

How should this type of scenario work?

I would expect the live metrics functionality to be only working inside the callback.

If I decouple the post_to_studio(self, "done", logger) from the live._ended, I think the snippet would behave as expected.

So:

    self.make_summary()
    if self.report_mode == "studio":
        if not self._ended:
            if not post_to_studio(self, "done", logger):
                logger.warning("`post_to_studio` `done` event failed.")
            self._ended = True
    else:
        self.make_report()

@dberenbaum
Copy link

dberenbaum commented Nov 21, 2022

None of this is a blocker since I don't think anything breaks the basic live metrics workflow, but it would be good to have it to "unbreak" more complex scenarios.

If I decouple the post_to_studio(self, "done", logger) from the live._ended, I think the snippet would behave as expected.

It's a little ugly but more likely to work the way users want (log summary/report always).

I would expect the live metrics functionality to be only working inside the callback.

Can we also have something like this to enable the context manager to override other calls to end?

    self.make_summary()
    if self.report_mode == "studio":
        if not self._ended:
            if not post_to_studio(self, "done", logger):
                logger.warning("`post_to_studio` `done` event failed.")
-           self._ended = True
+           if not self._keep_alive: # set to True in __enter__ and False in __exit__
+               self._ended = True
    else:
        self.make_report()

@daavoo daavoo force-pushed the live-metrics-updates branch 4 times, most recently from 49b1027 to a923a10 Compare November 25, 2022 18:57
@daavoo daavoo force-pushed the live-metrics-updates branch 2 times, most recently from 24de14d to 986fc2e Compare November 28, 2022 13:39
Ensure `post_to_studio` inside `live.end` is only called once.
@daavoo daavoo force-pushed the live-metrics-updates branch from 986fc2e to 9c5cd45 Compare November 28, 2022 14:19
@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2022

Codecov Report

Base: 96.37% // Head: 96.47% // Increases project coverage by +0.10% 🎉

Coverage data is based on head (9c5cd45) compared to base (da345f5).
Patch coverage: 96.55% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #364      +/-   ##
==========================================
+ Coverage   96.37%   96.47%   +0.10%     
==========================================
  Files          36       36              
  Lines        1739     1789      +50     
  Branches      153      155       +2     
==========================================
+ Hits         1676     1726      +50     
  Misses         37       37              
  Partials       26       26              
Impacted Files Coverage Δ
src/dvclive/live.py 96.13% <60.00%> (+0.06%) ⬆️
src/dvclive/catalyst.py 100.00% <100.00%> (ø)
src/dvclive/fastai.py 94.11% <100.00%> (+0.78%) ⬆️
src/dvclive/huggingface.py 91.30% <100.00%> (+0.82%) ⬆️
src/dvclive/keras.py 100.00% <100.00%> (ø)
src/dvclive/lightning.py 90.90% <100.00%> (+0.66%) ⬆️
src/dvclive/xgb.py 95.00% <100.00%> (+0.88%) ⬆️
tests/test_catalyst.py 95.55% <100.00%> (+0.43%) ⬆️
tests/test_fastai.py 100.00% <100.00%> (ø)
tests/test_huggingface.py 97.82% <100.00%> (+0.07%) ⬆️
... and 4 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.

@daavoo daavoo merged commit 9f9c31b into main Nov 28, 2022
@daavoo daavoo deleted the live-metrics-updates branch November 28, 2022 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A: frameworks Area: ML Framework integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants