Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New features] testing example of model zoo #4398

Merged
merged 23 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eb98e53
update model-zoo test
wj-Mcat Jan 9, 2023
06d3714
update config
wj-Mcat Jan 10, 2023
8354d82
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
wj-Mcat Jan 10, 2023
b051d5f
Merge branch 'PaddlePaddle:develop' into add-gpt-testing
wj-Mcat Jan 10, 2023
6de8bc4
update model-zoo test
wj-Mcat Jan 9, 2023
604c413
merge develop branch
wj-Mcat Jan 28, 2023
85b1a9c
Merge branch 'develop' of github.com:PaddlePaddle/PaddleNLP into add-…
wj-Mcat Jan 28, 2023
34c53e6
update config for gpt
wj-Mcat Jan 28, 2023
f12a035
add from_hf_hubarg
wj-Mcat Jan 28, 2023
fc926e9
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
wj-Mcat Jan 30, 2023
1ce33dd
Merge branch 'add-gpt-testing' of github.com:wj-Mcat/PaddleNLP into a…
wj-Mcat Jan 30, 2023
1b4b472
update model-zoo gpt
wj-Mcat Jan 30, 2023
882f18c
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
wj-Mcat Jan 30, 2023
dd813e6
add export & infer test
wj-Mcat Jan 30, 2023
a720b2d
Merge branch 'add-gpt-testing' of github.com:wj-Mcat/PaddleNLP into a…
wj-Mcat Jan 30, 2023
ad225f1
use with argv context
wj-Mcat Jan 30, 2023
cb0abb7
update gpt testing
wj-Mcat Jan 30, 2023
c6b76e9
update gpt configuration
wj-Mcat Jan 31, 2023
7daa40c
Merge branch 'develop' of github.com:PaddlePaddle/PaddleNLP into add-…
wj-Mcat Jan 31, 2023
af67ea5
skip gpt-ci
wj-Mcat Jan 31, 2023
6aba70e
fix lint
wj-Mcat Jan 31, 2023
6862118
Update tests/model_zoo/test_gpt.py
wj-Mcat Jan 31, 2023
5a4faa5
update ci-case & config variable name
wj-Mcat Jan 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions model_zoo/gpt/configs/default/generation.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions model_zoo/gpt/configs/default/glue.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions model_zoo/gpt/configs/default/msra_ner.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions model_zoo/gpt/configs/default/pretrain.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions model_zoo/gpt/configs/test/glue.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions model_zoo/gpt/configs/test/msra_ner.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions model_zoo/gpt/configs/test/pretrain.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions model_zoo/gpt/run_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def parse_args():
type=str,
help="The path or shortcut name of the pre-trained model.",
)
parser.add_argument("--from_hf_hub", type=bool, default=False, help="Whether load model from hf hub")
parser.add_argument(
"--decode_strategy", type=str, default="greedy_search", help="The decode strategy in generation."
)
Expand Down Expand Up @@ -112,8 +113,8 @@ def main(args, input_text):
)
)

model = model_class.from_pretrained(args.model_name_or_path)
tokenizer = tokenizer_class.from_pretrained(args.model_name_or_path)
model = model_class.from_pretrained(args.model_name_or_path, from_hf_hub=args.from_hf_hub)
tokenizer = tokenizer_class.from_pretrained(args.model_name_or_path, from_hf_hub=args.from_hf_hub)
model.eval()

args.max_dec_len = adjust_length_to_model(args.max_dec_len, model.max_position_embeddings)
Expand Down
8 changes: 0 additions & 8 deletions model_zoo/gpt/run_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import numpy as np
import paddle
from args import parse_config_file
from paddle.io import DataLoader
from paddle.metric import Accuracy

Expand Down Expand Up @@ -224,11 +223,4 @@ def do_train():


if __name__ == "__main__":
# support: python run_glue.py --config=./configs/default.yaml
config_file = parse_config_file()
if config_file is not None:
from args import init_argv

init_argv("glue", config_file)

do_train()
4 changes: 0 additions & 4 deletions model_zoo/gpt/run_msra_ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from functools import partial

import paddle
from args import init_argv, parse_config_file

from paddlenlp.data import DataCollatorForTokenClassification
from paddlenlp.datasets import load_dataset
Expand Down Expand Up @@ -154,7 +153,4 @@ def do_train():


