Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions megatron/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ 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 get_tests_dir(append_path=None):
"""
Expand Down
10 changes: 5 additions & 5 deletions tests/test_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from torch.nn import functional as F

from megatron.model.activations import liglu, geglu, reglu, swiglu
from megatron.testing_utils import set_seed
from megatron.testing_utils import set_seed, torch_assert_equal


class TestActivations(unittest.TestCase):
Expand All @@ -27,16 +27,16 @@ def test_shapes(self):

def test_liglu(self):
expected = self.x1 * self.x2
torch.testing.assert_equal(liglu(self.x), expected)
torch_assert_equal(liglu(self.x), expected)

def test_geglu(self):
expected = self.x1 * F.gelu(self.x2)
torch.testing.assert_equal(geglu(self.x), expected)
torch_assert_equal(geglu(self.x), expected)

def test_reglu(self):
expected = self.x1 * F.relu(self.x2)
torch.testing.assert_equal(reglu(self.x), expected)
torch_assert_equal(reglu(self.x), expected)

def test_swiglu(self):
expected = self.x1 * F.silu(self.x2)
torch.testing.assert_equal(swiglu(self.x), expected)
torch_assert_equal(swiglu(self.x), expected)