Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

MLX

Run local AI models on Apple Silicon with MLX. Models run on your Mac with Metal acceleration on M1, M2, M3, and M4 chips.

What is the Autohand MLX integration?

The Autohand MLX integration runs supported language models locally on Apple Silicon. Autohand sends model requests to a local MLX server, which runs a locally available model on your Mac.

Status Available
Requires Apple Silicon, a supported Autohand Code CLI version, the MLX runtime, and enough memory for the selected model.
Configure with Install the required MLX dependencies and model, then select the mlx provider and model in ~/.autohand/config.json or the CLI.
Best for Local inference on M-series Macs.

Overview

MLX is Apple’s machine learning framework optimized for Apple Silicon. Built by Apple’s machine learning research team and available on GitHub, MLX provides a NumPy-like API with automatic differentiation, lazy computation, and unified memory. When integrated with Autohand, you get:

  • Native Metal acceleration on M1, M2, M3, and M4 chips
  • Unified memory architecture for efficient model loading
  • Model requests go to the MLX server on your Mac, not a cloud model API
  • No API costs with unlimited local inference
  • Low latency responses from your local hardware
  • Support for popular open-source models in MLX format

Requirements

Before setting up MLX, make sure you meet these requirements:

Hardware

  • Mac with Apple Silicon (M1, M2, M3, or M4 series)
  • Minimum 8GB unified memory (16GB+ recommended)
  • macOS Sonoma 14.0 or later recommended

Software

  • Python 3.9 or later
  • pip or uv package manager
  • Autohand Code CLI v0.7.4 or later (latest release recommended)

Memory recommendations

Unified Memory Recommended Models
8GB 3B-7B parameter models (4-bit quantized)
16GB 7B-13B parameter models
32GB 13B-34B parameter models
64GB+ 34B-70B+ parameter models

Installation

Install the MLX LM package to run a local inference server.

Install mlx-lm

The mlx-lm package provides both the inference engine and an OpenAI-compatible server:

# Using pip
pip install mlx-lm

# Using uv (faster)
uv pip install mlx-lm

# Verify installation
python -c "import mlx_lm; print('MLX LM installed successfully')"

Download a model

MLX models are available on Hugging Face. Download one optimized for coding:

# Download a coding-optimized model
mlx_lm.convert --hf-path Qwen/Qwen2.5-Coder-7B-Instruct -q

# Or download a pre-converted MLX model
pip install huggingface_hub
huggingface-cli download mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

Start the server

Run the OpenAI-compatible API server:

# Start the server with your model
mlx_lm.server --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

# Or specify a local model path
mlx_lm.server --model ./models/qwen2.5-coder-7b-mlx

# The server runs on http://localhost:8080 by default

Verify the server

# Check if the server is running
curl http://localhost:8080/v1/models

# Test a completion
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Hello!"}],
    "max_tokens": 50
  }'

CLI configuration

Configure Autohand to use MLX as your model provider in ~/.autohand/config.json:

{
  "provider": "mlx",
  "mlx": {
    "baseUrl": "http://localhost:8080",
    "model": "mlx-community/Qwen2.5-Coder-7B-Instruct-4bit"
  }
}

Or use YAML format in ~/.autohand/config.yaml:

provider: mlx
mlx:
  baseUrl: http://localhost:8080
  model: mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

Configuration options

Option Description Default
baseUrl MLX server URL http://localhost:8080
port Server port (alternative to baseUrl) 8080
model Model name for display mlx-model

There are no temperature or maxTokens provider keys. Use --temperature to set sampling temperature for a run.

Environment variables

AUTOHAND_PROVIDER overrides the configured provider. The CLI does not read AUTOHAND_MODEL for MLX, so pass the model with --model:

export AUTOHAND_PROVIDER="mlx"
autohand --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

Tool calling depends on the model and server. An OpenAI-compatible endpoint alone does not guarantee usable tool calls. Confirm that the selected model, its chat template and your server support the tools your task needs. Memory use also grows with context size; these examples are starting points, not performance guarantees.

Available models

The MLX community maintains optimized versions of popular models on Hugging Face.

Coding models

Model Parameters CLI memory estimate Starting point
mlx-community/Qwen2.5-Coder-7B-Instruct-4bit 7B About 8GB First coding model
mlx-community/Qwen2.5-Coder-14B-Instruct-4bit 14B About 16GB Larger coding model
mlx-community/DeepSeek-Coder-V2-Lite-Instruct-4bit 16B MoE About 10GB Alternative for coding

The coding choices above match the CLI’s curated MLX fallbacks. Memory figures are CLI estimates, not hardware guarantees: leave room for macOS, the context cache and other applications.

General-purpose models

Model Parameters Memory Best for
mlx-community/Llama-3.2-3B-Instruct-4bit 3B 4GB Quick responses
mlx-community/Meta-Llama-3.1-8B-Instruct-4bit 8B 8GB General tasks
mlx-community/Mistral-7B-Instruct-v0.3-4bit 7B 8GB Efficient reasoning
mlx-community/Mixtral-8x7B-Instruct-v0.1-4bit 47B 32GB Expert-level tasks

