面向Apple Silicon的vLLM风格推理服务
vllm-mlx在Apple Silicon Mac上提供vLLM风格推理服务,集成连续批处理、分页KV缓存、前缀缓存与SSD分层缓存,并在同一进程内同时暴露OpenAI与Anthropic兼容接口。
# vllm-mlx **在一个服务器中连续批量 + OpenAI + Anthropic API. 原苹果硅推论.** **以其他语言阅读:** [联合国](<https://github.com/waybarrios/vllm-mlx/blob/main/README.md>) · [西班牙语Name](<https://github.com/waybarrios/vllm-mlx/blob/main/README.es.md>) · [法国语Name](<https://github.com/waybarrios/vllm-mlx/blob/main/README.fr.md>) · [中文](<https://github.com/waybarrios/vllm-mlx/blob/main/README.zh.md>) [](https://pypi.org/project/vllm-mlx/) [](https://pepy.tech/projects/vllm-mlx) [](https://www.python.org/downloads/) [](LICENSE) [](https://support.apple.com/en-us/HT211814) [](https://github.com/waybarrios/vllm-mlx) --- ## 什么是vllm -mlx吗? 用于 Apple 硅Macs 的 vLLM 类推论服务器。 不同 `Ollama` 或 时 间 `mlx-lm` 直接使用,它飞船 **连续批量、 页面化 KV 缓存、 前缀缓存和 SSD 级缓存**,并曝光 **两者均为OpenAI `/v1/*` 和 Athropic 数据 `/v1/messages`** 运行 LLMS 、 视觉模型、 音频和嵌入到金属上, 并有统一的内存, 没有转换步骤 。 ## 快速启动 新用户: [隔离释放安装](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/installation.md#install-a-release>) 财务报告和财务报告 [第一次反应检查](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/quickstart.md#first-response>). 下面的例子假设环境是激活的。 下载/加载时间取决于机器和连接. 下面的版本是这个行走的 固定的参考发布,而不是一个 自动更新最新版本 。 ```bash python -m pip install 'vllm-mlx==0.4.1' vllm-mlx serve mlx-community/Llama-3.2-3B-Instruct-4bit --host 127.0.0.1 --port 8000 ``` 第一次响应后, 以 `--continuous-batching` 尝试 [连续批量及其缓存选项](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/continuous-batching.md>). 上方的最小命令使用默认引擎,而不使用该旗帜. **OpenAI SDK:** 安装 `openai` 首先在 Python 客户端环境中; 它没有安装 在服务器软件包旁。见 [客户端设置](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/quickstart.md#option-1-openai-compatible-server>). ```python from openai import OpenAI client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed") r = client.chat.completions.create(model="mlx-community/Llama-3.2-3B-Instruct-4bit", messages=[{"role": "user", "content": "Hi!"}]) print(r.choices[0].message.content) ``` **Anthropic SDK / 克劳德代码:** ```bash export ANTHROPIC_BASE_URL=http://localhost:8000 export ANTHROPIC_API_KEY=not-needed claude ``` ## 编码 CLI 兼容性 **与OpenCode,pii, Codex, Claude Code, GitHub 副驾驶 CLI, Cline CLI , , , , , , 和OpenClaw的嵌入式代理.** 所有7人完成了一个流化工具互动 并在9月的一次本地运行中用 Qwen3 8.- 27B - 4bit 编辑一个精确的文件 19 , 2026. 结果适用于测试过的客户端版本和设置. 见 [已验证的 CLI 矩阵和设置指南](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/client-acceptance.md#validated-cli-versions>) 用于版本,API运输,复制命令,以及覆盖限制. ## 特征 ### APIs 辅助程序 - **OpenAI 兼容**: `/v1/chat/completions`, `/v1/completions`, `/v1/embeddings`, `/v1/rerank`, `/v1/responses` - **与人体兼容**: `/v1/messages` (流线、工具使用、系统提示) - **MCP 工具调用**:19 解析器(OpenAI,Anthropic,双子座,Quen,DeepSeek,Gemma等) - **结构化产出**: JSON Schema通过 `response_format` (lm-format-enforcer) ### 通过输出内存( M) - **连续批量**:同时提出请求的吞吐量高 - **页面化的 KV 缓存**: 内存效率与前缀共享 - **SSD 级 KV 缓存**: 将前缀缓存溢出到磁盘中, 用于长文本代理( S)`--ssd-cache-dir`) - **温暖提示**: 启动时预加载流行的前缀( P)`--warm-prompts`用于1.3 -2.25x TTFT - **前缀缓存**:基于三重程序,在请求中共享 ### 多式联运 - **文字+图像+视频+音频** 从一个服务器 - 视觉模型: Gemma 3, Gemma 4, Quen3- VL, Pixtral, Llama 视觉 - **音频输入** 聊天时( E)`audio_url` 内容块) - **原生的 TTS**:11语音,15+语言(Kokoro,Chatterbox,VibeVoice,VoxCPM). - **STT**Whisper 系列在 M4 Max 上 RTF 最高达 197 倍 ### 说明理由和高级( A) - **提取理由**: Qwen3和DeepSeek - R1 解析器(英语:`--reasoning-parser`) - **MoE 专家裁减**: `--moe-top-k` + 7 - 16% 在Qwen3-30B上 - A3B - **光谱解码**: `--enable-mtp` 用于支持的模型 - **分页预补**: 以注意力为基础 `--specprefill` 用于支持的模型/组合草稿 ### 观察性 - **普罗米修斯度量衡**: `/metrics` 结束点为 `--enable-metrics` - **内建基准器**: `vllm-mlx bench-serve` 用于使用 CSV / JSON 输出的快速扫描 ### 原生 GPU 加速 - 苹果硅(M1,M2,M3,M4,M5)通过MLX配有金属内核. - 统一内存, 不转换模型 ## 业绩 **LLM解码(M4 Max,128 GB,贪婪,单流):** | 型号 | Tok/s | 内存 | |-------|------:|-------:| | Qwen3-0.6B - 8 位元 | 417.9 | 0.7 GB | | Llama-3 2.2- 3B - 指令4位 | 205.6 | 1.8 GB | | Qwen3-30B - A3B-4 位元 | 127.7 | ~18 GB | **音频 speech-to-text(M4 Max,RTF = 实时因子):** | 型号 | RTF | 使用大小写 | |-------|----:|----------| | whisper-tiny | 197x | 实时/低延迟 | | whisper-large-v3-turbo | 55x | 质量+速度 | | whisper-large-v3 | 24x | 最高精确度 | 见 [docs/benchmarks/](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/benchmarks/>) 用于连续批斗结果,KV-cache 量化(4 -bit / 8 -bit / fp16),以及MoE 上-k扫描. ## 实例 ### Anthropic API (Claude Code, OpenCode) (英语). ```bash vllm-mlx serve mlx-community/Qwen3-8B-4bit --port 8000 export ANTHROPIC_BASE_URL=http://localhost:8000 export ANTHROPIC_API_KEY=not-needed claude ``` ### 理由模型(Qwen3,DeepSeek-R1) . ```bash vllm-mlx serve mlx-community/Qwen3-8B-4bit --reasoning-parser qwen3 ``` ```python r = client.chat.completions.create( model="mlx-community/Qwen3-8B-4bit", messages=[{"role": "user", "content": "What is 17 * 23?"}], ) print("Thinking:", r.choices[0].message.reasoning) print("Answer:", r.choices[0].message.content) ``` ### 多式联运(图像+文本) ```bash vllm-mlx serve mlx-community/Qwen3-VL-4B-Instruct-3bit --port 8000 ``` ```python r = client.chat.completions.create( model="mlx-community/Qwen3-VL-4B-Instruct-3bit", messages=[{"role": "user", "content": [ {"type": "text", "text": "What is in this image?"}, {"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}, ]}], ) ``` ### 结构化输出( JSON Schema) 快速启动的文本服务器 : ```python r = client.chat.completions.create( model="mlx-community/Llama-3.2-3B-Instruct-4bit", messages=[{"role": "user", "content": "List 3 colors."}], response_format={ "type": "json_schema", "json_schema": { "schema": {"type": "object", "properties": {"colors": {"type": "array", "items": {"type": "string"}}}} }, }, ) ``` ### 重新排队( E)`/v1/rerank`) ```bash curl http://localhost:8000/v1/rerank -H 'Content-Type: application/json' -d '{ "model": "default", "query": "apple silicon inference", "documents": ["MLX is Apples framework", "Metal kernels on M-series", "CUDA on NVIDIA"] }' ``` 内置的 MLX 重排前进路径支持标准 BERT / XLM- RoBERTa 序列分类加权数 `gelu`, `gelu_new`/`gelu_fast`, `relu`,或 `silu`/`swish` `hidden_act` 值。其他激活显然失败,所以自定义 重新排序的架构可以添加一个专用适配器,而不是默默使用 启动错误 。 ### 嵌入层 ```bash vllm-mlx serve <llm-model> --embedding-model mlx-community/all-MiniLM-L6-v2-4bit ``` ```python emb = client.embeddings.create(model="mlx-community/all-MiniLM-L6-v2-4bit", input=["Hello", "World"]) ``` ### 音频 (TTS / STT ). ```bash pip install vllm-mlx[audio] brew install espeak-ng # macOS, needed for non-English TTS python examples/tts_example.py "Hello, how are you?" --play python examples/tts_multilingual.py "Hola mundo" --lang es --play ``` ### 内设基准 ```bash vllm-mlx bench-serve --url http://localhost:8000 --concurrency 5 --prompts prompts.txt --output results.csv # Product-style workload with quality checks and metrics deltas vllm-mlx bench-serve --url http://localhost:8000 --workload workload.json --repetitions 5 --output results.json # Append workload rows into SQLite for longitudinal comparisons vllm-mlx bench-serve --url http://localhost:8000 --workload workload.json --repetitions 5 --format sqlite --output bench.db ``` ### 模型获取和转换 ```bash # Inspect repo metadata, file sizes, config, and rough fit before downloading weights vllm-mlx model inspect mlx-community/Llama-3.2-3B-Instruct-4bit # Acquire with resumable Hugging Face transfer and write a local artifact manifest vllm-mlx model acquire mlx-community/Llama-3.2-3B-Instruct-4bit --target-dir ./models/llama-3b-4bit # Wrap mlx-lm conversion and record the exact recipe in the converted artifact vllm-mlx model convert meta-llama/Llama-3.2-3B-Instruct --output ./models/llama-3b-mlx-q4 --quantize --q-bits 4 --q-group-size 64 --q-mode affine ``` ### 普罗米修斯度量衡 ```bash vllm-mlx serve <model> --enable-metrics curl http://localhost:8000/metrics ``` ## 安装 使用该 [释放走过](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/installation.md#install-a-release>) 对于一个孤立的环境和被绑定的服务器版本。如果您已经管理 具有uv的CLI工具,其孤立的等效物是: ```bash uv tool install 'vllm-mlx==0.4.1' ``` 保留 [开发检出](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/installation.md#development-checkout>) 分开。 [安装指南](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/installation.md>) (单位:千美元) 可选额外项目和 [音频指南](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/audio.md>) 用于音频设置。 ## 文档 浏览完整的文档 : [vllm-mlx.is-a.dev (英语).](https://vllm-mlx.is-a.dev/). - **开始**: [安装](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/installation.md>) · [快速启动](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/getting-started/quickstart.md>) - **服务器和 API**: [OpenAI 服务器](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/server.md>) · [Anhropic 信件 API](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/server.md#anthropic-messages-api>) · [Python API (英语).](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/python-api.md>) - **客户兼容性**: [运行编码客户端接受检查](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/client-acceptance.md>) - **特征**: [多式联运](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/multimodal.md>) · [音频](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/audio.md>) · [嵌入层](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/embeddings.md>) · [理由说明](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/reasoning.md>) · [MCP 调用工具( T)](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/mcp-tools.md>) · [工具分析器](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/tool-calling.md>) - **业绩**: [连续插头](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/continuous-batching.md>) · [多模式服务](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/model-registry.md>) · [温暖提示](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/warm-prompts.md>) · [MoE 顶级K](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/guides/moe-top-k.md>) - **参考**: [CLI](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/reference/cli.md>) · [模型](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/reference/models.md>) · [配置](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/reference/configuration.md>) - **基准**: [LLM](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/benchmarks/llm.md>) · [图像](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/benchmarks/image.md>) · [视频](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/benchmarks/video.md>) · [音频](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/benchmarks/audio.md>) ## 建筑 ``` ┌─────────────────────────────────────────────────────────────────────────┐ │ vllm-mlx Server │ │ OpenAI /v1/* · Anthropic /v1/messages · /v1/rerank · /metrics │ └─────────────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────┐ │ Continuous batching · Paged KV cache · Prefix cache · SSD tiering │ └─────────────────────────────────────────────────────────────────────────┘ │ ┌─────────────┬────────────┴────────────┬─────────────┐ ▼ ▼ ▼ ▼ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ mlx-lm │ │ mlx-vlm │ │ mlx-audio │ │mlx-embeddings │ │ (LLMs) │ │ (Vision) │ │ (TTS + STT) │ │ (Embeddings) │ └───────────────┘ └───────────────┘ └───────────────┘ └───────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────┐ │ MLX · Metal kernels · Unified memory │ └─────────────────────────────────────────────────────────────────────────┘ ``` ## 捐款 Bug 修正、 perf 工作、 文件和不同苹果硅芯片的基准都欢迎。 见 [贡献指南](<https://github.com/waybarrios/vllm-mlx/blob/main/docs/development/contributing.md>). ## 许可证 Apache 2.0. 见 [LICENSE](<https://github.com/waybarrios/vllm-mlx/blob/main/LICENSE>). ## 引用 ```bibtex @software{vllm_mlx2025, author = {Barrios, Wayner}, title = {vllm-mlx: Apple Silicon MLX Backend for vLLM}, year = {2025}, url = {https://github.com/waybarrios/vllm-mlx}, note = {Native GPU-accelerated LLM and vision-language model inference on Apple Silicon} } ``` ## 承认 - [MLX](https://github.com/ml-explore/mlx). Apple的ML框架. - [mlx-lm](https://github.com/ml-explore/mlx-lm). LLM推论库. - [mlx-vlm](https://github.com/Blaizzy/mlx-vlm). 愿景语言模型。 - [mlx-audio](https://github.com/Blaizzy/mlx-audio)。文本对语音和语音对文本。 - [mlx-embeddings](https://github.com/Blaizzy/mlx-embeddings)。文本嵌入。 - [快速 - MLX](https://github.com/raullenchai/Rapid-MLX). 社区叉 Vllm-mlx. - [vLLM 数据](https://github.com/vllm-project/vllm). 高通量 LLM service. vllm-mlx 受 vLLM 启发,通过 MLX 为苹果硅采用其连续的击打和呼呼KV-cache设计. ## 恒星历史 [](https://star-history.dera.page/#waybarrios/vllm-mlx&Date) --- **如果 vllm-mlx 帮助您, 请主播 Repo。 它可以帮助更多的苹果硅代碼找到它 。**
查看原始来源