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

clean up metrics code, use MetricCollection #1529

Merged
merged 4 commits into from
Jun 13, 2022
Merged

clean up metrics code, use MetricCollection #1529

merged 4 commits into from
Jun 13, 2022

Conversation

adamgayoso
Copy link
Member

By calling .update() explicitly, it should speed things up according to their documentation as we don't need the per step values.

This also fixes an issue where n_obs_training might not reflect the number of cells in an epoch, as in the large scale training params where we restrict an epoch to 20 minibatches

@adamgayoso adamgayoso added this to the 0.17.0 milestone May 3, 2022
@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #1529 (c15d1e7) into master (73952af) will decrease coverage by 0.04%.
The diff coverage is 87.23%.

@@            Coverage Diff             @@
##           master    #1529      +/-   ##
==========================================
- Coverage   91.12%   91.08%   -0.05%     
==========================================
  Files         113      113              
  Lines        8996     9015      +19     
==========================================
+ Hits         8198     8211      +13     
- Misses        798      804       +6     
Impacted Files Coverage Δ
scvi/train/_metrics.py 86.36% <77.77%> (-13.64%) ⬇️
scvi/train/_trainingplans.py 95.46% <100.00%> (+0.10%) ⬆️

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 73952af...c15d1e7. Read the comment docs.

scvi/train/_metrics.py Show resolved Hide resolved
scvi/train/_trainingplans.py Outdated Show resolved Hide resolved
scvi/train/_trainingplans.py Outdated Show resolved Hide resolved
scvi/train/_trainingplans.py Outdated Show resolved Hide resolved
@justjhong
Copy link
Contributor

@PierreBoyeau @adamgayoso updated and addressed my own comments. Condensed code by relying on this part of the metricscollection code https://github.com/PyTorchLightning/metrics/blob/11641b8558e713649743709d78d3ab363bcfc9aa/torchmetrics/metric.py#L681-L682

@justjhong
Copy link
Contributor

Also noticed GIMVI doesnt use this and seems hard to adapt to it. Does it matter?

scvi/train/_metrics.py Outdated Show resolved Hide resolved
kl_local_sum: torch.Tensor,
kl_global: torch.Tensor,
n_obs_minibatch: int,
**kwargs,
):
"""Updates all metrics."""
Copy link
Member Author

Choose a reason for hiding this comment

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

might be good to explain somehwere that in a metric collection that arguments get passed to each individual metric

Copy link
Contributor

@PierreBoyeau PierreBoyeau left a comment

Choose a reason for hiding this comment

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

PR looks good to me, also did a basic sanity check here to double-check that the metrics overall make sense.

@justjhong justjhong merged commit aecf24d into master Jun 13, 2022
@justjhong justjhong deleted the torchmetrics branch June 13, 2022 18:01
nrclaudio pushed a commit to nrclaudio/scvi-tools-tune that referenced this pull request Jun 21, 2022
* clean up metrics code

* condense elbo metric code with filtering inside the update fn

* codacy

* address comments

Co-authored-by: Justin Hong <[email protected]>
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