PengCheng.Mind 又称鹏城·脑海,是鹏城实验室基于鹏程·盘古α开发、开源、开放的基于Transformer架构的自回归式语言模型,目前包含7B、200B两个版本。模型全流程基于中国算力网的全自主安全可控国产软硬件平台进行开发和训练,采用MindSpore框架实现在大规模集群上长期稳定的多维分布式并行训练。鹏城·脑海模型主要聚焦中文核心能力,兼顾英文和部分多语言能力。当前模型已完成训练1.5T Tokens数据量,正式对外发布进阶版,可以在申请表中申请试用,模型仍在持续训练迭代中。
随着中国算力网的不断发展壮大,我们希望通过模型训练全流程开源开放的方式,将鹏城·脑海200B 模型培育为算力网上一个种子应用,吸引产学研界更多人参与到通用大语言模型基座的研究和应用中,一起助力国产智能软硬件生态的发展。
结构参数 | N(params) | N(layers) | D(model) | N(heads) | D(head) | seq_length | vocab_size |
---|---|---|---|---|---|---|---|
PengCheng.Mind 200B | 201.1 B | 104 | 12672 | 96 | 132 | 4096 | 49984 |
支持 python >= 3.7.5, mindspore >= 2.0.0 版本.
推荐使用mindspore的官方 docker 镜像。
硬件平台 | 操作系统 | 框架 | 7B推理 | 200B推理 | 200B 微调 |
---|---|---|---|---|---|
Ascend 910 | EulerOS-aarch64 | MindSpore | 1卡 | 16卡 | 144卡 |
python predict_200B.py \
--run_type predict \
--mode 200B \
--distribute true \
--use_pynative_op 1 \
--op_level_model_parallel_num 16 \
--device_num 16 \
--use_rope True \
--stage_num 1 \
--restore_checkpoint_bucket_dir /path/to/checkpoint/ \
--restore_ckpt_name_prefix PengCheng_Mind-200B.ckpt \
--top_p 1.0 \
--top_k_num 3 \
--max_generate_length 100
参考数据部分
运行脚本:(这里以144卡增量训练为例)
python train.py \
--data_url YOUR_OUTPUT_PATH \
--mode 200B \
--embedding_size 12672 \
--num_layers 104 \
--num_heads 96 \
--seq_length 4096 \
--device_num 144 \
--stage_num 18 \
--op_level_model_parallel 8 \
--micro_size 32 \
--optimizer_shard 0 \
--start_lr 5e-6 \
--end_lr 1e-6 \
--decay_steps 10000 \
--warmup_step 200 \
--per_batch_size 1 \
--epoch_size 1 \
--sink_size 4 \
--param_init_type fp16 \
--save_checkpoint True \
--save_checkpoint_steps 100 \
--recompute True \
--use_rope True \
--use_flash_attention True \
--sequence_parallel True \
--softmax_compute_fp32 FP32 \
--save_checkpoint_bucket_dir YOUR_SFT_OBS_PATH \
--pre_trained True \
--restore_checkpoint_bucket_dir PRETRAINED_MODEL_OBS_DIR \
--restore_ckpt_name_prefix PengCheng-Mind-200B_500bTokens.ckpt \
--pipeline_config_filename YOUR_PIPLINE_CONFIG_PATH
训练模型包含优化器参数,采用分片保存,鹏城·脑海 200B模型训练保存为3456个模型分片,finetune可在Ascend 910 144卡上进行,如果要进行微调,由于使用算力资源的差异,需要对模型切片进行合并。
推理模型我们提供的是转换好的16个分片的模型,无需进行模型分片的转换,如有需要可参考微调转换流程。
参考脚本
import mindspore
# 1、融合训练保存的分片策略文件
train_strategy_files = "/path/to/train_strategy/"
train_strategy_file_merged = "/path/to/train_strategy_merged.ckpt"
mindspore.merge_pipeline_strategys(src_strategy_dirs=train_strategy_files,
dst_strategy_file=train_strategy_file_merged)
# 2、融合微调保存的分片策略文件(需要根据并行策略配置先跑通生成策略文件)
finetune_strategy_files = "/path/to/train_strategy/"
finetune_strategy_file_merged = "/path/to/train_strategy_merged.ckpt"
mindspore.merge_pipeline_strategys(src_strategy_dirs=train_strategy_files,
dst_strategy_file=train_strategy_file_merged)
# 3、根据训练和微调策略文件调用接口进行分片模型文件的转换,考虑到机器内存限制采用分片逐个转换
for transform_rank in range(144):
# 获取转换transform_rank分片所需的源模型分片列表
rank_list = mindspore.rank_list_for_transform(rank_id = transform_rank,
src_strategy_file=train_strategy_file_merged,
dst_strategy_file=finetune_strategy_file_merged)
rank_list.sort(reverse=True)
checkpoint_files_map = {}
for k in rank_list:
# 对应rank分片模型的位置
checkpoint_files_map[k] = f"/path/to/rank_{k}/checkpoint_rank_{k}.ckpt"
# 转换得到对应分片模型
save_checkpoint_file_name = f"/save/to/checkpoint_rank_{transform_rank}.ckpt"
mindspore.transform_checkpoint_by_rank(rank_id = transform_rank,
checkpoint_files_map = checkpoint_files_map,
save_checkpoint_file_name = save_checkpoint_file_name,
src_strategy_file=train_strategy_file_merged,
dst_strategy_file=train_strategy_file_merged)
参考脚本:/tools/pre_process_data.py
在 YOUR_DATASET_PATH 目录下存放多个 xxx.json
文件,如果训练数据较多,最好每个 json
文件大小统一,且分开多个 json
存放,
大小可以 1M 一个文件。如果有繁体文字,需要转成简体,可以使用zhconv
。
每个 json
文本格式为(需要换行符号分割不同样本):
{"text": "sample1"}
{"text": "sample2"}
{"text": "sample2"}
python pre_process_data.py --input_globs "YOUR_DATASET_PATH/*.json" --output_file "YOUR_OUTPUT_PATH/mindrecord" --SEQ_LEN 4097
将会在YOUR_OUTPUT_PATH目录下生成mindrecord* 文件。
我们尽我们所能,来确保模型训练过程中使用的数据的合规性。然而,尽管我们已经做出了巨大的努力,但由于模型和数据的复杂性,仍有可能存在一些无法预见的问题。因此,如果由于使用鹏城·脑海开源模型而导致的任何问题,包括但不限于数据安全问题、公共舆论风险,或模型被误导、滥用、传播或不当利用所带来的任何风险和问题,我们将不承担任何责任。
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》