文件最后提交记录最后更新时间
!6618 fixed issue with py3.11+PT2.4 Merge pull request !6618 from 何金朗/master 1 年前
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 个月前
!4751 [自研][PyTorch] Bert-CRF当batchsize比较大时,大幅提升性能 * 修复batchsize增大时,性能不及预期的问题 2 年前
!2242 [自研][PyTorch] Bert-CRF_for_PyTorch模型上库 !2242 [自研][PyTorch] Bert-CRF_for_PyTorch模型上库 3 年前
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 个月前
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 个月前
!7376 optimize public_address_statement.md Merge pull request !7376 from 王凯宇/master 8 个月前
!6618 fixed issue with py3.11+PT2.4 Merge pull request !6618 from 何金朗/master 1 年前
!2242 [自研][PyTorch] Bert-CRF_for_PyTorch模型上库 !2242 [自研][PyTorch] Bert-CRF_for_PyTorch模型上库 3 年前
README.md

Bert-CRF for PyTorch

概述

简述

bert4torch是一个基于pytorch的训练框架,前期以效仿和实现bert4keras的主要功能为主,方便加载多类预训练模型进行finetune,提供了中文注释方便用户理解模型结构。主要是期望应对新项目时,可以直接调用不同的预训练模型直接finetune,或方便用户基于bert进行修改,快速验证自己的idea;节省在github上clone各种项目耗时耗力,且本地文件各种copy的问题。

  • 参考实现:

    url=https://github.com/Tongjilibo/bert4torch
    commit_id=43c28f9dbc5fe20b9ae57fb5050658dca617f3d1
    
  • 适配昇腾 AI 处理器的实现:

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

准备训练环境

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

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

准备环境

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

    表 1 版本支持表

    Torch_Version 三方库依赖版本
    PyTorch 1.5 -
    PyTorch 1.8 -
    PyTorch 1.11 -
    PyTorch 2.1 -
  • 环境准备指导。

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

  • 安装依赖。

    在模型源码包根目录下执行命令。

    pip install -r requirements.txt
    
  • 本模型在X86平台上性能显著高于ARM。

准备数据集

  1. 获取数据集。

    主要参考bert4torch进行人民日报 NER 数据集准备。 用户需自己新建一个 $data_path 路径,用于放预训练模型和数据集,$data_path 可以设置为服务器的任意目录(注意存放的磁盘需要为NVME固态硬盘)。 下载人民日报数据集,解压到 $data_path 下。

    数据集目录结构参考如下。

    $data_path
    └── china-people-daily-ner-corpus
        ├── example.dev
        ├── example.test
        └── example.train
    

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

获取预训练模型

用户需在 $data_path 目录下新建 pretrained_model 文件夹,下载Bertbase chinese预训练模型,将下载好的文件放在 $data_path/pretrained_model 目录下。

$data_path 最终的目录结构如下。

$data_path
├── china-people-daily-ner-corpus
│   ├── example.dev
│   ├── example.test
│   └── example.train
└── pretrained_model
    ├── config.json
    ├── pytorch_model.bin
    ├── tokenizer_config.json
    ├── tokenizer.json
    └── vocab.txt

开始训练

训练模型

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

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

    该模型支持单机单卡训练和单机8卡训练。

    • 单机单卡训练

      启动单卡训练。

      bash ./test/train_full_1p.sh --data_path=$data_path  # 单卡精度
      
      bash ./test/train_performance_1p.sh --data_path=$data_path # 单卡性能
      
    • 单机8卡训练

      启动8卡训练。

      bash ./test/train_full_8p.sh --data_path=$data_path  # 8卡精度
      
      bash ./test/train_performance_8p.sh --data_path=$data_path # 8卡性能
      

      启动高性能训练。

      bash ./test/train_full_1p_fast.sh --data_path=$data_path  # 单卡精度
      bash ./test/train_full_8p_fast.sh --data_path=$data_path  # 8卡精度
      

    --data_path参数填写数据集路径,需写到数据集的一级目录。

    模型训练脚本参数说明如下。

    公共参数:
    --train_epochs                      //训练的总epochs数
    --workers                           //dataloader开启的线程数
    --data_path                         //数据集路径
    

    训练完成后,权重文件默认会写入到和test文件同一目录下,并输出模型训练精度和性能信息到网络脚本test下output文件夹内。

训练结果展示

表 2 训练结果展示表

NAME CPU_Type Accuracy-Highest samples/s Epochs AMP_Type Torch_Version
1p-竞品A X86 best_F1: 0.95499 97 20 O1 1.5
8p-竞品A X86 best_F1: 0.92541 719.1 20 O1 1.5
1p-NPU 非arm best_F1: 0.96499 145 20 O1 1.8
8p-NPU 非arm best_F1: 0.95729 944.5 20 O1 1.8
8p-NPU arm best_F1: 0.95729 651.2 20 O1 1.11

表 3 高性能单卡,8卡训练结果展示表

NAME Accuracy-Highest samples/s Epochs AMP_Type Torch_Version
1p-NPU best_F1: 0.95690 1010 20 O2 1.11
8p-NPU best_F1: 0.94647 7738 20 O2 1.11

说明: 高性能训练脚本与普通脚本在参数设置上有区别:1、每张卡的batchsize由16提升为192;2、混合精度模式采用O2。

版本说明

变更

2022.10.12:首次发布。 2023.05.23:首次变更。

FAQ

无。

公网地址说明

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