Chuyển tới nội dung chính

MLX LM trên Apple Silicon

Plugin MLX LM (Apple Silicon) chạy mô hình MLX trực tiếp trên Mac M-series qua API MLX LM.

Kiến trúc

Libre WebUI in native development mode
frontend http://localhost:5173
backend http://localhost:3001
|
| OpenAI-compatible chat request
v
mlx_lm.server http://127.0.0.1:8081
|
v
MLX model on Apple Silicon unified memory

Dùng port 8081 để tránh xung đột với cổng mặc định 8080 của MLX và npx libre-webui.

Yêu cầu

  • Mac M1+
  • Python 3.10+
  • Bộ nhớ đủ
  • Libre WebUI chạy trực tiếp

Ternary Bonsai khoảng 8,5 GB; 24 GB RAM cho dư địa tốt hơn.

Cài MLX LM

brew install uv
uv tool install --upgrade mlx-lm
rehash
mlx_lm.server --help
uv tool upgrade mlx-lm
rehash

Qwen 3.5 cần mlx-lm 0.30.7+, ví dụ cần 0.31.3+.

Chạy máy chủ

mlx_lm.server \
--model "prism-ml/Ternary-Bonsai-27B-mlx-2bit" \
--host 127.0.0.1 \
--port 8081 \
--max-tokens 262144 \
--allowed-origins "http://localhost:5173,http://127.0.0.1:5173"

Lần đầu tải từ Hugging Face. Prompt và đầu ra chia sẻ 262144 vị trí tối đa.

mlx_lm.server \
--model "mlx-community/Llama-3.2-3B-Instruct-4bit" \
--host 127.0.0.1 \
--port 8081 \
--max-tokens 2048
cd examples/mlx-lm-server
uv run server.py
uv run server.py --dry-run

Kiểm tra API

curl http://127.0.0.1:8081/health
curl http://127.0.0.1:8081/v1/models
curl http://127.0.0.1:8081/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "prism-ml/Ternary-Bonsai-27B-mlx-2bit",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Reply with: MLX is ready."}
],
"temperature": 0.7,
"top_p": 0.95,
"max_tokens": 64,
"stream": false
}'

Hỗ trợ Server-Sent Events khi "stream": true.

Kết nối Libre WebUI

npm install
npm run dev

Mở http://localhost:5173.

  1. Settings > Plugins.
  2. Chọn MLX LM (Apple Silicon).
  3. Endpoint http://127.0.0.1:8081/v1/chat/completions phải chứa /v1/chat/completions.
  4. Kích hoạt.
  5. Chọn mô hình.
  • prism-ml/Ternary-Bonsai-27B-mlx-2bit

Thêm ID khác vào model_map trong plugins/mlx-lm.json nếu cần.

Cài đặt tạo sinh

Cài đặtGiá trị
Temperature0.7
Top P0.95
Top K20

Chạy với --top-k 20:

mlx_lm.server \
--model "prism-ml/Ternary-Bonsai-27B-mlx-2bit" \
--host 127.0.0.1 \
--port 8081 \
--top-k 20 \
--max-tokens 262144

Work và công cụ

Chỉ dùng trong Work nếu mô hình hỗ trợ gọi công cụ OpenAI đáng tin cậy. Cập nhật mlx-lm nếu lệnh lỗi.

Mạng Docker

Vùng chứa không thể tới 127.0.0.1 của Mac.

  1. Dùng --host 0.0.0.0.
  2. Dùng http://192.168.1.20:8081/v1/chat/completions.
  3. Chỉ mở mạng tin cậy.

Không mở mlx_lm.server công khai; dùng proxy HTTPS.

Khắc phục

Model type qwen3_5 not supported

rehash
which -a mlx_lm.server
uv tool upgrade mlx-lm
curl http://127.0.0.1:8081/v1/models

Địa chỉ bận

mlx_lm.server --model "owner/model" --port 8082

Dùng http://127.0.0.1:8082/v1/chat/completions.

Lần đầu chậm

Theo dõi Activity Monitor.

Liên quan