能力标签
MLX-VLM
🛠
AI工具

MLX-VLM

基于 Python · 开源免费,本地部署,数据完全自主可控
英文名:mlx-vlm
⭐ 4.8k Stars 🍴 550 Forks 💻 Python 📄 MIT 🏷 AI 8.5分
8.5AI 综合评分
AI视觉语言模型Python
✦ AI Skill Hub 推荐

经 AI Skill Hub 精选评估,MLX-VLM 获评「强烈推荐」。已获得 4.8k 颗 GitHub Star,这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 8.5 分,适合有一定技术背景的用户使用。

📚 深度解析

MLX-VLM 是一款基于 Python 的开源工具,在 GitHub 上收获 5k+ Star,是AI、视觉语言模型、Python领域中的优质开源项目。开源工具的最大优势在于代码完全透明,你可以审计每一行代码的安全性,也可以根据自身需求进行二次开发和定制。

**为什么要使用开源工具而非商业 SaaS?**
对于个人开发者和有隐私需求的用户,本地部署的开源工具意味着数据不离本机,不受第三方服务商的数据政策约束。同时,开源工具通常没有使用次数限制和月度费用,一次安装即可长期使用,对于高频使用场景的总拥有成本(TCO)远低于订阅制商业工具。

**安装与环境准备**
MLX-VLM 依赖 Python 运行环境。建议通过 pyenv(Python)或 nvm(Node.js)管理 Python 版本,避免全局环境污染。对于新手用户,推荐先创建虚拟环境(python -m venv venv && source venv/bin/activate),再安装依赖,这样即使出现问题也可以随时删除虚拟环境重新开始,不影响系统稳定性。

**社区与维护**
GitHub Issue 和 Discussion 是获取帮助的最快渠道。在提问前建议先检查 Closed Issues(已关闭的问题),大多数常见问题都已有解答。遇到 Bug 时,提供 pip list 的输出、完整错误堆栈和最小可复现示例,能显著提高开发者响应速度。AI Skill Hub 将持续追踪 MLX-VLM 的版本更新,及时通知重要功能变化。

📋 工具概览

MLX-VLM 是一款基于 Python 开发的开源工具,专注于 AI、视觉语言模型、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

GitHub Stars
⭐ 4.8k
开发语言
Python
支持平台
Windows / macOS / Linux
维护状态
持续维护,定期更新
开源协议
MIT
AI 综合评分
8.5 分
工具类型
AI工具
Forks
550

📖 中文文档

以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

MLX-VLM 是一款基于 Python 开发的开源工具,专注于 AI、视觉语言模型、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

📌 核心特色
  • 开源免费,支持本地部署,数据完全自主可控
  • 活跃的 GitHub 开源社区,持续迭代更新
  • 提供详细文档和使用示例,新手友好
  • 支持自定义配置,灵活适配不同使用环境
  • 可作为基础组件集成进现有技术栈或进行二次开发
🎯 主要使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 方式一:pip 安装(推荐)
pip install mlx-vlm

# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install mlx-vlm

# 方式三:从源码安装(获取最新功能)
git clone https://github.com/Blaizzy/mlx-vlm
cd mlx-vlm
pip install -e .

# 验证安装
python -c "import mlx_vlm; print('安装成功')"
📋 安装步骤说明
  1. 访问 GitHub 仓库页面
  2. 按照 README 文档完成依赖安装
  3. 根据系统环境完成初始化配置
  4. 参考官方示例或文档开始使用
  5. 遇到问题可在 GitHub Issues 中查找解答
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 命令行使用
mlx-vlm --help

# 基本用法
mlx-vlm input_file -o output_file

# Python 代码中调用
import mlx_vlm

# 示例
result = mlx_vlm.process("input")
print(result)
以下配置示例基于典型使用场景生成,具体参数请参照官方文档调整。
配置示例
# mlx-vlm 配置文件示例(config.yml)
app:
  name: "mlx-vlm"
  debug: false
  log_level: "INFO"

# 运行时指定配置文件
mlx-vlm --config config.yml

# 或通过环境变量配置
export MLX_VLM_API_KEY="your-key"
export MLX_VLM_OUTPUT_DIR="./output"
📑 README 深度解析 真实文档 完整度 82/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

简介

Upload Python Package

Vision Feature Caching