if __name__ == "__main__":
config_file = parse_config_file()
if config_file is not None:
init_argv("msra_ner", config_file)
do_train()
8 changes: 5 additions & 3 deletions model_zoo/gpt/run_pretrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def eval_freq(self):

@dataclass
class ModelArguments:
model_type: str = field(default="gpt", metadata={"help": "the type of model"})
model_name_or_path: str = field(default="gpt2-en", metadata={"help": ""})
max_seq_len: int = field(default=128, metadata={"help": "max sequence length"})
to_static: bool = field(default=False, metadata={"help": "whether use static pretraining mode."})
Expand Down Expand Up @@ -369,9 +370,10 @@ def do_train():
# Now, we only support data parallel in dygraph mode for now.
topo = Topology(device_rank=worker_index, world_size=worker_num, dp_degree=worker_num)

tokenizer = GPTTokenizer.from_pretrained(model_args.model_name_or_path)
pretrained_models_list = list(GPTForPretraining.pretrained_init_configuration.keys())
model = GPTForPretraining.from_pretrained(model_args.model_name_or_path)
model_class, tokenizer_class = MODEL_CLASSES[model_args.model_type]
tokenizer = tokenizer_class.from_pretrained(model_args.model_name_or_path)
pretrained_models_list = list(model_class.pretrained_init_configuration.keys())
model = model_class.from_pretrained(model_args.model_name_or_path)

