Skip to content

Commit

Permalink
[Tests] Better prints (huggingface#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickvonplaten authored Oct 28, 2022
1 parent 12be752 commit bf2fa37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@


if is_torch_available():
from .testing_utils import floats_tensor, load_image, parse_flag_from_env, require_torch_gpu, slow, torch_device
from .testing_utils import (
floats_tensor,
load_image,
parse_flag_from_env,
require_torch_gpu,
slow,
torch_all_close,
torch_device,
)


logger = get_logger(__name__)
Expand Down
8 changes: 8 additions & 0 deletions utils/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
torch_device = "mps" if (mps_backend_registered and torch.backends.mps.is_available()) else torch_device


def torch_all_close(a, b, *args, **kwargs):
if not is_torch_available():
raise ValueError("PyTorch needs to be installed to use this function.")
if not torch.allclose(a, b, *args, **kwargs):
assert False, f"Max diff is absolute {(a - b).abs().max()}. Diff tensor is {(a - b).abs()}."
return True


def get_tests_dir(append_path=None):
"""
Args:
Expand Down

0 comments on commit bf2fa37

Please sign in to comment.