mirror of
https://github.com/ml-explore/mlx.git
synced 2025-10-19 00:04:41 +08:00
Added ALiBi implementation (#232)
This commit is contained in:
@@ -570,6 +570,18 @@ class TestNN(mlx_tests.MLXTestCase):
|
||||
y = rope(x.astype(mx.float16))
|
||||
self.assertTrue(y.dtype, mx.float16)
|
||||
|
||||
def test_alibi(self):
|
||||
for kwargs in [{"num_heads": 8}]:
|
||||
alibi = nn.ALibi(**kwargs)
|
||||
shape = [1, 8, 20, 20]
|
||||
x = mx.random.uniform(shape=shape)
|
||||
y = alibi(x)
|
||||
self.assertTrue(y.shape, shape)
|
||||
self.assertTrue(y.dtype, mx.float32)
|
||||
|
||||
y = alibi(x.astype(mx.float16))
|
||||
self.assertTrue(y.dtype, mx.float16)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user