Skip to content

MLX Backend (Apple Silicon)

OpenMed v1.0.0 introduces native Apple Silicon acceleration via Apple MLX.

That MLX story now has two surfaces:

  • Python MLX through openmed[mlx] on Apple Silicon Macs
  • Swift MLX through OpenMedKit on Apple Silicon macOS and real iPhone/iPad hardware

Installation

# From the repository root
pip install -e ".[mlx]"

This installs mlx, huggingface-hub, transformers, tokenizers, and safetensors.

Quick Start

from openmed import analyze_text
from openmed.core.config import OpenMedConfig

# MLX is auto-detected on Apple Silicon — no config needed
result = analyze_text(
    "Patient John Doe, DOB 1990-05-15, SSN 123-45-6789",
    model_name="pii_detection",
)
print(result.entities)

To force a specific backend:

config = OpenMedConfig(backend="mlx")   # Force MLX
config = OpenMedConfig(backend="hf")    # Force HuggingFace/PyTorch
config = OpenMedConfig(backend=None)    # Auto-detect (default)

How It Works

  1. Auto-detection: On Apple Silicon Macs with mlx installed, OpenMed automatically selects the Python MLX backend.
  2. Artifact packaging: Supported conversions now produce a self-contained MLX artifact with:
  3. openmed-mlx.json
  4. config.json
  5. id2label.json
  6. tokenizer assets
  7. weights.safetensors by default
  8. weights.npz as a fallback when needed
  9. Shared contract: That same MLX artifact shape is now the contract for both Python MLX and Swift MLX.
  10. Identical output shape: MLX produces the same entity format as the HuggingFace backend, so downstream entity merging and PII handling stay consistent.

The public runtime focuses on automatic preparation at first use. OpenMed's broader cross-architecture conversion work is still being generalized privately across the full model collection.

Architecture Coverage

As of April 8, 2026, the current public BERT-family MLX path covers these families:

  • bert
  • distilbert
  • roberta
  • xlm-roberta
  • electra

Python MLX also has the DeBERTa-v2 / DeBERTa-v3 pilot path, but Swift MLX v1 is intentionally limited to the BERT-family encoder rollout above.

Architectures still in active rollout:

  • modernbert
  • longformer
  • eurobert
  • qwen3

That rollout is about making the converter universal and repeatable across the whole OpenMed collection, not just a single pilot checkpoint.

Fallback Behavior

If MLX is not available (non-Apple hardware, or mlx not installed), OpenMed automatically falls back to the HuggingFace/PyTorch backend. No code changes required.

MLX and Swift Apps

OpenMedKit can now load supported OpenMed MLX artifacts directly in Swift.

  • Use Python MLX when you are running OpenMed from Python on Apple Silicon.
  • Use Swift MLX when you want the same supported MLX artifact to run in an Apple app on:
  • Apple Silicon macOS
  • a real iPhone/iPad device
  • Use CoreML when you already have a bundled Apple model package or need a fallback path outside Swift MLX.

Swift MLX does not target iOS Simulator.

Swift MLX Quick Start

import OpenMedKit

let modelDirectory = try await OpenMedModelStore.downloadMLXModel(
    repoID: "OpenMed/OpenMed-PII-ClinicalE5-Small-33M-v1-mlx",
    authToken: "<token-if-private>"
)

let openmed = try OpenMed(
    backend: .mlx(modelDirectoryURL: modelDirectory)
)

let entities = try openmed.analyzeText(
    "Patient John Doe, DOB 1990-05-15, SSN 123-45-6789"
)

See OpenMedKit (Swift) for the full Swift setup flow.