-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[bugfix] Minor improvements to apply_to_collection
and type signature of log_dict
#7851
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for more information, see https://pre-commit.ci
Codecov Report
@@ Coverage Diff @@
## master #7851 +/- ##
=======================================
- Coverage 93% 88% -5%
=======================================
Files 202 202
Lines 13050 13051 +1
=======================================
- Hits 12085 11460 -625
- Misses 965 1591 +626 |
This was referenced Jun 7, 2021
kandluis
requested review from
awaelchli,
Borda,
carmocca,
justusschock,
kaushikb11,
SeanNaren,
tchaton and
williamFalcon
as code owners
June 7, 2021 01:25
ananthsub
approved these changes
Jun 7, 2021
justusschock
approved these changes
Jun 7, 2021
Edit: already done :) |
awaelchli
approved these changes
Jun 7, 2021
tchaton
approved these changes
Jun 7, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT !
Thanks @justusschock for updating the changelog. Will keep this in mind for future PRs :) |
Closed
Borda
pushed a commit
that referenced
this pull request
Jun 8, 2021
…re of `log_dict` (#7851) * minor fixeS * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
SeanNaren
pushed a commit
that referenced
this pull request
Jun 8, 2021
…re of `log_dict` (#7851) * minor fixeS * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 009e05d)
lexierule
pushed a commit
that referenced
this pull request
Jun 9, 2021
…re of `log_dict` (#7851) * minor fixeS * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 009e05d)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Improve
apply_to_collection
to continue working with CfgNode from yacsThe existing implementation assumes that
elem_type
is constructible fromIterate[Tuple[K, V]]
. This will fail for custom collections.Specifically, this fails with
CfgNode
(from YAQS) (https://github.com/rbgirshick/yacs/blob/master/yacs/config.py#L74) which is used in Detectron2Go. We use thesave_hyperameters
function on this object, which eventually callsapply_to_collection
. The code before PR #7769 worked fine, but the existing code raises an error sinceCfgNode
cannot be constructed from a List of Tuples.See for discussion: #7769 (comment)
Improved type signature for
log_dict
When merging into our codebase, we noticed that the new type signature for
log_dict
is overly restrictive. PR #7771 improved the type of thedictionary
parameter fromdict
toDict[str, Union[Union[Metric, torch.Tensor, Number], Dict[str, Union[Metric, torch.Tensor, Number]]]]]
.However, given
Dict[K, V]
implies mutability (eg, the function might mutate the dictionary), the type checker defines it as invariant (see python/mypy#2300 (comment)). As such,Dict[str, torch.Tensor]
is no longer a valid type to pass tolog_dict
, which is unintended.Given that
dictionary
parameter appears to be read-only inlog_dict
, the easiest fix is to change fromDict[K, V]
toMapping[K, V]
. I believe this better matches the intention of thelog_dict
function, unless we truly intend for the parameter to be mutable.See for discussion: #7771 (comment)
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