Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
Lin 6f6cd8cb99 | 5 months ago | |
---|---|---|
.gitee | 2 years ago | |
.jenkins/test/config | 7 months ago | |
configs | 5 months ago | |
docs | 5 months ago | |
mindformers | 5 months ago | |
research | 5 months ago | |
scripts | 5 months ago | |
tests | 5 months ago | |
.gitignore | 1 year ago | |
.readthedocs.yaml | 6 months ago | |
LICENSE | 2 years ago | |
OWNERS | 1 year ago | |
README.md | 5 months ago | |
build.sh | 7 months ago | |
requirements.txt | 6 months ago | |
run_chat_web.py | 7 months ago | |
run_infer_main.py | 5 months ago | |
run_mindformer.py | 5 months ago | |
setup.py | 7 months ago |
MindSpore Transformers套件的目标是构建一个大模型训练、微调、评估、推理、部署的全流程开发套件:
提供业内主流的Transformer类预训练模型和SOTA下游任务应用,涵盖丰富的并行特性。期望帮助用户轻松的实现大模型训练和创新研发。
MindSpore Transformers套件基于MindSpore内置的并行技术和组件化设计,具备如下特点:
如果您对MindSpore Transformers有任何建议,请通过issue与我们联系,我们将及时处理。
目前支持的模型列表如下:
模型 | 任务(task name) | 模型(model name) |
---|---|---|
LLama2 | text_generation | llama2_7b llama2_13b llama2_7b_lora llama2_13b_lora llama2_70b |
GLM2 | text_generation | glm2_6b glm2_6b_lora |
CodeGeex2 | text_generation | codegeex2_6b |
LLama | text_generation | llama_7b llama_13b llama_7b_lora |
GLM | text_generation | glm_6b glm_6b_lora |
Bloom | text_generation | bloom_560m bloom_7.1b |
GPT2 | text_generation | gpt2_small gpt2_13b |
PanGuAlpha | text_generation | pangualpha_2_6_b pangualpha_13b |
BLIP2 | contrastive_language_image_pretrain zero_shot_image_classification |
blip2_stage1_vit_g |
CLIP | contrastive_language_image_pretrain zero_shot_image_classification |
clip_vit_b_32 clip_vit_b_16 clip_vit_l_14 clip_vit_l_14@336 |
BERT | masked_language_modeling text_classification token_classification question_answering |
bert_base_uncased txtcls_bert_base_uncased txtcls_bert_base_uncased_mnli tokcls_bert_base_chinese tokcls_bert_base_chinese_cluener qa_bert_base_uncased qa_bert_base_chinese_uncased |
T5 | translation | t5_small |
sam | segment_anything | sam_vit_b sam_vit_l sam_vit_h |
MAE | masked_image_modeling | mae_vit_base_p16 |
VIT | image_classification | vit_base_p16 |
Swin | image_classification | swin_base_p4w7 |
目前在research中支持的模型列表如下:
模型 | 任务(task name) | 模型(model name) |
---|---|---|
skywork | text_generation | skywork_13b |
Baichuan2 | text_generation | baichuan2_7b baichuan2_13b baichuan2_7b_lora baichuan2_13b_lora |
Baichuan | text_generation | baichuan_7b baichuan_13b |
Qwen | text_generation | qwen_7b |
Wizardcoder | text_generation | wizardcoder_15b |
Internlm | text_generation | Internlm_7b |
ziya | text_generation | ziya_13b |
支持源码编译安装,用户可以执行下述的命令进行包的安装
git clone -b dev https://gitee.com/mindspore/mindformers.git
cd mindformers
bash build.sh
docker下载命令
docker pull swr.cn-central-221.ovaijisuan.com/mindformers/mindformers0.8.0_mindspore2.2.0:aarch_20231025
创建容器
# --device用于控制指定容器的运行NPU卡号和范围
# -v 用于映射容器外的目录
# --name 用于自定义容器名称
docker run -it -u root \
--ipc=host \
--network host \
--device=/dev/davinci0 \
--device=/dev/davinci1 \
--device=/dev/davinci2 \
--device=/dev/davinci3 \
--device=/dev/davinci4 \
--device=/dev/davinci5 \
--device=/dev/davinci6 \
--device=/dev/davinci7 \
--device=/dev/davinci_manager \
--device=/dev/devmm_svm \
--device=/dev/hisi_hdc \
-v /etc/localtime:/etc/localtime \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /var/log/npu/:/usr/slog \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
--name {请手动输入容器名称} \
swr.cn-central-221.ovaijisuan.com/mindformers/mindformers0.8.0_mindspore2.2.0:aarch_20231025 \
/bin/bash
版本对应关系 | MindFormers | MindPet | MindSpore | Python | 芯片 | 备注 |
---|---|---|---|---|---|---|
版本号 | dev | 1.0.2 | 2.2 | 3.9 | Ascend 910A/B | 开发分支(非稳定版本) |
版本号 | 0.8 | 1.0.2 | 2.2 | 3.9 | Ascend 910A/B | 发布版本分支 |
MindFormers套件对外提供两种使用和开发形式,为开发者提供灵活且简洁的使用方式和高阶开发接口。
用户可以直接clone整个仓库,按照以下步骤即可运行套件中已支持的任意configs
模型任务配置文件,方便用户快速进行使用和开发:
准备工作
git clone -b dev https://gitee.com/mindspore/mindformers.git
cd mindformers
step2: 准备相应任务的数据集,请参考docs
目录下各模型的README.md文档准备相应数据集
step3:修改配置文件configs/{model_name}/run_{model_name}_***.yaml
中数据集路径
step4:如果要使用分布式训练,则需提前生成RANK_TABLE_FILE
# 不包含8本身,生成0~7卡的hccl json文件
python mindformers/tools/hccl_tools.py --device_num [0,8)
单卡启动:统一接口启动,根据模型 CONFIG 完成任意模型的单卡训练、微调、评估、推理流程
# 训练启动,run_status支持train、finetuen、eval、predict四个关键字,以分别完成模型训练、评估、推理功能,默认使用配置文件中的run_mode
python run_mindformer.py --config {CONFIG_PATH} --run_mode {train/finetune/eval/predict}
# 8卡分布式运行, DEVICE_RANGE = [0,8), 不包含8本身
cd scripts
bash run_distribute.sh RANK_TABLE_FILE CONFIG_PATH DEVICE_RANGE RUN_MODE
RANK_TABLE_FILE: 由mindformers/tools/hccl_tools.py生成的分布式json文件
CONFIG_PATH: 为configs文件夹下面的{model_name}/run_*.yaml配置文件
DEVICE_ID: 为设备卡,范围为0~7
DEVICE_RANGE: 为单机分布式卡的范围, 如[0,8]为8卡分布式,不包含8本身
RUN_MODE: 为任务运行状态,支持关键字 train\finetune\eval\predict\export
详细高阶API使用教程请参考:MindFormers大模型使用教程
准备工作
具体安装请参考第二章。
准备相应任务的数据集,请参考docs
目录下各模型的README.md文档准备相应数据集。
Trainer 快速入门
用户可以通过以上方式安装mindformers库,然后利用Trainer高阶接口执行模型任务的训练、微调、评估、推理功能。
用户可使用Trainer.train
或者Trainer.finetune
接口完成模型的训练/微调/断点续训。
import mindspore; mindspore.set_context(mode=0, device_id=0)
from mindformers import Trainer
cls_trainer = Trainer(task='image_classification', # 已支持的任务名
model='vit_base_p16', # 已支持的模型名
train_dataset="/data/imageNet-1k/train", # 传入标准的训练数据集路径,默认支持ImageNet数据集格式
eval_dataset="/data/imageNet-1k/val") # 传入标准的评估数据集路径,默认支持ImageNet数据集格式
# Example 1: 开启训练复现流程
cls_trainer.train()
# Example 2: 加载集成的mae权重,开启微调流程
cls_trainer.finetune(finetune_checkpoint='mae_vit_base_p16')
# Example 3: 开启断点续训功能
cls_trainer.train(train_checkpoint=True, resume_training=True)
用户可使用Trainer.evaluate
接口完成模型的评估流程。
import mindspore; mindspore.set_context(mode=0, device_id=0)
from mindformers import Trainer
cls_trainer = Trainer(task='image_classification', # 已支持的任务名
model='vit_base_p16', # 已支持的模型名
eval_dataset="/data/imageNet-1k/val") # 传入标准的评估数据集路径,默认支持ImageNet数据集格式
# Example 1: 开启评估已集成模型权重的复现流程
cls_trainer.evaluate()
# Example 2: 开启评估训练得到的最后一个权重
cls_trainer.evaluate(eval_checkpoint=True)
# Example 3: 开启评估指定的模型权重
cls_trainer.evaluate(eval_checkpoint='./output/checkpoint/rank_0/mindformers.ckpt')
结果打印示例(已集成的vit_base_p16模型权重评估分数):
Top1 Accuracy=0.8317
用户可使用Trainer.predict
接口完成模型的推理流程。
import mindspore; mindspore.set_context(mode=0, device_id=0)
from mindformers import Trainer
cls_trainer = Trainer(task='image_classification', # 已支持的任务名
model='vit_base_p16') # 已支持的模型名
input_data = './cat.png' # 一张猫的图片
# Example 1: 指定输入的数据完成模型推理
predict_result_d = cls_trainer.predict(input_data=input_data)
# Example 2: 开启推理(自动加载训练得到的最后一个权重)
predict_result_b = cls_trainer.predict(input_data=input_data, predict_checkpoint=True)
# Example 3: 加载指定的权重以完成推理
predict_result_c = cls_trainer.predict(input_data=input_data, predict_checkpoint='./output/checkpoint/rank_0/mindformers.ckpt')
print(predict_result_d)
结果打印示例(已集成的vit_base_p16模型权重推理结果):
{‘label’: 'cat', score: 0.99}
pipeline 快速入门
MindFormers套件为用户提供了已集成模型的pipeline推理接口,方便用户体验大模型推理服务。
# 以gpt2 small为例
import mindspore; mindspore.set_context(mode=0, device_id=0)
from mindformers.pipeline import pipeline
pipeline_task = pipeline(task="text_generation", model="gpt2")
pipeline_result = pipeline_task("An increasing sequence: one,", do_sample=False, max_length=20)
print(pipeline_result)
结果打印示例(已集成的gpt2模型权重推理结果):
[{'text_generation_text': ['An increasing sequence: one, two, three, four, five, six, seven, eight,']}]
AutoClass 快速入门
MindFormers套件为用户提供了高阶AutoClass类,包含AutoConfig、AutoModel、AutoProcessor、AutoTokenizer四类,方便开发者进行调用。
from mindformers import AutoConfig
# 获取gpt2的模型配置
gpt2_config = AutoConfig.from_pretrained('gpt2')
# 获取vit_base_p16的模型配置
vit_base_p16_config = AutoConfig.from_pretrained('vit_base_p16')
from mindformers import AutoModel
# 利用from_pretrained功能实现模型的实例化(默认加载对应权重)
gpt2 = AutoModel.from_pretrained('gpt2')
# 利用from_config功能实现模型的实例化(默认加载对应权重)
gpt2_config = AutoConfig.from_pretrained('gpt2')
gpt2 = AutoModel.from_config(gpt2_config)
# 利用save_pretrained功能保存模型对应配置
gpt2.save_pretrained('./gpt2', save_name='gpt2')
from mindformers import AutoProcessor
# 通过模型名关键字获取对应模型预处理过程(实例化gpt2的预处理过程,通常用于Trainer/pipeline推理入参)
gpt2_processor_a = AutoProcessor.from_pretrained('gpt2')
# 通过yaml文件获取相应的预处理过程
gpt2_processor_b = AutoProcessor.from_pretrained('configs/gpt2/run_gpt2.yaml')
from mindformers import AutoTokenizer
# 通过模型名关键字获取对应模型预处理过程(实例化gpt2的tokenizer,通常用于Trainer/pipeline推理入参)
gpt2_tokenizer = AutoTokenizer.from_pretrained('gpt2')
欢迎参与社区贡献,可参考MindSpore贡献要求Contributor Wiki。
MindSpore Transformers套件的目标是构建一个大模型训练、推理、部署的全流程套件: 提供业内主流的Transformer类预训练模型, 涵盖丰富的并行特性。 期望帮助用户轻松的实现大模型训练。 文档:https://mindformers.readthedocs.io/zh-cn/latest/
Jupyter Notebook Python Markdown Shell
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》