Skip to content

Phase C: MLX backend port for AMICATorchNG (Apple-native GPU) #76

Description

@neuromechanist

Context

Higher-ceiling Apple-GPU path of the epic. MLX (Apple's array framework) beats PyTorch
MPS by ~2-3x on the same hardware, is Apple-native with a real compiler / lazy graph, and
can fuse the per-block work that PyTorch MPS runs eager and largely unfused. GPU arrays are
float32-only, so this depends on Phase A.

Approach

  • Port the AMICATorchNG per-block E/M-step to MLX arrays behind a backend switch, keeping
    the PyTorch path as the float64 parity / CUDA backend.
  • Reuse the Phase A mixed-precision strategy (float64 accumulation on CPU where MLX allows,
    float32 on GPU).
  • Keep MLX an optional dependency (not required for the core install).

Acceptance

  • MLX backend produces results equivalent to the PyTorch float32 backend on the sample data
    (matched LL within tolerance).
  • Behavior-validated (no bit-exact float64 oracle is possible on an Apple GPU).
  • Optional-dependency install path documented.

Dependencies

Blocked by Phase A (MLX GPU is float32-only). Research: .context/mps_pathways.md
Pathway C.

Activity

  1. neuromechanist commented on Jul 8, 2026

    @neuromechanist
    MemberAuthor

    Done via PR #79 (squash-merged into the epic branch feature/issue-74-epic-apple-gpu, commit 4ff3a11). AMICAMLXNG (pyAMICA/mlx_impl/core.py) is a v1 MVP: single-model, generalized-Gaussian, natural gradient. Hybrid design forced by MLX 0.32 (GPU float32 hot path + CPU-stream inv/slogdet hoisted to once/iter + host-side SciPy for the missing lgamma/digamma), carrying the Phase A ufp/y guard. Validated on real EEG: sufficient stats match the NumPy float64 reference to rtol ~1e-4, converged LL matches the PyTorch float32 backend to ~2e-6. Optional dependency (Apple-only), so CI skips the MLX tests (and mlx_impl is omitted from the coverage gate). Newton, the other PDF families, sharing, multi-model, and save/load are fast-follows. Whether MLX beats CPU/MPS is Phase B's question. Phase C of epic #74.

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

    featureNew feature or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions