Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SunMarc committed May 22, 2024
1 parent c137c22 commit 5d18005
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from huggingface_hub.serialization import split_state_dict_into_shards_factory
from huggingface_hub.serialization._base import convert_file_size_to_int
from huggingface_hub.serialization._numpy import get_tensor_size as get_tensor_size_numpy
from huggingface_hub.serialization._tensorflow import get_tensor_size as get_tensor_size_tensorflow
from huggingface_hub.serialization._torch import get_tensor_size as get_tensor_size_torch
Expand Down Expand Up @@ -123,3 +124,13 @@ def test_get_tensor_size_torch():

assert get_tensor_size_torch(torch.tensor([1, 2, 3, 4, 5], dtype=torch.float64)) == 5 * 8
assert get_tensor_size_torch(torch.tensor([1, 2, 3, 4, 5], dtype=torch.float16)) == 5 * 2


def test_convert_file_size_to_int():
assert convert_file_size_to_int("1KiB") == 2**10
assert convert_file_size_to_int("1KB") == 10**3
assert convert_file_size_to_int("1MiB") == 2**20
assert convert_file_size_to_int("1MB") == 10**6
assert convert_file_size_to_int("1GiB") == 2**30
assert convert_file_size_to_int("1GB") == 10**9
assert convert_file_size_to_int("5GB") == 5 * 10**9

0 comments on commit 5d18005

Please sign in to comment.