Skip to main content
Use MLX for running models on Apple Silicon Macs with Metal GPU acceleration.
MLX leverages unified memory architecture on Apple Silicon, allowing seamless data sharing between CPU and GPU. The mlx-lm package provides a simple interface for loading and serving LLMs.

Installation

Install the MLX language model package:

Basic Usage

The mlx-lm package provides a simple interface for text generation with MLX models. See the Models page for all available MLX models, or browse MLX community models at mlx-community LFM2 models.

Generation Parameters

Control text generation behavior using parameters in the generate() function. Key parameters:
  • temperature (float, default 1.0): Controls randomness (0.0 = deterministic, higher = more random). Typical range: 0.1-2.0
  • top_p (float, default 1.0): Nucleus sampling - limits to tokens with cumulative probability ≤ top_p. Typical range: 0.1-1.0
  • top_k (int, default 50): Limits to top-k most probable tokens. Typical range: 1-100
  • max_tokens (int): Maximum number of tokens to generate
  • repetition_penalty (float, default 1.0): Penalty for repeating tokens (>1.0 = discourage repetition). Typical range: 1.0-1.5
Example with custom parameters:

Streaming Generation

Stream responses with stream_generate():

Serving with mlx-lm

MLX can serve models through an OpenAI-compatible API. Start a server with:

Using the Server

Once running, use the OpenAI Python client:
You can also use curl to interact with the server:

Vision Models

LFM2-VL models support both text and image inputs for multimodal inference. Use mlx_vlm to load and generate with vision models: