Simplify DTensor Check for modeling_utils.py (#38245)

Update modeling_utils.py
This commit is contained in:
amd-xiaoyu12 2025-05-21 09:35:44 -04:00 committed by GitHub
parent e4decee9c0
commit 174684a9b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3567,7 +3567,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, PushToHubMixin, PeftAdapterMi
for name, tensor in state_dict.items():
# Sometimes in the state_dict we have non-tensor objects.
# e.g. in bitsandbytes we have some `str` objects in the state_dict
if isinstance(tensor, torch.Tensor) or isinstance(tensor, DTensor):
if isinstance(tensor, torch.Tensor):
ptrs[id_tensor_storage(tensor)].append(name)
else:
# In the non-tensor case, fall back to the pointer of the object itself