M1 Max Mac版本实测 Rapid-MLX 项目(据说比ollama快4倍)

我想把Rapid-MLX这个项目跑起来:

shell 复制代码
https://github.com/raullenchai/Rapid-MLX

此教程只是作为记录,实测下来,感觉没那么快,第一个问题出来得比较快,但是第二个问题出来得比较慢,一直打印这个内容:

shell 复制代码
INFO:vllm_mlx.scheduler:[Metal memory] active=5.7GB peak=5.8GB cache=0.0GB step=4864 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #180 disconnected=False elapsed=90.3s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.7GB peak=5.8GB cache=0.0GB step=5120 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #190 disconnected=False elapsed=95.3s
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #200 disconnected=False elapsed=100.3s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.7GB peak=5.8GB cache=0.0GB step=5376 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #210 disconnected=False elapsed=105.3s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.7GB peak=5.8GB cache=0.0GB step=5632 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #220 disconnected=False elapsed=110.3s
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #230 disconnected=False elapsed=115.3s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.7GB peak=5.8GB cache=0.0GB step=5888 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #240 disconnected=False elapsed=120.4s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.7GB peak=5.8GB cache=0.0GB step=6144 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #250 disconnected=False elapsed=125.4s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.8GB peak=5.8GB cache=0.0GB step=6400 running=1 waiting=0
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #260 disconnected=False elapsed=130.4s
INFO:vllm_mlx.service.helpers:[disconnect_guard] poll #270 disconnected=False elapsed=135.4s
INFO:vllm_mlx.scheduler:[Metal memory] active=5.8GB peak=5.8GB cache=0.0GB step=6656 running=1 waiting=0

我的配置是m1 max 64G,跑的是这条命令rapid-mlx serve qwen3.5-9b

感兴趣的话,可以查看一下下面的步骤。


🚀 核心运行步骤

1. 选择安装方式

项目提供了多种安装方式,你可以根据自己的情况任选其一。

  • ✅ Homebrew 安装(最推荐)

    对于大多数macOS用户,这是最简单且无痛的方式,因为它会自动处理Python版本等依赖问题。

    bash 复制代码
    brew install raullenchai/rapid-mlx/rapid-mlx
  • 🐍 pip 安装

    适合习惯使用Python包管理器的用户。需要确保你的Python版本是 3.10 或以上(macOS预装的通常是3.9)。

    bash 复制代码
    pip install rapid-mlx
  • ⚡️ 一键脚本安装

    适合想快速尝试的用户,该脚本会自动安装所需依赖。

    bash 复制代码
    curl -fsSL https://raullenchai.github.io/Rapid-MLX/install.sh | bash

💡 注意 :如果你需要视觉或多模态功能(如Gemma 4, Qwen-VL等模型),需要在安装基础包后额外安装 vision 模块:

bash 复制代码
pip install 'rapid-mlx[vision]'

文本版安装包大小约460MB,视觉版会增加约322MB。

2. 启动并体验模型

安装成功后,只需一行命令就能启动一个模型服务。

  1. 启动服务

    在终端中运行 serve 命令,它会自动下载模型并启动一个兼容OpenAI的API服务器。

    bash 复制代码
    rapid-mlx serve qwen3.5-4b

    首次运行会自动下载模型(约2.5GB),请耐心等待,直到终端显示服务已就绪:

    复制代码
    Ready: http://localhost:8000/v1
  2. 测试聊天功能

    服务启动后,你可以用 curl 命令来测试聊天接口:

    bash 复制代码
    curl http://localhost:8000/v1/chat/completions \
      -H "Content-Type: application/json" \
      -d '{
        "model": "default",
        "messages": [{"role": "user", "content": "Say hello"}]
      }'

🔧 进阶配置与功能

Rapid-MLX 提供了丰富的命令行参数和配置,让你能更好地控制服务。

  • 查看所有可用模型:运行以下命令可以列出所有官方支持的模型别名,方便你选择不同大小和能力的模型。

    bash 复制代码
    rapid-mlx models
  • 根据设备内存选模型

    项目提供了一个与硬件匹配的模型推荐表,你可以根据自己Mac的内存大小来选择最适合的模型,以获得最佳的性能和效果平衡。

    设备内存 推荐模型 生成速度 (tok/s)
    16 GB (MacBook Air) Qwen3.5-4B 160 tok/s
    32+ GB (Mac Mini/Studio) Nemotron-Nano 30B 141 tok/s
    64 GB (Mac Mini/Studio) Qwen3.5-35B 95 tok/s
    96+ GB (Mac Studio/Pro) Qwen3.5-122B 83 tok/s
    128+ GB (Mac Studio Ultra) DeepSeek V4 Flash 158B-A13B 31-56 tok/s
  • 常用命令示例

    bash 复制代码
    # 启动一个 9B 参数的模型,它比4B模型更聪明
    rapid-mlx serve qwen3.5-9b --port 8000
    
    # 在32GB内存的Mac上,启动更快的模型,并优化首次响应速度
    rapid-mlx serve qwen3.5-35b --prefill-step-size 8192 --port 8000
    
    # 启动视觉模型 (需要先安装 vision 模块)
    rapid-mlx serve qwen3-vl-4b --mllm --port 8000
    
    # 高级用法:启用KV缓存量化以减少内存占用
    rapid-mlx serve qwen3.5-4b --kv-cache-quantization --port 8000

