New Tool Radar

AI Concepts

How to Convert a Hugging Face Model to MLX Format

Convert a Hugging Face model to MLX format with mlx_lm.convert, optionally quantized to 4-bit, and upload it to the Hub.

Schematic diagram with four steps: install mlx-lm with pip, run mlx_lm.convert with -q, check the converted model in mlx_model, then optionally upload it to the Hub.

MLX models are not the same files as the Hugging Face originals: they are converted to MLX format, usually with 4-bit quantization, and published under names like mlx-community/...-4bit. mlx_lm.convert does the conversion from the command line or from Python.

Convert and quantize from the command line

Install mlx-lm with pip install mlx-lm on an Apple Silicon Mac, then run mlx_lm.convert --model mistralai/Mistral-7B-Instruct-v0.3 -q to convert and quantize the model. The converted model is saved in the path mlx_model by default. Add --upload-repo mlx-community/my-4bit-mistral to upload the converted model to the Hugging Face Hub in the same step.

pip install mlx-lm
mlx_lm.convert --model mistralai/Mistral-7B-Instruct-v0.3 -q
# or from Python:
# from mlx_lm import convert
# convert(repo, quantize=True, upload_repo=upload_repo)

MLX runs on Apple Silicon only — an Intel Mac or a Linux machine cannot run it. The converted model is a new set of weights: keep the original Hugging Face repo untouched, and check the converted model’s size before uploading it anywhere.

Try it: four checks

Check What you should see If you do not see it
mlx-lm installed pip install mlx-lm succeeds Apple Silicon Mac only
Convert runs mlx_lm.convert finishes without an error Check the model name spelling
Model saved The converted model is in mlx_model Check the disk space first
Quantized The output is a 4-bit model The -q flag does the quantization

Expected result. We checked the mlx-lm README, which documents pip install mlx-lm, mlx_lm.convert –model … -q, the default mlx_model output path, and –upload-repo. We did not convert a model on this machine.

Limits

This guide covers the convert command only. MLX needs Apple Silicon, and the converted weights are a separate copy. We did not test any conversion ourselves.

Sources

See all