In multi-turn conversations about an image, the vision encoder runs on every turn even though the image hasn't changed. VisionFeatureCache stores projected vision features in an LRU cache keyed by image path, so the expensive vision encoder is only called once per unique image.

With trust remote code enabled (required for some models)

mlx_vlm.server --trust-remote-code

Require bearer authentication for API endpoints

mlx_vlm.server --api-key <secret-token>

Installation

The easiest way to get started is to install the mlx-vlm package using pip:

pip install -U mlx-vlm

The Gradio chat UI needs an extra dependency that is not part of the base install:

pip install -U 'mlx-vlm[ui]'

Quote the package name so that shells which expand square brackets, such as zsh, do not treat [ui] as a glob pattern.

Usage

Usage Examples

Python Script

from mlx_vlm import load, generate
from mlx_vlm.prompt_utils import apply_chat_template
from mlx_vlm.utils import load_config

model_path = "mlx-community/Qwen2-VL-2B-Instruct-4bit"
model, processor = load(model_path)
config = model.config

images = ["path/to/image1.jpg", "path/to/image2.jpg"]
prompt = "Compare these two images."

formatted_prompt = apply_chat_template(
    processor, config, prompt, num_images=len(images)
)

output = generate(model, processor, formatted_prompt, images, verbose=False)
print(output)

Command Line

mlx_vlm.generate --model mlx-community/Qwen2-VL-2B-Instruct-4bit --max-tokens 100 --prompt "Compare these images" --image path/to/image1.jpg path/to/image2.jpg

Usage Examples

#### Command Line

mlx_vlm.generate --model mlx-community/Qwen2-VL-2B-Instruct-4bit --max-tokens 100 --prompt "Describe this video" --video path/to/video.mp4 --fps 1.0

These examples demonstrate how to use multiple images with MLX-VLM for more complex visual reasoning tasks.

Quick Start

