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: 0 additions & 4 deletions mlx/backend/cpu/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ void Matmul::eval_cpu(const std::vector<array>& inputs, array& out) {
}

void AddMM::eval_cpu(const std::vector<array>& inputs, array& out) {
if (out.dtype() != float32) {
throw std::runtime_error(
"[AddMM::eval_cpu] Currently only supports float32.");
}
if (out.size() == 0) {
out.set_data(allocator::malloc(out.nbytes()));
return;
Expand Down
9 changes: 9 additions & 0 deletions python/tests/test_blas.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,15 @@ def test_addmm(self):
expected = beta * c + alpha * (a @ b)
self.assertTrue(mx.allclose(expected, out))

# Test half precision
for t, tol in [(mx.float16, 1e-3), (mx.bfloat16, 1e-2)]:
c = mx.ones((32, 32)).astype(t)
a = mx.random.uniform(shape=(32, 32)).astype(t)
b = mx.random.uniform(shape=(32, 32)).astype(t)
out = mx.addmm(c, a, b)
expected = a @ b + c
self.assertTrue(mx.allclose(out, expected, rtol=tol, atol=tol))

def test_addmm_grad(self):
def make_ref_addmm(alpha, beta):
return lambda c, a, b: alpha * (a @ b) + beta * c
Expand Down