MLX Engine 使用教程
1. 项目介绍
MLX Engine 是由 LM Studio 开发的一个开源项目,它基于 Apple MLX 推断引擎,为用户提供了一种高效的方式来处理大型语言模型(LLM)的文本生成和视觉模型的推理任务。MLX Engine 集成了多种功能,如结构化输出(Outlines)、视觉模型推理(Vision model inferencing)等,旨在简化机器学习工作流程。
2. 项目快速启动
环境准备
- macOS 14.0 (Sonoma) 或更高版本
- Python 3.11
使用 brew install python@3.11
安装 Python 3.11 不会影响您的默认 Python 设置。
克隆仓库
git clone https://github.com/lmstudio-ai/mlx-engine.git
cd mlx-engine
创建虚拟环境(可选)
python3.11 -m venv .venv
source .venv/bin/activate
安装依赖
pip install -U -r requirements.txt
文本模型演示
下载模型并运行演示脚本:
lms get mlx-community/Meta-Llama-3.1-8B-Instruct-4bit
python demo.py --model mlx-community/Meta-Llama-3.1-8B-Instruct-4bit
如果要使用自定义提示符,可以添加 --prompt
参数:
python demo.py --model mlx-community/Meta-Llama-3.1-8B-Instruct-4bit --prompt "你的问题或提示符"
视觉模型演示
运行视觉模型的演示脚本:
lms get mlx-community/pixtral-12b-4bit
python demo.py --model mlx-community/pixtral-12b-4bit --prompt "Compare these images" --images demo-data/chameleon.webp demo-data/toucan.jpeg
3. 应用案例和最佳实践
- 文本生成: 使用 MLX Engine 中的文本生成模型,可以创建自动回复机器人、生成文章摘要、撰写代码等。
- 图像识别: 利用视觉模型进行图像分类、目标检测等任务。
4. 典型生态项目
- Outlines: 提供结构化输出,便于处理和解析大型语言模型的结果。
- Vision Model Inferencing: 为视觉模型提供高效的推理能力。
- Pre-commit Hooks: 用于维护代码质量,确保代码提交前符合一定的标准。
以上是 MLX Engine 的基本使用教程,希望对您有所帮助。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考