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

Deprecate LossRecorder, create LossOutput dataclass alternative #1749

Merged
merged 29 commits into from
Oct 25, 2022

Conversation

adamgayoso
Copy link
Member

@adamgayoso adamgayoso commented Oct 17, 2022

Dataclasses allow the same workflow to be applied to jax-based models.

Two changes are important:

  • LossRecorder is deprecated, to be removed in v0.20.0
  • JaxTrainingPlan gets proper logging using the same paradigm

TODO:

Some code was added to loss recorder to make it backwards compatible, but it will be removed anyway

Base automatically changed from jax_training to main October 18, 2022 17:19
@adamgayoso adamgayoso marked this pull request as ready for review October 18, 2022 18:22
@adamgayoso adamgayoso added this to the 0.19.0 milestone Oct 18, 2022
@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Base: 90.86% // Head: 90.85% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (7e3a444) compared to base (b2b6224).
Patch coverage: 95.65% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1749      +/-   ##
==========================================
- Coverage   90.86%   90.85%   -0.01%     
==========================================
  Files         118      118              
  Lines        9969    10015      +46     
==========================================
+ Hits         9058     9099      +41     
- Misses        911      916       +5     
Impacted Files Coverage Δ
scvi/module/base/__init__.py 100.00% <ø> (ø)
scvi/module/_scanvae.py 80.00% <60.00%> (ø)
scvi/module/base/_base_module.py 92.75% <93.15%> (-0.61%) ⬇️
scvi/external/gimvi/_module.py 86.61% <100.00%> (-0.10%) ⬇️
scvi/external/gimvi/_task.py 98.43% <100.00%> (ø)
scvi/external/scar/_module.py 87.38% <100.00%> (-0.12%) ⬇️
scvi/external/stereoscope/_module.py 96.36% <100.00%> (ø)
scvi/external/tangram/_module.py 93.10% <100.00%> (ø)
scvi/model/base/_log_likelihood.py 100.00% <100.00%> (ø)
scvi/model/base/_vaemixin.py 93.65% <100.00%> (ø)
... and 10 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.

Copy link
Contributor

@justjhong justjhong left a comment

Choose a reason for hiding this comment

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

looks good

@@ -281,7 +284,7 @@ def forward(self, *args, **kwargs):
@torch.inference_mode()
def compute_and_log_metrics(
self,
loss_recorder: LossRecorder,
loss_recorder: Union[LossRecorder, LossOutput],
metrics: MetricCollection,
Copy link
Contributor

Choose a reason for hiding this comment

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

ordereddict now? to ensure the next(iter stuff works

Copy link
Member Author

Choose a reason for hiding this comment

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

this is still the loss output

Copy link
Contributor

Choose a reason for hiding this comment

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

commenting on the metrics not the loss recorder

# Use the torchmetric object for the ELBO
# We only need to update the ELBO metric
# As it's defined as a sum of the other metrics
next(iter(metrics.values()))[0].update(
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't you key into elbo here?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yeah I didn't see we have access to the mode here

scvi/train/_trainingplans.py Show resolved Hide resolved
reconstruction_loss: Optional[LossRecord] = None
kl_local: Optional[LossRecord] = None
kl_global: Optional[LossRecord] = None
extra_metrics: Optional[Dict[str, Tensor]] = field(default_factory=dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
extra_metrics: Optional[Dict[str, Tensor]] = field(default_factory=dict)
extra_metrics: Dict[str, Tensor] = field(default_factory=dict)

Copy link
Member Author

Choose a reason for hiding this comment

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

I would say this is optional because you don't need to specifiy it

@adamgayoso adamgayoso enabled auto-merge (squash) October 25, 2022 21:40
@adamgayoso adamgayoso merged commit 0c3808e into main Oct 25, 2022
@adamgayoso adamgayoso deleted the loss_recorder_dataclass branch November 1, 2022 15:51
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.

3 participants