convert-quantize
它能做什么
这项技能教智能体如何把 Hugging Face 的 AI 模型转换为 MLX 格式,并可选择将其压缩得更小。适合希望在苹果设备上运行模型的人。
适用场景
- ✓当用户想把 Hugging Face 模型转换为适用于 Mac 的 MLX 版本的时候。
- ✓当用户想要模型的 4 位或 8 位较小版本的时候。
- ✓当转换或量化命令失败,需要修复的时候。
技能链接
https://github.com/Blaizzy/mlx-vlm/blob/main/skills/skills/convert-quantize/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把这个 Hugging Face 模型转换为 MLX,并生成一个适合我 Mac 的 4 位版本。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先确认源模型和模型系列,然后使用所选的位宽、分组大小和模式运行转换命令。由于参数可能变化,它会先检查帮助输出。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Convert & Quantize
Use this workflow for mlx_vlm.convert — turning a Hugging Face checkpoint into MLX format, optionally quantizing it.
First Checks
- Confirm the source: a Hugging Face repo id or a local path (
--hf-path, alias--model). - Confirm the model family is supported in
mlx_vlm/models/(a folder named after theconfig.jsonmodel_type). If not, this is a porting task — switch toSkill("mlx-vlm-skills:add-new-model"). - Verify current flags before finalizing:
uv run mlx_vlm.convert --help. - Entry point is
mlx_vlm.convert.python -m mlx_vlm.convertis deprecated; useuv run mlx_vlm.convert ...orpython -m mlx_vlm convert ....
Command Patterns
Plain convert (no quantization), saves to ./mlx_model by default:
uv run mlx_vlm.convert --hf-path <repo-or-path> --mlx-path ./out-mlx
4-bit affine quantization (RTN, the default method):
uv run mlx_vlm.convert --hf-path <repo-or-path> --mlx-path ./out-4bit -q --q-bits 4 --q-group-size 64
Other quant modes (--q-mode sets its own bit/group defaults):
# mxfp4 (group 32, 4 bit), nvfp4 (group 16, 4 bit), mxfp8 (group 32, 8 bit)
uv run mlx_vlm.convert --hf-path <repo-or-path> --mlx-path ./out-mxfp4 -q --q-mode mxfp4
Mixed-bit recipe (per-layer bit allocation, llama.cpp-style):
# recipes: mixed_2_6 mixed_3_4 mixed_3_5 mixed_3_6 mixed_3_8 mixed_4_6 mixed_4_8
uv run mlx_vlm.convert --hf-path <repo-or-path> --mlx-path ./out-mixed -q --quant-predicate mixed_3_6
AWQ (activation-aware, needs a calibration pass):
uv run mlx_vlm.convert --hf-path <repo-or-path> --mlx-path ./out-awq -q --quant-method awq \
--calibration multimodal --calibration-data /path/to/media # or --calibration text (default)
dtype cast only / dequantize:
uv run mlx_vlm.convert --hf-path <repo-or-path> --mlx-path ./out-bf16 --dtype bfloat16
uv run mlx_vlm.convert --hf-path <quantized-repo> --mlx-path ./out-fp -d # dequantize
Upload the result to the Hub:
uv run mlx_vlm.convert --hf-path <repo> --mlx-path ./out -q --upload-repo <user>/<name>-mlx
Key Facts
- Multimodal modules are skipped from quantization by default (
skip_multimodal_module) — vision/audio towers stay full precision; only the language model is quantized. This is expected, not a bug. --q-modechoices:affine(default, group 64 / 4 bit),mxfp4(32/4),nvfp4(16/4),mxfp8(32/8).--q-bits/--q-group-sizeoverride the mode defaults.--quant-method:rtn(default, round-to-nearest) orawq(needs calibration;--calibration text|multimodal, optional--calibration-data).-q/--quantizeand-d/--dequantizeare mutually exclusive.--dtype(fromconfig.jsontorch_dtypeif unset) casts float weights; useful for shrinking fp32 → bf16 without quantizing.- The converted folder gets the weights, copied
*.py/*.json, the processor, a regeneratedconfig.json, and a model card — it is ready formlx_vlm.generateand the server.
Validation
- After converting, load and run a tiny generation to prove the checkpoint works — see
Skill("mlx-vlm-skills:cli-inference"). Run on Apple Silicon with enough RAM for the model; do not attempt a large model on an 8 GB machine. - For quality, compare a few greedy outputs between the source and the quantized model; large drops usually mean too-low bits or a wrong
--q-modefor the model. - For code changes touching conversion, run
uv run --with pytest python -m pytest mlx_vlm/tests/test_utils.py -qand any model-specific test. - If the outcome is a bug report, switch to
Skill("mlx-vlm-skills:reproducible-github-issues").
常见问题
所有模型都能转换吗?
不能。这项技能说明该模型系列必须已经受支持,否则就属于移植任务。
量化步骤做什么?
它会按你选择的位宽,使转换后的模型变得更小。
结果可以上传到 Hugging Face 吗?
可以。这项技能涵盖上传到 Hub 作为可选步骤。
详情
作者的原始描述
Use this skill when the user wants to convert a Hugging Face model to MLX or quantize/dequantize one with mlx_vlm.convert, including bits and group size, quant modes (affine, mxfp4, nvfp4, mxfp8), RTN vs AWQ, mixed-bit recipes, dtype casts, calibration (text or multimodal), local vs Hub paths, revisions, uploading to the Hub, and convert/quant errors.
repo: Blaizzy/mlx-vlm
热度
- GitHub 星标
- 5.7k
- 排名
- #14749
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
cli-inference
5.7k帮你的智能体从命令行运行或排查 MLX-VLM 模型推理,支持文本、图像和音频输入,并为每项任务找到正确的参数。
hf-cache-models
5.7k帮你的智能体通过模型发现接口,列出正在运行的 MLX-VLM 服务器可以看到的模型,包括缓存模型、自定义模型和已加载的模型。
reproducible-github-issues
5.7k帮你的智能体为 MLX-VLM 撰写清晰、可复现的 GitHub 问题报告,附上环境信息、准确命令和一个小示例,用于反馈缺陷或速度变慢的问题。
server-inference
5.7k帮你的智能体运行并调试 MLX-VLM API 服务器,涵盖健康检查、聊天和 responses 请求、流式输出以及常见的请求错误。