文件最后提交记录最后更新时间
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!5791 [自研][]Pytorch训练]GLM10B修改FA格式,关闭dropout Merge pull request !5791 from 王智伟/master 2 年前
!5611 [Fix] GLM-10B enable INF-NAN mode * GLM-10B enable inf-nan mode 2 年前
!5001 【自研】【PyTorch】修复GLM-10B多机训练时数据读取失败 * fix glm-10b readme 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!6077 [自研][]Pytorch训练]GLM10B修改FA的attn_mask为完整下三角 Merge pull request !6077 from 王智伟/master 2 年前
!5964 [自研][Pytorch训练]GLM10B微调适配FA+BF16及更新readme Merge pull request !5964 from 王智伟/master 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!5964 [自研][Pytorch训练]GLM10B微调适配FA+BF16及更新readme Merge pull request !5964 from 王智伟/master 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!5964 [自研][Pytorch训练]GLM10B微调适配FA+BF16及更新readme Merge pull request !5964 from 王智伟/master 2 年前
!4828 [自研][PyTorch]GLM-10B supports NPU * glm-10b supports NPU 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4828 [自研][PyTorch]GLM-10B supports NPU * glm-10b supports NPU 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!7376 optimize public_address_statement.md Merge pull request !7376 from 王凯宇/master 8 个月前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!5714 [自研][]Pytorch训练]GLM10B兼容适配PT2.1 Merge pull request !5714 from 王智伟/master 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!5964 [自研][Pytorch训练]GLM10B微调适配FA+BF16及更新readme Merge pull request !5964 from 王智伟/master 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
!4740 【自研】【PyTorch】GLM-10B源码上传 * GLM-10B source code 2 年前
README.md

GLM-10B for PyTorch

概述

简述

GLM是一个用自回归完型填空目标预训练的通用语言模型,可以在各种自然语言理解和生成任务中进行微调。

  • 参考实现:

    url=https://github.com/THUDM/GLM
    commit_id=4f61ed7237a3b0187f4d62062429348276a78c84
    
  • 适配昇腾 AI 处理器的实现:

    url=https://gitcode.com/ascend/ModelZoo-PyTorch.git
    code_path=PyTorch/built-in/foundation
    

准备训练环境

该模型为不随版本演进模型(随版本演进模型范围可在此处查看),未在最新昇腾配套软件中适配验证,您可以:

  1. 根据下面提供PyTorch版本在软件版本配套表中选择匹配的CANN等软件下载使用。
  2. 查看软件版本配套表后确认对该模型有新版本PyTorch和CANN中的适配需求,请在modelzoo/issues中提出您的需求。自行适配不保证精度和性能达标。

准备环境

默认配置需要每张卡有60G以上空闲内存。

  • 当前模型支持的 PyTorch 版本和已知三方库依赖如下表所示。

    表 1 版本支持表

    Torch_Version 三方库依赖版本
    PyTorch 1.11 deepspeed 0.9.2
    PyTorch 2.1 deepspeed 0.9.2
  • 环境准备指导。

    请参考《Pytorch框架训练环境准备》。

  • 安装依赖。

    1. 安装基础依赖

    在模型源码包根目录下执行命令,安装模型对应PyTorch版本需要的依赖。

    pip3 install -r requirements.txt 
    
    1. 安装deepspeed_npu插件
    cd DeepSpeed
    pip3 install -e ./
    
    1. 安装pdsh

    获取pdsh-2.34源码并解压。

    cd pdsh-2.34
    ./configure --with-ssh
    make && make install
    

