Skip to content

mps: amax drops NaN and answers -FLT_MAX for all -inf; randn fails at an F64 -> F32 cast #49

Closed

Description

@b-re-w

Found by #29's design round (measured on the current build, this Mac):

  • aten.amax.default on mps returns -FLT_MAX (f16: -65504, bf16: -3.39e38) for an all--inf input, and drops NaN: amax([nan, 1]) is 1.0. Cause: candle's Metal reduce fold starts from the finite lowest value, not -inf, and skips NaN. The same helper feeds softmax's row max.
  • torch.randn(..., device='mps') fails with aten.normal_: Metal contiguous to_dtype F64 F32. eq and to(bool) on an empty mps tensor take an F32 -> F64 path.
  • min([0., -0., 0., -0.]) on cpu returns 0.0 where upstream returns -0.0. The golden comparator cannot see the sign of zero.

Done when

  • amax/amin/max/min on mps agree with upstream for all-±inf, NaN and ties, using mps: generate stops at zero-element tensors and at the host-readback ops (isin, argmax, ...) #29's first_extremum_index + gather approach. Counters show Metal computed them.
  • randn/normal_ on mps compute on the device and agree with upstream's distribution checks (or draws, if the stream can match). Otherwise they refuse by name.
  • The golden comparator distinguishes ±0.0, and the min case is fixed.
  • Nullified. Gate green.

Activity

  1. b-re-w commented on Oct 5, 2026

    @b-re-w
    MemberAuthor

    Paused before starting (user's instruction). Next in the correctness queue after #33.

  2. b-re-w commented on Oct 16, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions