-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cherry-pick] PART-2 : Add Dataset and Module for Sequence Classifica…
…tion task of Ernie model (#945) * Support ERNIE Export (#934) * [Ernie] PART-2 : Add Dataset and Module for Sequence Classification task of Ernie model (#935) * add ernie export yaml and shell * update * add dataset and module * add tokenizer * add training/valuation step Co-authored-by: Chang Xu <molixu7@gmail.com>
- Loading branch information
1 parent
f787795
commit 6ffc799
Showing
15 changed files
with
706 additions
and
22 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
ppfleetx/configs/nlp/ernie/finetune_ernie_345M_single_card.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
_base_: ./finetune_ernie_base.yaml | ||
|
||
Global: | ||
global_batch_size: | ||
local_batch_size: 8 | ||
micro_batch_size: 8 | ||
|
||
|
||
Model: | ||
vocab_size: 40000 | ||
hidden_size: 1024 | ||
num_hidden_layers: 24 | ||
num_attention_heads: 16 | ||
intermediate_size: | ||
hidden_act: "gelu" | ||
hidden_dropout_prob: 0.1 | ||
attention_probs_dropout_prob: 0.1 | ||
max_position_embeddings: 512 | ||
type_vocab_size: 4 | ||
initializer_range: 0.02 | ||
pad_token_id: 0 | ||
task_type_vocab_size: 3 | ||
task_id: 0 | ||
use_task_id: True | ||
use_recompute: False | ||
|
||
|
||
Distributed: | ||
dp_degree: | ||
mp_degree: 1 | ||
pp_degree: 1 | ||
sharding: | ||
sharding_degree: 1 | ||
sharding_stage: 1 | ||
sharding_offload: False | ||
reduce_overlap: False | ||
broadcast_overlap: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
Global: | ||
device: gpu | ||
seed: 1024 | ||
binary_head: True | ||
|
||
global_batch_size: | ||
local_batch_size: 16 | ||
micro_batch_size: 16 | ||
|
||
|
||
Engine: | ||
max_steps: 500000 | ||
num_train_epochs: 1 | ||
accumulate_steps: 1 | ||
logging_freq: 1 | ||
eval_freq: 500000 | ||
eval_iters: 10 | ||
test_iters: -1 | ||
mix_precision: | ||
use_pure_fp16: False | ||
scale_loss: 32768.0 | ||
custom_black_list: ["reduce_sum", "c_softmax_with_cross_entropy", "elementwise_div"] | ||
custom_white_list: ["lookup_table", "lookup_table_v2"] | ||
save_load: | ||
save_steps: 50000 | ||
save_epoch: 1 | ||
output_dir: ./output | ||
ckpt_dir: | ||
|
||
|
||
Model: | ||
module: "ErnieSeqClsModule" | ||
name: "Ernie" | ||
hidden_size: 768 | ||
num_hidden_layers: 12 | ||
num_attention_heads: 12 | ||
intermediate_size: 3072 | ||
hidden_act: "gelu" | ||
hidden_dropout_prob: 0.1 | ||
attention_probs_dropout_prob: 0.1 | ||
max_position_embeddings: 512 | ||
type_vocab_size: 2 | ||
initializer_range: 0.02 | ||
pad_token_id: 0 | ||
task_type_vocab_size: 3 | ||
task_id: 0 | ||
use_task_id: False | ||
use_recompute: False | ||
|
||
|
||
Data: | ||
Train: | ||
dataset: | ||
name: ErnieSeqClsDataset | ||
dataset_type: chnsenticorp_v2 | ||
tokenizer_type: ernie-1.0-base-zh-cw | ||
max_seq_len: 512 | ||
sampler: | ||
name: GPTBatchSampler | ||
shuffle: False | ||
drop_last: True | ||
loader: | ||
num_workers: 0 | ||
return_list: False | ||
collate_fn: | ||
name: DataCollatorWithPadding | ||
|
||
Eval: | ||
dataset: | ||
name: ErnieSeqClsDataset | ||
dataset_type: chnsenticorp_v2 | ||
tokenizer_type: ernie-1.0-base-zh-cw | ||
max_seq_len: 512 | ||
sampler: | ||
name: GPTBatchSampler | ||
shuffle: False | ||
drop_last: True | ||
loader: | ||
num_workers: 0 | ||
return_list: False | ||
collate_fn: | ||
name: DataCollatorWithPadding | ||
|
||
|
||
Optimizer: | ||
name: FusedAdamW | ||
weight_decay: 0.01 | ||
beta1: 0.9 | ||
beta2: 0.999 | ||
epsilon: 1.0e-8 | ||
lr: | ||
name: CosineAnnealingWithWarmupDecay | ||
decay_steps: 990000 | ||
warmup_rate: 0.01 | ||
max_lr: 0.0001 | ||
min_lr: 5e-05 | ||
grad_clip: | ||
name: "ClipGradByGlobalNorm" | ||
clip_norm: 1.0 | ||
tensor_fusion: False | ||
|
||
|
||
Profiler: | ||
enable: False | ||
scheduler: [1, 5] | ||
profiler_log: profiler_log | ||
detailed: False |
18 changes: 18 additions & 0 deletions
18
ppfleetx/configs/nlp/ernie/inference_ernie_345M_single_card.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
_base_: ./pretrain_ernie_base_345M_single_card.yaml | ||
|
||
|
||
Inference: | ||
model_dir: ./output | ||
mp_degree: 1 | ||
|
||
|
||
Distributed: | ||
dp_degree: | ||
mp_degree: 1 | ||
pp_degree: 1 | ||
sharding: | ||
sharding_degree: 1 | ||
sharding_stage: 1 | ||
sharding_offload: False | ||
reduce_overlap: False | ||
broadcast_overlap: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from paddlenlp.transformers import ErnieTokenizer | ||
|
||
tokenizer = None | ||
|
||
|
||
def get_ernie_tokenizer(tokenizer_type): | ||
global tokenizer | ||
if tokenizer is None: | ||
tokenizer = ErnieTokenizer.from_pretrained(tokenizer_type) | ||
|
||
return tokenizer |
Oops, something went wrong.