mlx icon indicating copy to clipboard operation
mlx copied to clipboard

Different outputs of mlx.core.max using cpu/gpu

Open Redempt1onzzZZ opened this issue 1 year ago • 1 comments

Describe the bug Different(maybe wrong) outputs of mlx.core.max using cpu/gpu compared to numpy

To Reproduce

import mlx.core as mx
import numpy as np
array_mlx = mx.array([[1, 2, 3], [float('nan'), 5, 6]], dtype=mx.float32)

mx.set_default_device(mx.gpu)
max_gpu = mx.max(array_mlx, axis=0)
print("Max on GPU:", max_gpu)

mx.set_default_device(mx.cpu)
max_cpu = mx.max(array_mlx, axis=0)
print("Max on CPU:", max_cpu)

a_np = np.array([[1, 2, 3], [float('nan'), 5, 6]], dtype=np.float32)
max_np = np.max(a_np, axis=0)
print("Max using NumPy:", max_np)

image

Desktop (please complete the following information):

  • OS Version: MacOS 14.2.1
  • Version 0.0.10

Redempt1onzzZZ avatar Jan 29 '24 07:01 Redempt1onzzZZ

Actually this one is not so easy to fix as we use the simd instructions in Metal. The NaN are being suppressed there.

awni avatar Jan 29 '24 14:01 awni