# Create the critrion for the gpt model
criterion = GPTPretrainingCriterion()
Expand Down
95 changes: 48 additions & 47 deletions scripts/regression/ci_case.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,53 +279,54 @@ print_info $? gpt_deploy_C_FT
}
# 8 gpt
gpt(){
if [ ! -f 'test.py' ];then
echo '模型测试文件不存在!'
# data process
cd ${nlp_dir}/model_zoo/ernie-1.0/data_tools
sed -i "s/python3/python/g" Makefile
sed -i "s/python-config/python3.7m-config/g" Makefile
cd ${nlp_dir}/model_zoo/gpt/
# pretrain
python -m paddle.distributed.launch run_pretrain.py \
--model_name_or_path "__internal_testing__/gpt" \
--input_dir "./pre_data" \
--output_dir "output" \
--weight_decay 0.01 \
--max_steps 2 \
--save_steps 2 \
--device gpu \
--warmup_steps 320000 \
--warmup_ratio 0.01 \
--micro_batch_size 8 \
--eval_steps 100 \
--overwrite_output_dir true \
--dataloader_drop_last true \
--do_train true \
--do_predict true >${log_path}/gpt_pretrain >>${log_path}/gpt_pretrain 2>&1
print_info $? gpt_pretrain
# export model
python export_model.py --model_type=gpt \
--model_path=gpt2-medium-en \
--output_path=./infer_model/model >${log_path}/gpt_export >>${log_path}/gpt_export 2>&1
print_info $? gpt_export
# inference
python deploy/python/inference.py \
--model_type gpt \
--model_path ./infer_model/model >${log_path}/gpt_p_depoly >>${log_path}/gpt_p_depoly 2>&1
print_info $? gpt_p_depoly
# test acc
# cd ${nlp_dir}/tests/examples/gpt/
# time (python -m unittest test_accuracy.py >${log_path}/gpt_test_acc) >>${log_path}/gpt_test_acc 2>&1
# print_info $? gpt_test_acc
else
pytest ${nlp_dir}/model_zoo/gpt/ >${log_path}/gpt >>${log_path}/gpt 2>&1
print_info $? gpt
fi
fast_gpt
cd ${nlp_dir}/fast_generation/samples
python gpt_sample.py >${log_path}/fast_generation_gpt >>${log_path}/fast_generation_gpt 2>&1
print_info $? fast_generation_gpt
echo 'skip gpt testing in paddle-ci, for details you can see: https://github.com/PaddlePaddle/PaddleNLP/pull/4398'
# if [ ! -f 'test.py' ];then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接删除吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我先把gpt 的函数体代码给删掉,这里留一个 todo 让军军去删除其他关联的脚本(免得没删干净导致一些运行时的 bug)

# echo '模型测试文件不存在!'
# # data process
# cd ${nlp_dir}/model_zoo/ernie-1.0/data_tools
# sed -i "s/python3/python/g" Makefile
# sed -i "s/python-config/python3.7m-config/g" Makefile
# cd ${nlp_dir}/model_zoo/gpt/
# # pretrain
# python -m paddle.distributed.launch run_pretrain.py \
# --model_name_or_path "__internal_testing__/gpt" \
# --input_dir "./pre_data" \
# --output_dir "output" \
# --weight_decay 0.01 \
# --max_steps 2 \
# --save_steps 2 \
# --device gpu \
# --warmup_steps 320000 \
# --warmup_ratio 0.01 \
# --micro_batch_size 8 \
# --eval_steps 100 \
# --overwrite_output_dir true \
# --dataloader_drop_last true \
# --do_train true \
# --do_predict true >${log_path}/gpt_pretrain >>${log_path}/gpt_pretrain 2>&1
# print_info $? gpt_pretrain
# # export model
# python export_model.py --model_type=gpt \
# --model_path=gpt2-medium-en \
# --output_path=./infer_model/model >${log_path}/gpt_export >>${log_path}/gpt_export 2>&1
# print_info $? gpt_export
# # inference
# python deploy/python/inference.py \
# --model_type gpt \
# --model_path ./infer_model/model >${log_path}/gpt_p_depoly >>${log_path}/gpt_p_depoly 2>&1
# print_info $? gpt_p_depoly
# # test acc
# # cd ${nlp_dir}/tests/examples/gpt/
# # time (python -m unittest test_accuracy.py >${log_path}/gpt_test_acc) >>${log_path}/gpt_test_acc 2>&1
# # print_info $? gpt_test_acc
# else
# pytest ${nlp_dir}/model_zoo/gpt/ >${log_path}/gpt >>${log_path}/gpt 2>&1
# print_info $? gpt
# fi
# fast_gpt
# cd ${nlp_dir}/fast_generation/samples
# python gpt_sample.py >${log_path}/fast_generation_gpt >>${log_path}/fast_generation_gpt 2>&1
# print_info $? fast_generation_gpt
}
# 9 ernie-1.0
ernie-1.0 (){
Expand Down
95 changes: 95 additions & 0 deletions tests/fixtures/model_zoo/gpt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
pretrain:
slow:
model_type: gpt
model_name_or_path: __internal_testing__/gpt
input_dir: ./data
output_dir: ./output_dir/pretrain
weight_decay: 0.01
max_steps: 2
save_steps: 10
warmup_steps: 10
warmup_ratio: 0.01
per_device_train_batch_size: 4
device: cpu
eval_steps: 10
do_train: true
do_predict: true

default:
model_type: gpt
model_name_or_path: gpt2-en
warmup_steps: 320000
warmup_ratio: 0.01
per_device_train_batch_size: 4
device: cpu
eval_steps: 100
do_train: true
do_predict: true


msra_ner:
slow:
model_name_or_path: __internal_testing__/gpt_cn
max_seq_length: 32
per_device_eval_batch_size: 4
learning_rate: 2e-5
num_train_epochs: 3
logging_steps: 25
save_steps: 250
output_dir: ./output_dir/msra_ner/
device: cpu
do_train: true
max_steps: 10

default:
model_name_or_path: gpt-cpm-small-cn-distill
max_seq_length: 128
per_device_eval_batch_size: 32
learning_rate: 2e-5
num_train_epochs: 3
logging_steps: 25
save_steps: 250
output_dir: ./tmp/msra_ner/
device: gpu
do_train: true

glue:
slow:
model_name_or_path: __internal_testing__/gpt
task_name: SST-2
max_seq_length: 128
per_device_train_batch_size: 32
learning_rate: 2e-5
num_train_epochs: 3
logging_steps: 1
save_steps: 500
output_dir: ./output_dir/glue
max_steps: 10
eval_steps: 1
device: cpu
do_train: true

default:
model_name_or_path: gpt2-medium-en
task_name: SST-2
max_seq_length: 128
per_device_train_batch_size: 32
learning_rate: 2e-5
num_train_epochs: 3
logging_steps: 1
save_steps: 500
output_dir: ./output_dir/glue
eval_steps: 1
device: gpu
do_train: true


generation:
slow:
model_type: gpt2
model_name_or_path: hf-internal-testing/tiny-random-GPT2Model
from_hf_hub: true

default:
model_type: gpt2-cn
model_name_or_path: gpt-cpm-small-cn-distill
13 changes: 13 additions & 0 deletions tests/model_zoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 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.
Loading