```sh

Configure thinking defaults at startup

mlx_vlm.server --model Qwen/Qwen3.5-4B \ --enable-thinking \ --thinking-budget 512 \ --thinking-start-token "<think>" \ --thinking-end-token "</think>"

Optional diagnostics: inspect the automatically inferred cache groups.

print(apc.coordinator(model).plan.describe())

document = Path("long_document.txt").read_text()

try: # First request computes the full prefix and stores reusable K/V blocks. prompt1 = apply_chat_template( processor, model.config, prompt=f"{document}\n\nSummarize the key decisions.", num_images=0, ) for _ in stream_generate( model, processor, prompt1, max_tokens=128, temperature=0.0, apc_manager=apc ): pass

# Second request shares the same document prefix and only prefills the suffix. prompt2 = apply_chat_template( processor, model.config, prompt=f"{document}\n\nList the open engineering risks.", num_images=0, ) for chunk in stream_generate( model, processor, prompt2, max_tokens=128, temperature=0.0, apc_manager=apc ): print(chunk.text, end="", flush=True)

print(apc.stats_snapshot()) finally: apc.close()


To compare cold, warm-memory, warm-disk, and disk-eviction behavior with a
model, use the same direct API path:
python import os import tempfile import time from pathlib import Path

from mlx_vlm import load, stream_generate from mlx_vlm.apc import APCManager, DiskBlockStore from mlx_vlm.prompt_utils import apply_chat_template

model_id = "Qwen/Qwen3-VL-4B-Instruct" contexts = [8000, 20000, 50000, 100000] disk_cap_gb = 0 # 0 means uncapped shard_max_blocks = 256 context_sweep_max_tokens = 1 # one token is enough to measure prefill reuse

test_prompt_tokens = 8000 fill_prompts = 80 eviction_disk_cap_gb = 3.0

os.environ["APC_DISK_SHARD_MAX_BLOCKS"] = str(shard_max_blocks)

model, processor = load(model_id) tokenizer = processor.tokenizer if hasattr(processor, "tokenizer") else processor

def disk_cap_bytes(gb: float): return None if gb <= 0 else int(gb * (1 << 30))

def make_context(target_tokens: int, seed: int = 0) -> str: line = ( f"Document {seed}: APC benchmark content with deterministic facts, " "dates, identifiers, and repeated technical notes.\n" ) line_tokens = max(1, len(tokenizer.encode(line, add_special_tokens=False))) text = line * max(1, target_tokens // line_tokens) while len(tokenizer.encode(text, add_special_tokens=False)) < target_tokens: text += line return text

def make_prompt(context: str, question: str) -> str: return apply_chat_template( processor, model.config, prompt=f"{context}\n\n{question}", num_images=0, )

def run_once(apc: APCManager, context: str, question: str, max_tokens: int = 32): prompt = make_prompt(context, question) apc.reset_stats()

last = None output = [] start = time.perf_counter() for chunk in stream_generate( model, processor, prompt, max_tokens=max_tokens, temperature=0.0, apc_manager=apc, ): output.append(chunk.text) last = chunk

if last is None: raise RuntimeError("generation returned no chunks")

return { "wall_s": time.perf_counter() - start, "prompt_tokens": last.prompt_tokens, "prompt_tps": last.prompt_tps, "generation_tps": last.generation_tps, "apc": apc.stats_snapshot(), "text": "".join(output).strip(), }

def print_result(label: str, result: dict) -> None: stats = result["apc"] print( f"{label:<12} " f"prompt_tokens={result['prompt_tokens']:>7} " f"prompt_tps={result['prompt_tps']:>8.1f} " f"gen_tps={result['generation_tps']:>7.1f} " f"matched={stats.get('matched_tokens', 0):>7} " f"disk_hits={stats.get('disk_hits', 0):>5} " f"disk_evictions={stats.get('disk_evictions', 0):>5}" )

def open_apc(cache_root: Path, namespace: str, disk_gb: float) -> APCManager: disk = DiskBlockStore( cache_root, namespace=namespace, max_bytes=disk_cap_bytes(disk_gb), ) return APCManager(num_blocks=4096, block_size=16, disk=disk)

def run_context_sweep() -> None: print("cold / warm-memory / warm-disk") with tempfile.TemporaryDirectory() as tmp: cache_root = Path(tmp) for target_tokens in contexts: context = make_context(target_tokens) namespace = f"{model_id}-context-{target_tokens}" apc = open_apc(cache_root, namespace, disk_cap_gb) try: print(f"\ncontext ~= {target_tokens} text tokens") print_result( "cold", run_once( apc, context, "Summarize the key decisions.", max_tokens=context_sweep_max_tokens, ), ) print_result( "warm-memory", run_once( apc, context, "List the open engineering risks.", max_tokens=context_sweep_max_tokens, ), ) finally: # Closing waits for queued disk writes before reopening the disk tier. apc.close()

apc = open_apc(cache_root, namespace, disk_cap_gb) try: print_result( "warm-disk", run_once( apc, context, "Extract the implementation timeline.", max_tokens=context_sweep_max_tokens, ), ) finally: apc.close()

def run_disk_eviction_workload() -> None: print("\ndisk eviction workload") with tempfile.TemporaryDirectory() as tmp: cache_root = Path(tmp) namespace = f"{model_id}-eviction" test_context = make_context(test_prompt_tokens, seed=0)

apc = open_apc(cache_root, namespace, eviction_disk_cap_gb) try: print_result( "seed", run_once(apc, test_context, "Summarize the retained test prefix."), ) finally: apc.close()

apc = open_apc(cache_root, namespace, eviction_disk_cap_gb) try: for i in range(fill_prompts): fill_context = make_context(test_prompt_tokens, seed=i + 1) run_once( apc, fill_context, f"Summarize filler document {i + 1}.", max_tokens=1, ) if (i + 1) % 10 == 0: stats = apc.stats_snapshot() print( f"filled={i + 1:>3} " f"disk_gb={stats.get('disk_bytes', 0) / (1 << 30):.2f} " f"disk_evictions={stats.get('disk_evictions', 0)}" ) finally: apc.close()

apc = open_apc(cache_root, namespace, eviction_disk_cap_gb) try: print_result( "post-fill", run_once( apc, test_context, "Check whether the retained test prefix still restores.", ), ) finally: apc.close()

run_context_sweep() run_disk_eviction_workload()


#### Server

Enable in-memory APC for the server with environment variables:
sh APC_ENABLED=1 \ APC_NUM_BLOCKS=4096 \ mlx_vlm.server --model Qwen/Qwen3-VL-4B-Instruct --port 8080

APC works with KV-cache quantization (`--kv-bits`):
sh APC_ENABLED=1 \ APC_NUM_BLOCKS=4096 \ mlx_vlm.server --model Qwen/Qwen3-VL-4B-Instruct --kv-bits 8 --port 8080

Enable the persistent disk tier:
sh APC_ENABLED=1 \ APC_NUM_BLOCKS=4096 \ APC_DISK_PATH=~/.cache/mlx-vlm/caching \ APC_DISK_MAX_GB=3 \ APC_DISK_SHARD_MAX_BLOCKS=256 \ mlx_vlm.server --model Qwen/Qwen3-VL-4B-Instruct --port 8080

Repeated requests with the same long prefix will hit APC automatically:
sh curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "X-APC-Tenant: demo" \ -d '{ "model": "Qwen/Qwen3-VL-4B-Instruct", "messages": [{ "role": "user", "content": "Paste a long shared document here.\n\nNow answer question A." }], "max_tokens": 128 }'

Use the same `X-APC-Tenant` value for requests that may share cached prefixes. Use different tenant values to isolate cache entries between users or workspaces.

Inspect and reset APC state:
sh curl http://localhost:8080/v1/cache/stats curl -X POST http://localhost:8080/v1/cache/reset

Common APC environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `APC_ENABLED` | `0` | Set to `1` to enable APC |
| `APC_NUM_BLOCKS` | `2048` | Number of in-memory APC blocks |
| `APC_BLOCK_SIZE` | `16` | Tokens per APC block |
| `APC_CHECKPOINT_ENTRIES` | `2` | In-memory checkpoint entries for hybrid/stateful cache layouts |
| `APC_CHECKPOINT_GUARD_TOKENS` | `1` | Tokens retained after a reusable hybrid checkpoint boundary; the default preserves the normal final-token prefill boundary |
| `APC_DISK_PATH` | unset | Directory for persistent disk shards |
| `APC_DISK_MAX_GB` | `0` | Disk cap in GB; `0` means uncapped |
| `APC_DISK_SHARD_MAX_BLOCKS` | `256` | Max blocks per disk segment shard |
| `APC_MAX_POOL_TENSORS` | `450000` | Stops adding memory blocks before the Metal resource limit; disk writes continue |
| `APC_LAYER_MAJOR_MEMORY_MIN_TOKENS` | `50000` | Store long warm-memory prefixes as compact layer-major snapshots instead of per-block tensors |
| `APC_HASH` | `fast` | Set to `sha256` for a stable cryptographic hash |
| `APC_TRACE` | unset | Set to `1` for greppable store/reject/self-check log lines |

Custom cache layouts can opt in without APC model-name checks by implementing `prefix_cache_snapshot()` and `prefix_cache_restore(snapshot)`. In-tree dense, sliding-window, recurrent, composite, VLM, and Omni cache layouts are detected automatically. APC works with `--kv-bits` (including TurboQuant): the live KV cache stays quantized; pageable APC K/V blocks are stored as dequantized float K/V, so block-pool size does not shrink with quant.
When APC is enabled on the server, a non-fatal layout self-check runs at model load.

#### KV Cache Quantization

Reduce KV cache memory during continuous batching with `--kv-bits`. Both uniform quantization and TurboQuant are supported. Compatible with Automatic Prefix Caching (`APC_ENABLED=1`).
sh

Command Line Interface (CLI)

Generate output from a model using the CLI:

```sh

