You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] [CPU] mx.compile(shapeless=True): crash in Reduce::eval_cpu when reduced axes have size 1 #5019
☑️ I understand it is strictly prohibited to use AI to write issues.
Describe the bug
During the investigation of the CPU CI failure in #5010, I discovered that running a reduction operator under mx.compile(..., shapeless=True) (or the built-in mlx.nn.log_softmax with shapeless=True) under mx.cpu would crash when all the reduced axes had a size of 1.
Both metal/reduce.cpp and cuda/reduce.cu have already performed copy_gpu early termination for in.size() > 0 && out.size() == in.size(), but Reduce::eval_cpu in mlx/backend/cpu/reduce.cpp missed this branch, that's the root cause of the crash.
To Reproduce
importmlx.coreasmxwithmx.stream(mx.cpu):
fn=mx.compile(lambdax: x.sum(axis=0), shapeless=True)
mx.eval(fn(mx.ones((4, 8))))
y=fn(mx.ones((1, 8)))
mx.eval(y)
print(y)
# Note: mlx.nn.log_softmax(mx.array([[1.5], [-2.0]]), axis=-1) also crashes directly on mx.cpu
Expected behavior
It doesn't crash; it returns an all-ones array of shape (8,) just like mx.gpu.
Desktop (please complete the following information):
OS Version: macOS 15.8.3 (arm64, Apple M3 Max)
Version: 0.32.5 (also reproduced on main @ b343960)
Activity