Skip to content

Commit

Permalink
Add torch.float8_e4m3fn format dtype_byte_size (#2945)
Browse files Browse the repository at this point in the history
* add new format

* check torch version

* style
  • Loading branch information
SunMarc authored Jul 20, 2024
1 parent 0af1d8b commit a5a3e57
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/accelerate/utils/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from .memory import clear_device_cache
from .offload import load_offloaded_weight, offload_weight, save_offload_index
from .tqdm import is_tqdm_available, tqdm
from .versions import compare_versions
from .versions import compare_versions, is_torch_version


if is_npu_available(check_device=False):
Expand Down Expand Up @@ -163,6 +163,8 @@ def dtype_byte_size(dtype: torch.dtype):
return 1 / 2
elif dtype == CustomDtype.FP8:
return 1
elif is_torch_version(">=", "2.1.0") and dtype == torch.float8_e4m3fn:
return 1
bit_search = re.search(r"[^\d](\d+)$", str(dtype))
if bit_search is None:
raise ValueError(f"`dtype` is not a valid dtype: {dtype}.")
Expand Down

0 comments on commit a5a3e57

Please sign in to comment.