mlx-lm
LLMs with MLX and the Hugging Face Hub
What it is and what it does
MLX LM is a Python package that brings large language model inference, generation, fine-tuning, and quantization to Apple silicon Macs. It wraps the MLX framework and integrates with Hugging Face Hub to let you download and run thousands of pre-built models with a single command or Python call. The package works both as a command-line tool (mlx_lm.generate, mlx_lm.chat) and as a Python module, supporting streaming generation, custom sampling, prompt caching, and rotating key-value caches for long-context work.
The package handles model quantization and can upload converted models back to Hugging Face. It supports low-rank and full model fine-tuning, including on quantized models, and offers distributed inference and fine-tuning via mx.distributed. Runtime dependencies include mlx, numpy, transformers, sentencepiece, protobuf, pyyaml, and jinja2—all standard ML and NLP libraries.
Use it for:
- Run open-source LLMs locally on a Mac for chat, text generation, or code completion without cloud APIs.
- Quantize and convert models from Hugging Face to MLX format for efficient inference on Apple silicon.
- Fine-tune existing models on your own data using low-rank or full fine-tuning with quantized weights.
- Build interactive chat applications with persistent context using the Python API or command-line REPL.
- Cache long prompts to speed up repeated queries with the same context across multiple generations.
- Distribute inference and fine-tuning workloads across multiple devices using mx.distributed.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
MLX LM loads, generates text with, fine-tunes, and quantizes large language models on Apple silicon using the MLX framework and Hugging Face Hub integration.
Yes, if you have Apple silicon and want to run LLMs locally. The package is actively maintained, has no known vulnerabilities, installs cleanly, and offers a mature feature set including generation, fine-tuning, quantization, streaming, and caching. The MIT license imposes no restrictions. The main blocker is hardware: you need a Mac with Apple silicon; it will not work on Intel or non-macOS systems.
Install
mlx-lm on PyPI
pip
pip install mlx-lmuv
uv add mlx-lmpoetry
poetry add mlx-lmInstalling mlx-lm
Before you install
Low friction installation as a pure Python wheel. Active maintenance with recent commits and a substantial user base (top 5000 PyPI packages). Seven runtime dependencies are all well-established libraries.
License in practice
MIT license is permissive; you can use, modify, and distribute this package with minimal legal restrictions.
Quickstart
pip install mlx-lm
from mlx_lm import load, generate
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
text = generate(model, tokenizer, prompt="Hello", verbose=True)
Requires macOS with Apple silicon and MLX framework support; large models may require macOS 15.0 or higher for optimal performance.
Verify before relying
- Whether all quantization formats are equally stable across different model architectures.
- Performance characteristics and memory overhead for distributed inference and fine-tuning with mx.distributed.
- Exact list of supported model architectures beyond the examples provided in the description.
- Hardware requirements and performance characteristics on different Apple silicon generations.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — mlx, numpy, transformers, sentencepiece, protobuf, pyyaml, jinja2 |
| Maintenance | actively maintained — 114 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,412,545/month — #3,933 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mlx_lm-0.31.3-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
mlx-vlmMLX-VLM runs vision language models and omni…
permissive · top 5,000 on PyPI
mlx-whisperRuns OpenAI's Whisper speech recognition models…
permissive · top 15,000 on PyPI
text-generationProvides a Python client to query text…
permissive · top 15,000 on PyPI
lmstudioPython SDK for interacting with LM Studio, a…
unclear · top 15,000 on PyPI
mlxMLX is an array framework for machine learning…
permissive · top 5,000 on PyPI
renderersConverts chat messages to token IDs for LLM…
permissive · top 15,000 on PyPI
llmcompressorllmcompressor optimizes large language models…
permissive · top 15,000 on PyPI
mlx-audioMLX-Audio provides text-to-speech,…
permissive · top 15,000 on PyPI
llama-modelsProvides a CLI and Python interface to…
unclear · top 15,000 on PyPI
lm-evalUnified framework for evaluating generative…
permissive · top 5,000 on PyPI