Validate dims in rope (#3230)

Co-authored-by: KD2YCU <[email protected]>
This commit is contained in:
Dan Anderson
2026-03-09 21:48:45 -07:00
committed by GitHub
co-authored by KD2YCU
parent 9bbd375eec
commit 572e0a4ac3
2 changed files with 52 additions and 0 deletions
+35
View File
@@ -169,6 +169,41 @@ class TestFast(mlx_tests.MLXTestCase):
x, dims, traditional=traditional, base=base, scale=scale, offset=offset
)
def test_rope_dims_validation(self):
T = 4
feature_dim = 64
x = mx.random.uniform(shape=(1, T, feature_dim))
# dims = 0 should raise
with self.assertRaises(ValueError):
mx.fast.rope(
x, dims=0, traditional=False, base=10000.0, scale=1.0, offset=0
)
# negative dims should raise
with self.assertRaises(ValueError):
mx.fast.rope(
x, dims=-2, traditional=False, base=10000.0, scale=1.0, offset=0
)
# odd dims should raise
with self.assertRaises(ValueError):
mx.fast.rope(
x, dims=7, traditional=False, base=10000.0, scale=1.0, offset=0
)
# dims > feature_dim should raise
with self.assertRaises(ValueError):
mx.fast.rope(
x, dims=128, traditional=False, base=10000.0, scale=1.0, offset=0
)
# valid dims should not raise
mx.fast.rope(x, dims=32, traditional=False, base=10000.0, scale=1.0, offset=0)
mx.fast.rope(
x, dims=feature_dim, traditional=False, base=10000.0, scale=1.0, offset=0
)
def test_rope_with_freqs(self):
mx.random.seed(0)