Server (FastAPI)

Start the server: ```sh mlx_vlm.server --port 8080

Python API

Pass quantize_activations=True to the load function:

```python from mlx_vlm import load, generate

Supported Models

The following models support video chat:

  1. Qwen2-VL
  2. Qwen2.5-VL
  3. Idefics3
  4. LLaVA
  5. MiniMax M3
  6. LLaVA-OneVision

With more coming soon.

🇨🇳 中文文档镜像 AI 翻译 2026-06-24
英文原文章节由系统翻译为中文摘要,便于快速理解。完整原文见上方 "📑 README 深度解析"。
📌 简介

mlx-vlm 是一个专为 Apple Silicon 优化的视觉语言模型库,旨在通过 MLX 框架实现高效的视觉推理任务。该项目支持多种先进的视觉模型,能够处理图像与视频输入,为开发者提供高性能、低延迟的视觉理解能力。

⚡ 功能介绍

项目引入了 Vision Feature Caching 机制,专门优化了多轮对话场景。在处理涉及同一张图片的连续对话时,系统会通过 LRU cache 缓存已投影的视觉特征,避免在每一轮对话中重复调用高能耗的 vision encoder,从而显著提升推理效率并降低计算开销。

📋 环境依赖

在使用某些特定模型时,需要确保在启动时启用 `--trust-remote-code` 参数,以允许执行远程代码。这对于加载部分非标准架构的模型至关重要,请根据实际需求在命令行中进行配置。

