Conversation
Loading.load_buffer() iterated every key in module._buffers and unconditionally read module._buffers[name].data, but PyTorch modules can register a buffer as None (e.g. nn.InstanceNorm1d's running_mean/running_var/num_batches_tracked when track_running_stats=False). Loading a checkpoint into such a module raised AttributeError: 'NoneType' object has no attribute 'data'. Skip buffers that are None before touching .data; there is nothing to cast to a concrete tensor or copy a checkpoint value into. Fixes deepspeedai#8514 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: adarshsm <24850536+adarshsm@users.noreply.github.com>
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.
Bug
Loading.load_buffer()indeepspeed/module_inject/auto_tp.pyiterates every key inmodule._buffersand unconditionally doesmodule._buffers[name].data.is_meta. PyTorch lets a buffer be registered asNone— e.g.nn.InstanceNorm1dwith the defaulttrack_running_stats=Falseregistersrunning_mean,running_var, andnum_batches_trackedasNone. Loading a checkpoint into a model containing such a module crashes with:Repro from #8514 (CPU-only, no GPU or
transformersneeded):Fix
Skip a buffer when it is
Nonebefore touching.data— there is nothing to cast to a concrete tensor or copy a checkpoint value into for an unset buffer.Testing
Added
tests/unit/module_inject/test_load_buffer.py:test_load_buffer_skips_unset_buffers— annn.InstanceNorm1d(all-Nonebuffers) goes throughLoading.load_bufferwithout raising. This fails with the reportedAttributeErroron the code before this change.test_load_buffer_still_loads_present_buffers— a normalnn.BatchNorm1dbuffer is still copied fromstate_dictas before.Ran
pytest tests/unit/module_inject/test_load_buffer.py— both pass after the fix, andtest_load_buffer_skips_unset_buffersreproduces the reported crash when run against the pre-fix code. Also ranflake8andyapf --style .style.yapf --diffover both changed files with no findings.Fixes #8514