You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defaultdict with no factory argument has the same behavior as a plain dict — missing keys raise KeyError. The previous defaultdict(lambda: 1.0) returned the documented default 1.0 for tasks without an explicit weight.
Only one usage was patched to .get(name, 1.0). Direct indexing sites (e.g. future code, or external subclasses that read head._task_weights[task_name]) will now raise KeyError where they previously returned 1.0.
Either restore the lambda: 1.0 factory, so defaultdict conveys its documented meaning, or switch to plain dict() with consistent .get(name, 1.0) access at every call site. Using defaultdict() is misleading because the name promises a default factory it no longer has.
Environment details
Transformers4Rec: main @ 8bf122f5 (regression from PR Sec pic fix #802 / commit ab7207cf)
Additional context
Preferred fix — restore the factory (closest to original behavior):
Bug description
PR #802 (commit
ab7207cf) changedself._task_weights = defaultdict(lambda: 1.0)toself._task_weights = defaultdict()intransformers4rec/torch/model/base.py:Transformers4Rec/transformers4rec/torch/model/base.py
Line 272 in 8bf122f
defaultdictwith no factory argument has the same behavior as a plaindict— missing keys raiseKeyError. The previousdefaultdict(lambda: 1.0)returned the documented default1.0for tasks without an explicit weight.Only one usage was patched to
.get(name, 1.0). Direct indexing sites (e.g. future code, or external subclasses that readhead._task_weights[task_name]) will now raiseKeyErrorwhere they previously returned1.0.Steps/Code to reproduce bug
Expected behavior
Either restore the
lambda: 1.0factory, sodefaultdictconveys its documented meaning, or switch to plaindict()with consistent.get(name, 1.0)access at every call site. Usingdefaultdict()is misleading because the name promises a default factory it no longer has.Environment details
main@8bf122f5(regression from PR Sec pic fix #802 / commitab7207cf)Additional context
Preferred fix — restore the factory (closest to original behavior):
Happy to send a one-line PR.