-
Notifications
You must be signed in to change notification settings - Fork 415
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
Refactor: Rename update and compute methods to _update and _compute #840
Conversation
Also, update docs and how to implement own metric... |
Codecov Report
@@ Coverage Diff @@
## master #840 +/- ##
=====================================
- Coverage 95% 95% -0%
=====================================
Files 167 167
Lines 6931 6958 +27
=====================================
+ Hits 6587 6599 +12
- Misses 344 359 +15 |
@Borda this class in PL now breaks: |
@carmocca mind help here... |
Yes. We did a vote in core-metrics on slack and it was decided the renaming should be
Not really. We want to push breaking API changes now, as we are moving closer to v1.0 release where we cannot make these kind of changes. Do you think we should just stick with what we have and not do the breaking change?
Yes. We already increased integration with lightning to v1.5 in this release: |
It's up to the metrics core team, it's a big breaking change but I agree that it's either now or never. So if torchmetrics is going to be "moving fast and breaking things" it's probably worth pinning the torchmetrics dependency to 0.8 in PL. Just beware that this could leave PL users unable to upgrade PL without also upgrading their torchmetrics implementations, so if you don't provide backwards compatibility at least provide clear upgrade guidance for existing Metrics implementations. Now, we are in a "chicken and egg" situation where both libraries require the other one to release. We would need to orchestrate this before the PL 1.6 release. One solution would be:
But it's pretty risky. Ideally either torchmetrics keeps backwards compatibility for one version or PL adds support for both until 1.6 is released and then drops the previous format for 1.7 |
@carmocca I think for PL itself this should not be a problem, as the I think since the On the other side, this wouldn't be only PL breaking, but every user code, so I suggest we do something about backwards compatibility, despite not being stable yet. My proposal: For user-backwards compatibility, we could probably check if the |
@Borda @justusschock @carmocca I updated the PR so the change is now backwards compatible, thus the integrations tests will pass but the user will get a deprecation warning asking them to rename their methods. This is the relevant code: # check update and compute format
if is_overridden("update", self, Metric):
warnings.warn(
"We detected that you have overwritten the ``update`` method, which was the API"
" for torchmetrics v0.7 and below. Insted implement the ``_update`` method."
" (exact same as before just with a ``_`` infront to make the implementation private)"
" Implementing `update` directly was deprecated in v0.8 and will be removed in v0.9.",
DeprecationWarning,
)
self._update_signature = inspect.signature(self.update)
self.update: Callable = self._wrap_update(self.update) # type: ignore
else:
if not hasattr(self, "_update"):
raise NotImplementedError("Expected method `_update` to be implemented in subclass.")
self._update_signature = inspect.signature(self._update)
if is_overridden("compute", self, Metric):
warnings.warn(
"We detected that you have overwritten the ``compute`` method, which was the API"
" for torchmetrics v0.7 and below. Insted implement the ``_compute`` method."
" (exact same as before just with a ``_`` infront to make the implementation private)"
" Implementing `compute` directly was deprecated in v0.8 and will be removed in v0.9.",
DeprecationWarning,
)
self.compute: Callable = self._wrap_compute(self.compute) # type: ignore
else:
if not hasattr(self, "_compute"):
raise NotImplementedError("Expected method `_compute` to be implemented in subclass.") We still need to sync with PL, but it will not be as critical. @carmocca I kept the naming as |
Sounds good to me. Do you want to open a PR with the update to PL? |
Cool, still let's do it before v1.6 is out :) |
hey everyone, i just want to clarify the process for any proposed API changes.
the APIs are like the web front-end for everything we do... front-ends are designed by designers (not by a collective effort, otherwise you build a frankenstein). Treat the APIs with the same level of riguour. What is covered under API?
it's the "high-level", "root" classes that a user would mess with directly. the API does NOT include internal things like:
if you're unclear whether it's covered or not, please ask @awaelchli or @williamFalcon Thanks! |
What does this PR do?
Currently we are wrapping users implementation of
update
andcompute
. This is in general bad practise and we have received a couple of questions about this (especially because it can be confusing to debug what is going on for the user). Instead we will now ask the user to implement the private methods_update
and_compute
which will then be called by their public counter-part. The end user will still just callupdate
andcompute
and the change is therefore backward compatible for users that just uses TM. Users that have implemented custom metrics will need to update their metrics.I have borrowed the
is_overridden
function from PL such that we are going to check if metric are overwriting theupdate
andcompute
method.Before submitting
PR review
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 🙃