Restore default factory on Head._task_weights#819
Open
shaun0927 wants to merge 1 commit into
Open
Conversation
PR NVIDIA-Merlin#802 replaced defaultdict(lambda: 1.0) with defaultdict(), which has the same runtime semantics as a plain dict - missing keys raise KeyError. The documented behavior ('1.0 when unset') was preserved at only one call site via .get(name, 1.0); any other direct indexing regresses to a crash. Restoring the lambda factory is a one-line change that preserves the original API contract and keeps downstream code that reads head._task_weights[task_name] working. Fixes NVIDIA-Merlin#813
Author
|
FYI — I have read |
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.
Goals ⚽
Restore the documented "unset task weight defaults to 1.0" behavior that regressed in PR #802.
Fixes #813.
Implementation Details 🚧
PR #802 (
ab7207cf) changedself._task_weights = defaultdict(lambda: 1.0)toself._task_weights = defaultdict()intransformers4rec/torch/model/base.py:272. Adefaultdictconstructed with no factory has the same runtime behavior as a plaindict— missing keys raiseKeyError. The previous factory returned1.0for unset task weights, which matches the docstring forHead(task_weights=...):One usage inside
Head.forwardwas patched to.get(name, 1.0)as a workaround, but any other indexing site — internal future code or external subclasses that readhead._task_weights[task_name]— now raisesKeyErrorwhere it previously returned1.0.Minimal fix — restore the factory:
This is the smallest change that re-establishes the
defaultdictcontract and avoids the need for scattered.get(name, 1.0)work-arounds.Testing Details 🔍
Pre-fix regression:
Post-fix:
Existing tests that touch
Head(...)construction still pass (the factory change is purely additive on unset-key reads). No new test is added because the repro is a straightforward standard-library semantic; happy to add an explicit regression test if reviewers would prefer.