Download and run models

# Start server with a Hugging Face model (downloads automatically)
mlx_lm.server --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

# Use a quantized model for lower memory usage
mlx_lm.server --model mlx-community/Meta-Llama-3.1-8B-Instruct-4bit

# Switch models in Autohand during a session (opens the model picker)
/model

Server options

Fine-tune the mlx-lm server for optimal performance:

Basic options

mlx_lm.server \
  --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit \
  --host 127.0.0.1 \
  --port 8080

Memory and performance

# Use 4-bit quantization for lower memory
mlx_lm.server \
  --model mlx-community/Meta-Llama-3.1-8B-Instruct-4bit

# Specify cache directory for models
mlx_lm.server \
  --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit \
  --cache-dir ~/.cache/mlx-models

Server options reference

Option Description
--model Hugging Face model ID or local path
--host Server host address
--port Server port (default: 8080)
--cache-dir Model cache directory

Commands

Use these commands to interact with MLX through Autohand:

Switch to MLX

# Start Autohand with MLX
autohand --provider mlx --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

# Or open the model picker during a session
/model

Check connection

# Test the MLX server
curl http://localhost:8080/v1/models

# Check server health
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "test"}], "max_tokens": 5}'

Converting models

Convert Hugging Face models to MLX format for optimal performance:

Convert a model

# Convert with default settings
mlx_lm.convert --hf-path Qwen/Qwen2.5-Coder-7B-Instruct

# Convert with 4-bit quantization (recommended for most users)
mlx_lm.convert --hf-path Qwen/Qwen2.5-Coder-7B-Instruct -q

# Specify output directory
mlx_lm.convert \
  --hf-path Qwen/Qwen2.5-Coder-7B-Instruct \
  --mlx-path ./models/qwen2.5-coder-7b-mlx \
  -q

Quantization options

Option Bits Memory Quality
None (default) 16 Highest Best
-q 4 Lowest Good
--q-bits 8 8 Medium Better

Best practices

  • Use quantized models: 4-bit quantized models offer the best balance of quality and memory usage on Apple Silicon.
  • Match model to memory: Choose models that fit comfortably in your unified memory with room for the OS and other apps.
  • Keep the server running: Start the MLX server once and keep it running to avoid model reload times.
  • Use coding models for code: Start with Qwen2.5-Coder or the DeepSeek-Coder-V2-Lite MLX choice, then check the result against your project tests.
  • Monitor Activity Monitor: Check memory pressure in Activity Monitor to ensure you’re not swapping.

Start with Qwen2.5-Coder 7B

{
  "provider": "mlx",
  "mlx": {
    "model": "mlx-community/Qwen2.5-Coder-7B-Instruct-4bit"
  }
}

Try Qwen2.5-Coder 14B with more headroom

{
  "provider": "mlx",
  "mlx": {
    "model": "mlx-community/Qwen2.5-Coder-14B-Instruct-4bit"
  }
}

Try DeepSeek-Coder-V2-Lite as an alternative

{
  "provider": "mlx",
  "mlx": {
    "model": "mlx-community/DeepSeek-Coder-V2-Lite-Instruct-4bit"
  }
}

Troubleshooting

Common issues

Issue Solution
MLX not supported error MLX only works on Apple Silicon Macs. Use Ollama or llama.cpp instead.
Connection refused Start the MLX server: mlx_lm.server --model your-model
Out of memory Use a smaller or 4-bit quantized model
Slow responses Close other memory-intensive apps or use a smaller model
Model not found Check the model path or Hugging Face model ID

Check platform support

# Verify Apple Silicon
uname -m
# Should output: arm64

# Check macOS version
sw_vers
# Should show macOS 14.0 or later for best performance

Debug mode

# Run Autohand with debug logging
AUTOHAND_DEBUG=true autohand --provider mlx

# Check MLX server logs
mlx_lm.server --model your-model 2>&1 | tee mlx-server.log

Memory pressure

If you see yellow or red memory pressure in Activity Monitor:

  • Switch to a smaller model (7B instead of 13B)
  • Use 4-bit quantization
  • Close other memory-intensive applications
  • Restart the MLX server to clear cached data

MLX vs other providers

Choose the right local provider for your setup:

Feature MLX Ollama llama.cpp
Platform Apple Silicon only All platforms All platforms
Setup Python package Single binary Build from source
Performance on Mac Excellent Good Good
Memory efficiency Excellent Good Good
Model format MLX/Safetensors Ollama format GGUF
Best for Apple Silicon users Easy setup Maximum control
How do I configure the Autohand MLX integration?

Install the required MLX dependencies and model, then select the mlx provider and model in ~/.autohand/config.json or the CLI.

What does the Autohand MLX integration require?

Apple Silicon, a supported Autohand Code CLI version, the MLX runtime, and enough memory for the selected model.

What limitations should I know about?

Model compatibility, context size, speed, and memory use vary with the model and Apple Silicon hardware.

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification