From da3f14f84fc5f2c428c2d9b9ff1a55ac69463388 Mon Sep 17 00:00:00 2001 From: amd-xiaoyu12 Date: Tue, 20 May 2025 11:56:17 -0400 Subject: [PATCH] Update modeling_utils.py Simplify the condition check, since DTensor is also a Tensor if isinstance(tensor, torch.Tensor) or isinstance(tensor, DTensor): => if isinstance(tensor, torch.Tensor): --- src/transformers/modeling_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformers/modeling_utils.py b/src/transformers/modeling_utils.py index ece787c7b675..49f7b03d4ece 100644 --- a/src/transformers/modeling_utils.py +++ b/src/transformers/modeling_utils.py @@ -3567,7 +3567,7 @@ def save_pretrained( 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