跳转至

MLC LLM 本地部署配置

通用 LLM 部署引擎,支持移动端(iOS/Android)、浏览器(WebGPU)和本地推理


系统要求

项目 最低要求 推荐
Python 3.8+ 3.10+
GPU NVIDIA / Apple Silicon / Vulkan
内存 8 GB 16 GB+

安装

pip 安装

Bash
pip install mlc-llm

CLI 使用

Bash
1
2
3
4
5
6
7
8
# 对话(自动下载模型)
mlc_llm chat HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC

# 指定 GPU
mlc_llm chat HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC --device cuda

# Apple Silicon
mlc_llm chat HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC --device metal

REST API 服务

Bash
1
2
3
mlc_llm serve HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC \
  --host 0.0.0.0 \
  --port 8000
Bash
1
2
3
4
curl http://localhost:8000/v1/chat/completions -d '{
  "model": "Qwen2.5-1.5B-Instruct",
  "messages": [{"role": "user", "content": "你好"}]
}'

移动端部署

iOS

Bash
1
2
3
# 编译 iOS App
mlc_llm compile HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC --target iphone
mlc_llm package --target iphone

Android

Bash
mlc_llm compile HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC --target android
mlc_llm package --target android

Web 浏览器部署

Bash
1
2
3
4
5
# 编译为 WebGPU
mlc_llm compile HF://mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC --target webgpu

# 在浏览器中运行
mlc_llm serve --target webgpu

练习清单

  • 安装 MLC LLM,运行 CLI 对话
  • 启动 REST API 服务
  • 尝试 WebGPU 浏览器推理