Skip to content

Commit

Permalink
Fix the size of int and bool type when computing module size (#2411)
Browse files Browse the repository at this point in the history
* According to the code in set_module_tensor_to_device, uint, int and bool type
  won't be converted, so let's keep its original size, or the module size will be
  under-estimated.
  • Loading branch information
notsyncing authored Feb 2, 2024
1 parent 46f1391 commit 68f5472
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/accelerate/utils/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,10 @@ def compute_module_sizes(
size = tensor.numel() * special_dtypes_size[name]
elif dtype is None:
size = tensor.numel() * dtype_byte_size(tensor.dtype)
elif str(tensor.dtype).startswith(("torch.uint", "torch.int", "torch.bool")):
# According to the code in set_module_tensor_to_device, these types won't be converted
# so use their original size here
size = tensor.numel() * dtype_byte_size(tensor.dtype)
else:
size = tensor.numel() * min(dtype_size, dtype_byte_size(tensor.dtype))
name_parts = name.split(".")
Expand Down

0 comments on commit 68f5472

Please sign in to comment.