🛠 安装步骤(Docker/pip/源码)

安装 mlx-vlm 非常简单,推荐使用 pip 进行快速部署。您可以通过运行命令 `pip install -U mlx-vlm` 来安装或更新至最新版本,确保您的开发环境已配置好 Python 包管理工具。

🚀 使用教程

项目提供了灵活的使用方式,支持 Python Script 和 Command Line 两种模式。开发者可以通过 Python 调用 `load` 和 `generate` 函数进行复杂的视觉推理任务(如对比多张图片);同时,也可以直接使用命令行工具 `mlx_vlm.video_generate` 来实现对视频内容的描述与分析。

🔌 API 说明

mlx-vlm 提供了完善的接口支持。通过 Command Line Interface (CLI),用户可以直接在终端生成模型输出;此外,项目还内置了基于 FastAPI 的 Server 模式,支持通过指定端口启动服务;对于开发者,还提供了 Python API,可以通过在 `load` 函数中传递 `quantize_activations=True` 等参数来优化性能。

🔄 工作流/模块

目前 mlx-vlm 已支持多种主流视觉模型的视频对话功能,包括 Qwen2-VL、Qwen2.5-VL、Idefics3 以及 LLaVA 等。随着项目的持续迭代,未来将支持更多类型的视觉模型,为开发者提供更丰富的模型生态选择。

🎯 aiskill88 AI 点评 A 级 2026-05-30

高质量的开源AI工具,实现视觉语言模型的推理和微调

📚 实用指南(长尾问题)
适合谁
  • 构建企业知识库 / RAG 检索应用的团队
  • 需要从图片、PDF 提取文字的文档自动化场景
最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • Python 依赖冲突:建议用 venv / uv 隔离环境
部署方案
  • CLI:直接 npm install -g / pip install,命令行调用
  • 云端托管:可放在 Vercel / Railway / Fly.io 等 PaaS 平台
相关搜索
mlx-vlm 中文教程mlx-vlm 安装报错怎么办mlx-vlm 与同类工具对比mlx-vlm 最佳实践mlx-vlm 适合谁用

⚡ 核心功能

👥 适合谁
  • 构建企业知识库 / RAG 检索应用的团队
  • 需要从图片、PDF 提取文字的文档自动化场景
⭐ 最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
⚠️ 常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • Python 依赖冲突:建议用 venv / uv 隔离环境

👥 适合人群

AI 技术爱好者研究人员和学生开发者和工程师技术创业者

🎯 使用场景

  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发

⚖️ 优点与不足

✅ 优点
  • +MIT 协议,可免费商用
  • +完全开源免费,无授权费用
  • +本地部署,数据完全自主可控
  • +开发者社区支持,遇问题可查可问
⚠️ 不足
  • 安装和初始配置可能需要一定技术基础
  • 功能完整性通常不如成熟商业产品
  • 技术支持主要依赖开源社区,响应速度不稳定
⚠️ 使用须知

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。

🔗 相关工具推荐

📰 相关 AI 新闻
🍿 AI 圈相关吃瓜
🗺️ 相关解决方案
🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合

❓ 常见问题 FAQ

mlx-vlm 是一款Python开发的AI辅助工具。开源AI工具:MLX-VLM is a package for inference and fine-tuning of Vision Language Models (VL。⭐4.8k · Python 主要应用场景包括:视觉语言模型的推理和微调。
💡 AI Skill Hub 点评

AI Skill Hub 点评:MLX-VLM 的核心功能完整,质量优秀。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。

📚 深入学习 MLX-VLM
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 mlx-vlm
原始描述 开源AI工具:MLX-VLM is a package for inference and fine-tuning of Vision Language Models (VL。⭐4.8k · Python
Topics AI视觉语言模型Python
GitHub https://github.com/Blaizzy/mlx-vlm
License MIT
语言 Python
🔗 原始来源
🐙 GitHub 仓库  https://github.com/Blaizzy/mlx-vlm

收录时间:2026-05-30 · 更新时间:2026-05-30 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。

📺 订阅 AI Skill Hub Daily Telegram 频道
每天 8 条精选 AI Skill、MCP、Agent 与自动化工具推送
加入频道 →