Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions megatron/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,20 @@ def get_gpu_count():
else:
return 0

def torch_assert_equal(actual, expected):
""" emulates the removed torch.testing.assert_equal """
torch.testing.assert_close(actual, expected, rtol=0.0, atol=0.0)
def torch_assert_equal(actual, expected, **kwargs):
# assert_equal was added around pt-1.9, it does better checks - e.g will check dimensions match
if hasattr(torch.testing, "assert_equal"):
return torch.testing.assert_equal(actual, expected, **kwargs)
else:
return torch.allclose(actual, expected, rtol=0.0, atol=0.0)

def torch_assert_close(actual, expected, **kwargs):
# assert_close was added around pt-1.9, it does better checks - e.g will check dimensions match
if hasattr(torch.testing, "assert_close"):
return torch.testing.assert_close(actual, expected, **kwargs)
else:
kwargs.pop("msg", None) # doesn't have msg arg
return torch.allclose(actual, expected, **kwargs)


def is_torch_bf16_available():
Expand Down