openMind is a magicain who takes you to experience the mystery and creativity of AI.
Project description
📝 简介
openMind Library是一个大模型微调套件,通过命令行接口或SDK原生支持在昇腾NPU上进行微调、推理、评估和部署。通过简化使用流程,充分利用NPU的独特优势,为大模型应用提供高效、可扩展的解决方案。
为什么使用 openMind Library?
基于Transformers框架,openMind Library实现了高效的微调流程。它集成了PyTorch生态中常用的工具库功能,提供数据预处理、权重加载、低参微调、量化适配以及训练跟踪等全流程的一键式解决方案。此外,库内融合了针对昇腾NPU的优化算子,可大幅提升模型训练效率。
openMind Library提供了统一的Pipeline SDK,提供更快速、更高效的推理体验。
模型部署方面,openMind Library基于LMDeploy和MindIE,提供多后端部署支持,极大地简化了部署流程,使得模型部署更加便捷。
openMind Library目前支持的特性如下:
- 模型类型:支持Qwen2,Qwen2.5系列模型,更多模型适配中
- 微调训练:SFT训练
- 高效微调:BF16微调,LoRA微调,4bit QLoRA微调
- 分布式训练:DDP,DeepSpeed
- 微调加速:npu_fusion_attention融合算子,npu_rms_norm融合算子
- 训练监控:SwanLab
- 推理:Transformers/Diffusers多backend,text-generation/text-to-image多任务
- 部署:LMDeploy,MindIE
- 评估:lm_eval
🌟 项目特色
openMind Library支持QLoRA,融合算子等训练加速手段,帮助您减少显存开销,提升微调训练速度。
|
Qwen2.5-7B Full/LoRA/QLoRA显存开销
npu=8, per_device_train_batch_size=1, max_length=1024 |
Qwen2.5-7B Full/LoRA性能对比
npu=8, max_length=1024, train_samples_per_second |
🚀 更新日志
- 2024/12: openMind Library 1.0.0版本发布,支持cli命令启动微调,LoRA权重合并,SwanLab训练监控,LMDeploy/MindIE部署。
🛠️ 安装
openMind Library支持PyTorch和MindSpore双框架,您可以根据需求选择安装对应框架和依赖。请注意不要同时安装双框架。
使用pip进行安装:
# 不安装框架,仅安装openMind Library
pip install openmind
# aarch64环境下安装PyTorch框架及其框架
pip install openmind[pt]
# x86环境下安装PyTorch框架及其框架
pip install openmind[pt] --extra-index-url https://download.pytorch.org/whl/cpu
# MindSpore框架及其依赖
pip install openmind[ms]
从源代码安装:
git clone https://gitee.com/modelers/openmind.git
cd openmind
# 不安装框架,仅安装openMind Library
pip install -e .
# aarch64环境下安装PyTorch框架及其框架
pip install -e .[pt]
# x86环境下安装PyTorch框架及其框架
pip install -e .[pt] --extra-index-url https://download.pytorch.org/whl/cpu
# MindSpore框架及其依赖
pip install -e .[ms]
关于openMind Library的安装步骤,推荐用户参考《安装》文档,以确保顺利并正确地完成安装过程。
🧰 快速上手
openMind Library支持通过cli或SDK方式启动微调,推理,评估和部署。
微调
openMind Library支持通过openmind-cli train命令行方式解析yaml文件运行微调全流程。openMind Library为您提供了examples示例,您可以通过以下命令快速启动微调示例。
全参微调
openmind-cli train examples/features/train_sft_full.yaml
LoRA微调
openmind-cli train examples/features/train_sft_lora.yaml
QLoRA微调
QLoRA微调启动前,需要手动安装bitandbytes仓,请参考微调QLoRA章节中的安装指引完成前置配置。
openmind-cli train examples/features/train_sft_qlora.yaml
NPU亲和算子优化
openMind Library目前集成了npu_fusion_attention和npu_rms_norm融合算子,可以显著提升模型微调训练性能。您可以参考融合算子使能文档使用该功能提升训练速度。
推理
openMind Library支持基于cli命令快速启动文本生成推理。
openmind-cli run text-generation --framework pt --input "What is AI?"
openmind-cli run也支持文生图推理。
openmind-cli run text-to-image --framework pt --backend diffusers --input "masterpiece, best quality, Cute dragon creature, pokemon style, night, moonlight, dim lighting"
如果您需要集成openMind Library的推理功能,或者有其他使用需求,您也可以使用对应的SDK接口进行调用。
from openmind import pipeline
pipe = pipeline(
task="text-generation",
model="Baichuan/Baichuan2_7b_chat_pt",
framework="pt",
backend="transformers",
trust_remote_code=True,
device="npu:0",
)
output = pipe("Give three tips for staying healthy.")
print(output)
更多推理功能使用,您可以参考推理文档和openmind-cli run章节。
评估
openMind Library集成了lm_eval进行模型评估推理。您可以调用openmind-cli lmeval命令,从魔乐社区下载评估数据集完成评估。
openmind-cli lmeval --model Baichuan/Baichuan2_7b_chat_pt --device npu:0 --tasks arithmetic --batch_size 64 --trust_remote_code 1
更多使用方式和支持的评估数据集列表,请查看openmind-cli lmeval章节。
部署
openMind Library支持了LMDeploy和MindIE部署模型服务。您可以使用以下命令运行示例,完成服务部署。
-
基于LMDeploy部署Qwen2-7B模型
openmind-cli deploy AI-Research/Qwen2-7B --backend lmdeploy
-
调用API接口完成推理
curl http://127.0.0.1:1025/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{"model": "AI-Research/Qwen2-7B", "messages": "推荐一个海边度假的地方"}'
更多deploy接口使用和MindIE后端使用,请查看openmind-cli deploy文档。
📚 贡献
- 在上传PR之前,请确保所有测试都通过。首先在本地运行如下命令。
# The scripts below run on system default python version by default. If you want to use other python version, set the env
# PY_VERSION. For example, `PY_VERSION=3.8 ./ci/lint.sh`
# Lint check
./ci/lint.sh
# Unit test
./ci/unit_test.sh
# Functional test, Please generate the HUB_TOKEN from openmind by yourself and use it privatelly.
HUB_TOKEN=your_hub_token ./ci/functional_test.sh
-
当您推送或更新PR(Pull Request)后,系统将自动触发CI(持续集成)构建和测试流程。若所有CI构建和测试均顺利通过,
ci-success标记将自动添加到您的PR中。然而,若出现CI故障,您可以点击CI日志链接以详细查看失败原因,并在本地进行必要的修复。一旦您完成了修复并希望重新运行CI作业,只需在PR中留下评论/recheck即可。 -
详细贡献指南请参考: https://gitee.com/modelers/openmind/blob/dev/docs/zh/developer_tutorial/contribution.md
🔒 安全声明
为保障使用过程安全,推荐用户参考《安全声明》了解相关安全信息,进行必要的安全加固。
📖 许可证
MulanPSL v2 openMind Library使用木兰宽松许可证第2版(MulanPSL v2)。详见LICENSE文件。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openmind-1.0.0-py3-none-any.whl.
File metadata
- Download URL: openmind-1.0.0-py3-none-any.whl
- Upload date:
- Size: 234.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0208c202ce6aebe89976c3fbd41fea61191997a44db369052c98a6b0747f5418
|
|
| MD5 |
7df7764989a9f04ac8fc8f81df28bd61
|
|
| BLAKE2b-256 |
79a1a269531e6990420ce88b882381bceabaf39c06f5ffffb11aeb33d56f3024
|