准备数据集

  1. 获取数据集。

    用户自行获取原始数据集,预训练可选用的开源数据集The Pile等,微调可选用COPA数据集等。将数据集上传到服务器任意路径下并解压。

    GLM-10B预训练使用到的Pile数据集目录结构参考如下所示,完整数据集解压处理后近3T,仅使用部分数据00.jsonl预训练作为参考。多机预训练时,每节点上均须将Pile数据集移动或软连接到模型脚本目录下。默认仅使用00.jsonl文件进行预训练。

    目录结构参考如下:

    ├── GLM-10B
         ├── pile
              ├──00.jsonl
              ├──02.jsonl
              ├   ...
              ├──29.jsonl
    

    微调可使用COPA数据集,目录结构参考如下。

    ├── COPA
          ├──train.jsonl
          ├──test.jsonl
          ├──val.jsonl
    

    说明: 该数据集的训练过程脚本只作为一种参考示例。

  2. 获取词表

    用户自行获取gpt2词表,并放在模型目录中.pytorch_pretrained_bert目录下,该目录可从参考实现链接中获取,目录结构如下。

    ├── .pytorch_pretrained_bert
          ├──gpt2-merges.txt
          ├──gpt2-vocab.json
    

准备模型权重

  1. 获取语言识别模型

    用户自行获取语言识别模型lid.176.bin,并放于模型目录下,预训练或微调均依赖该模型权重。

  2. 获取预训练权重

    用户自行获取预训练权重,如glm-10b-1024,可从参考实现链接中获取,在模型目录下创建checkpoints目录,并将预训练权重放入其中。微调依赖该权重。目录结构如下。

    ├── checkpoints
          ├──glm-10b-1024
              ├──126000
                  ├──mp_rank_00_model_states.pt
              ├──latest
              ├──latest_checkpointed_iteration.txt
    

开始训练

训练模型

  1. 进入解压后的源码包根目录。

    cd /${模型文件夹名称}
    
  2. 运行训练脚本。

    该模型预训练支持双机16卡,微调支持单机8卡。

    • 双机16卡预训练 修改hostfile文件,参考默认配置修改为双机IP。

      启动16卡训练。

      bash ./tests/train_pretrain_full_16p.sh # 16卡预训练长稳
      
      bash ./tests/train_pretrain_performance_16p.sh # 16卡预训练性能
      
      bash ./tests/train_pretrain_full_16p_single_node.sh # 单机16卡预训练长稳
      
      

      --data_path参数填写数据集路径,若仅使用一个jsonl文件,指定到具体的文件,若使用多个,指定到上一级目录; 模型在tests/env_npu.sh设置ASCEND_USE_FLASH_ATTN开关,默认为True--开启FA;

    • 单机8卡微调

      启动8卡微调。

      bash ./tests/train_finetune_full_8p.sh --data_path=/data/xxx/  # 8卡微调精度,
      

      --data_path参数填写数据集路径,需写到微调数据集的上一级目录,如COPA的上一级;

    模型训练参数说明如下。

    公共参数:
    --train-iters                       //训练总迭代数
    --fp16                              //是否使用fp16训练
    --train_micro_batch_size_per_gpu    //每卡训练批次大小
    --lr                                //学习率
    --stage                             //ZeRO stage配置
    --seed                              //使用随机数种子
    

    训练完成后,权重文件保存在当前路径下,并输出模型训练精度和性能信息。

训练结果展示

表 2 训练结果展示表

NAME SamplesPerSec Iterations DataType Torch_Version
Pretrain 16p-NPU 39 5000 fp16 1.11
Pretrain 16p-GPU 38 5000 fp16 1.11
Pretrain 16p-NPU 44 5000 bf16 2.1
Pretrain 16p-GPU 41 5000 bf16 2.1
NAME Accuracy Epochs DataType Torch_Version
Finetune 8p-NPU 98 100 fp16 1.11
Finetune 8p-GPU 98 100 fp16 1.11
Finetune 8p-NPU 52 100 bf16 2.1
Finetune 8p-GPU 52 100 bf16 2.1

说明: Accuracy指微调过程中最高精度,实际验证NPU与GPU均存在1~2%波动。

版本说明

变更

2023.6.10:首次发布。 2023.11.15:预训练支持BF16和FA 2023.12.15:微调支持BF16和FA

FAQ

  1. 报错torch.cuda.nvtx缺少range属性

    # 早期版本适配问题,新版本已修复。
    # 若遇到该报错,修改deepspeed/utils/nvtx.py如下。
    
    def instrument_w_nvtx(func):
        return func
    
    

公网地址说明

代码涉及公网地址参考 public_address_statement.md