Repository navigation
Fix interval merge bug in _find_disjoint that breaks weight tying - #47814
sharmax-vikas wants to merge 1 commit into
Conversation
…n save/reload When a short tensor is fully contained inside a larger one in shared storage, `last_stop` shrinks to the smaller tensor's end pointer, causing subsequent overlapping tensors to be incorrectly classified as disjoint. This leads to shared weights being cloned and saved as independent tensors, silently breaking weight tying after reload.
CI recapDashboard: View test results in Grafana |
SunMarc
left a comment
There was a problem hiding this comment.
Thanks ! Can you give a real example on how you caught this bug ?
|
Investigated this properly — my original claim was wrong. There is no save/reload corruption: triggering the mis-classification requires strict containment, which guarantees the group is never "identical" in The invariant itself is still wrong though ( |
Summary
_find_disjoint()(src/transformers/modeling_utils.py, line 406) wherelast_stop = stopshould belast_stop = max(last_stop, stop)last_stopshrinks to the smaller tensor's end pointer, causing subsequent overlapping tensors to be incorrectly classified as disjoint.clone()'d and saved as independent tensors, silently breaking weight tying aftersave_pretrained->from_pretrainedround-tripExample
After processing B,
last_stopdrops from 100 to 50. Then C'sstart=60 >= 50is true, so C is incorrectly put in a new disjoint group -- even though it overlaps with A.Test plan
_find_disjointtests still passsave_pretrained->from_pretrainedround-trip preserves weight tying in this scenario