Repository navigation
[BugFix] Resolve CompositeDistribution name_map with unraveled keys - #2649
Open
YeonwooSung wants to merge 2 commits into
Open
YeonwooSung wants to merge 2 commits into
YeonwooSung wants to merge 2 commits into
Conversation
Tuple keys such as ("a",) keep the sample name "a" instead of the
name_map target, and a name_map key that matches no distribution is
ignored. Cover both constructors.
name_map was keyed by unraveled names but looked up with the original
distribution key, so a tuple such as ("a",) never renamed the sample.
Match on the unraveled name in both constructors, and raise KeyError
when a name_map key is not one of the distributions.
This branch has not been deployed
This file contains hidden or 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
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.
Problem
CompositeDistribution.__init__andfrom_distributionsunraveled both sides ofname_map, then looked the distribution up with the original key:dict.getnever raises, so theexcept KeyErrorwas dead. A tuple key does not surviveunravel_key(("a",)becomes"a", and(("nested",), "disc")becomes("nested", "disc")), so the lookup missed and the sample kept the unraveled distribution name. String keys only worked becauseunravel_key("a")is still"a". Aname_mapentry that did not match any distribution was ignored, despitefrom_distributionsdocumenting that case as aKeyError.Fix
Both constructors resolve
name_mapthrough one helper. Distribution names are matched afterunravel_key, and the sample is written under the mapped key. Names omitted fromname_mapkeep their own name. Aname_mapkey that does not match any distribution raisesKeyError.Tests
TestCompositeDistcovers tuple-key rename, nested tuple-key rename, string-key rename, and an unknownname_mapkey, for__init__andfrom_distributions.Before the fix, the tuple-key tests failed with the sample key left as
"a"(nested keys stayed("nested", "disc")), and the unknown-key tests did not raise. String keys already passed.After the fix:
ruff checkandruff formatare clean ontensordict/nn/distributions/composite.pyandtest/nn/test_nn.py.