espnet2.torch_utils.model_summary.to_bytes
Less than 1 minute
espnet2.torch_utils.model_summary.to_bytes
espnet2.torch_utils.model_summary.to_bytes(dtype) → int
Convert a PyTorch data type to the corresponding byte size.
This function takes a PyTorch data type as input and returns the size in bytes by extracting the number of bits represented by the type and converting it to bytes.
- Parameters:dtype – A PyTorch data type (e.g., torch.float16, torch.float32, etc.).
- Returns: An integer representing the size of the data type in bytes.
Examples
>>> to_bytes(torch.float16)
2
>>> to_bytes(torch.float32)
4
>>> to_bytes(torch.float64)
8