💻 在代码中集成

Rapid-MLX 作为 OpenAI API 的替代品,可以无缝融入任何兼容 OpenAI 的代码库。

python 复制代码
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")

# 获取用户输入的参数
user_input = input("请输入你想问 AI 的问题:")

response = client.chat.completions.create(
    model="default",
    messages=[{"role": "user", "content": user_input}],
)

print("AI 的回答:")
print(response.choices[0].message.content)

如果还没有安装openai,则执行:

shell 复制代码
pip install openai -i https://pypi.tuna.tsinghua.edu.cn/simple

执行:

python 复制代码
python xxx.py

🔗 与第三方应用集成

Rapid-MLX 真正的强大之处在于它能与众多 AI 工具和应用无缝集成,只需简单地修改API地址。

应用 配置方法
Cursor 在设置 SettingsModels 中添加模型。OpenAI API Base: http://localhost:8000/v1, API Key: not-needed
Claude Code 在终端设置环境变量:export OPENAI_BASE_URL=http://localhost:8000/v1,然后正常运行 claude 命令即可。
Aider 启动时添加参数:aider --openai-api-base http://localhost:8000/v1 --openai-api-key not-needed
Open WebUI / LibreChat 几乎所有支持自定义 OpenAI API 地址的应用,都可以通过设置 API Base URLhttp://localhost:8000/v1 来接入。

你还可以在GitHub仓库的 "Works With" 章节找到更多工具(如 Continue, LangChain, PydanticAI 等)的详细配置说明。

❓ 常见问题与排错 (Troubleshooting)

  • 安装时报 "No matching distribution" 错误

    这通常意味着你的Python版本过低。Rapid-MLX要求Python 3.10+。你可以通过 brew install python@3.12 安装新版Python,然后用 python3.12 -m pip install rapid-mlx 来安装。

  • 服务异常排查

    如果运行时遇到问题,可以运行内置的诊断工具。它会检查Metal GPU可用性、依赖项和模型加载等环节。

    bash 复制代码
    rapid-mlx doctor

比如下面:

复制代码
(base) ☁  ~  rapid-mlx doctor
Rapid-MLX Doctor
============================================================
  [metal] OK (0.1s)
  [imports] OK (1.4s)
  [cli] OK (0.2s)
  [model_load] FAIL (3.2s)
      b/python3.12/site-packages/huggingface_hub/_snapshot_download.py", line 328, in snapshot_download
          raise LocalEntryNotFoundError(
      huggingface_hub.errors.LocalEntryNotFoundError: Got: ConnectError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1010)
      An error happened while trying to locate the files on the Hub and we cannot find the appropriate snapshot folder for the specified revision on the local disk. Please check your internet connection and try again.

────────────────────────────────────────────────────────────
Result: FAIL  (3 pass, 0 regression, 1 fail, 0 skip)
Report: /opt/homebrew/Cellar/rapid-mlx/0.6.30/libexec/lib/python3.12/site-packages/harness/runs/2026-05-10-213302-smoke/report.md

原因是我没有开代理。

  • 安装视觉功能后遇到问题
    根据你的安装方式,pip 路径可能不同。如果你通过Homebrew安装,需使用其内部的pip来确保模块安装到正确的位置:

    bash 复制代码
    $(brew --prefix)/opt/rapid-mlx/libexec/bin/pip install 'rapid-mlx[vision]'

💡 补充说明

  • 硬件要求:该项目专为搭载Apple Silicon(M1/M2/M3/M4系列芯片)的Mac设计,依赖苹果的MLX框架实现高性能。
  • 项目状态:这是一个非常活跃的开源项目(Apache 2.0协议),拥有超过2100个测试用例,社区活跃,更新频繁。
相关推荐
AIsoft_86886 小时前
会议录音转文字与AI纪要工具推荐:免费额度与核心功能对比指南
人工智能
sphw6 小时前
nixnb: Jupyter Notebook 优雅分享
ide·人工智能·jupyter
mingo_敏6 小时前
DeepAgents : 权限(Permissions)
人工智能·深度学习·langchain
合调于形6 小时前
Bianfchheng (Liuu) 《边城(六)》字母标调拼音拼写实测案例
人工智能·自然语言处理·人机交互·语音识别·学习方法
凯丨6 小时前
AI 蠕虫来了:恶意文档如何通过 Copilot for Word 自我传播?
人工智能·c#·copilot
武子康6 小时前
GPT-5.6 Luna 降价 80%:Agent 真正该重算的是单次成功成本
人工智能·chatgpt·llm
Gu Gu Study7 小时前
ScoutLoop开放域深度研究引擎(agent的初步设计想法)
人工智能·python
HyperAI超神经7 小时前
15亿参数挑战机器人控制,MiniCPM-RobotManip正式开源;覆盖文本/图/视频/动作序列,英伟达发布全模态模型Cosmos3-Edge
人工智能·深度学习·机器人·多模态·图像生成·具身智能·智能体
搞科研的小刘选手7 小时前
【国际生态学协会主办】2026年生态环境与人工智能国际学术会议(ICAIEE 2026)
人工智能·生态环境·学术会议·会议推荐
笨鸟先飞,勤能补拙7 小时前
AI 赋能网络安全领域深度剖析
网络·人工智能·windows·安全·web安全·网络安全·github