Skip to content

MLX backend has no convergence stops: every fit runs to max_iter #248

Closed

Description

@neuromechanist

What

pamica/mlx_impl/core.py implements neither convergence stop. Verified by
grep — zero references to any of:

min_dll, use_min_dll, maxincs, min_nd, use_grad_norm, ndtmpsum

Its only stop_reason values are max_iter (:570), lrate_floor (:659) and the
degenerate ones (nan_ll/singular_ll :590, nan_params :634). So an MLX fit
runs the full iteration budget unless the learning rate floors or the fit
degenerates.

The other backends stop on likelihood stagnation (min_dll, on by default at
1e-9) long before max_iter on real data — measured at iteration 326-1076 on
the bundled sample depending on the BLAS build. The same nominal configuration
therefore does materially different work on MLX than on PyTorch/NumPy/Fortran.

Why it matters

Unsupported parameters fail loudly today — the constructor rejects unknown
kwargs with TypeError, and do_newton=True/non-GG pdftype raise
NotImplementedError. But this gap is silent: nothing signals that the fit
had no convergence criterion. A user moving a working config from the PyTorch
backend to MLX for the documented Apple-GPU speedup (~15-25 ms/it, ~7x
torch-CPU, AGENTS.md) gets a fit that quietly ignores stopping and burns the
whole budget.

It also makes MLX unable to participate in convergence-behavior claims. #218
documents that min_nd is unreachable on small recordings "in any of the three
implementations"; MLX cannot be evaluated on that axis at all, because it never
computes the gradient norm.

Scope

  1. min_dll / use_min_dll / maxincs — the consecutive-small-gain rule
    (amica15.f90:1060-1072). The likelihood is already computed per iteration, so
    this is the cheap half and the one that changes real runs.
  2. min_nd / use_grad_norm — requires accumulating ndtmpsum (Fortran
    amica15.f90:1731-1743). Note the gradient norm is also a useful diagnostic in
    its own right (epic Epic: diagnostic outputs - parity, cost and verification (nd / LLt / MIR) #231), independent of the stop.
  3. Decide whether lrate_floor's missing .or. (ndtmpsum .le. min_nd) half
    (the grad_norm_floor stop) comes along with (2).

Per .rules/backend_parity.md this should land with cross-backend tests
asserting MLX stops at the same iteration as the PyTorch backend on the same
data and config, within float32 tolerance.

The divergence is documented meanwhile in docs/guides/amica-differences.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions