Skip to content

Commit 361d91c

Browse files
authored
[BugFix] Fix model zoo relative import (#2130)
* fix as relative import * add soft link * refine * copy data tools to model * fix gpt-3 * refine gpt readme. * delete unused dataset utils code * delete some code. * softlink * move data_tools to ernie. * fix
1 parent 6de32e5 commit 361d91c

28 files changed

+436
-25
lines changed

examples/language_model/gpt-3/README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,53 @@ GPT-[3](https://arxiv.org/pdf/2005.14165.pdf) 是以[Transformer](https://arxiv.
2222
注:需要PaddlePaddle版本大于等于2.2rc,或者使用最新develop版本,安装方法请参见Paddle[官网](https://www.paddlepaddle.org.cn)
2323

2424

25+
### 数据获取与制作
26+
27+
[OpenWebTextCorpus](https://skylion007.github.io/OpenWebTextCorpus/)是一个开源的英文网页文本数据集,数据来源于Reddit,经过去重、清洗、提取,最终包含800多万个文档。
28+
本示例采用EleutherAI清洗好的[OpenWebText2数据](https://openwebtext2.readthedocs.io/en/latest/index.html#download-plug-and-play-version)
29+
30+
下载以后通过以下命令解压:
31+
32+
```shell
33+
wget https://mystic.the-eye.eu/public/AI/pile_preliminary_components/openwebtext2.jsonl.zst.tar
34+
tar -xvf openwebtext2.json.zst.tar -C /path/to/openwebtext
35+
```
36+
37+
然后使用[data_tools](./data_tools)工具下的`create_pretraining_data.py`脚本进行数据集制作:
38+
```
39+
python -u create_pretraining_data.py \
40+
--model_name gpt2-en \
41+
--tokenizer_name GPTTokenizer \
42+
--data_format JSON \
43+
--input_path /path/to/openwebtext/ \
44+
--append_eos \
45+
--output_prefix gpt_openwebtext \
46+
--workers 40 \
47+
--log_interval 10000
48+
```
49+
处理时间约一个小时左右,就可以得到我们需要的`gpt_openwebtext_ids.npy`, `gpt_openwebtext_idx.npz`数据集文件。
50+
51+
为了方便用户运行测试本模型,本项目提供了处理好的300M的训练样本:
52+
```shell
53+
wget https://bj.bcebos.com/paddlenlp/models/transformers/gpt/data/gpt_en_dataset_300m_ids.npy
54+
wget https://bj.bcebos.com/paddlenlp/models/transformers/gpt/data/gpt_en_dataset_300m_idx.npz
55+
```
56+
57+
将所有预处理得到的文件统一放入一个文件夹中,以备训练使用:
58+
59+
```
60+
mkdir data
61+
mv gpt_en_dataset_300m_ids.npy ./data
62+
mv gpt_en_dataset_300m_idx.npz ./data
63+
```
64+
65+
2566
```shell
2667
cd static # 或者 cd dygraph
2768
# 下载样例数据
2869
mkdir data && cd data
29-
wget https://bj.bcebos.com/paddlenlp/models/transformers/gpt/train.data.json_ids.npz
70+
wget https://bj.bcebos.com/paddlenlp/models/transformers/gpt/data/gpt_en_dataset_300m_ids.npy
71+
wget https://bj.bcebos.com/paddlenlp/models/transformers/gpt/data/gpt_en_dataset_300m_idx.npz
3072
cd ..
3173
# 运行pretrian 脚本
3274
sh run.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../model_zoo/ernie-1.0/data_tools

examples/language_model/gpt-3/dygraph/lr.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import math
16+
import numpy
17+
import warnings
18+
from paddle import Tensor
19+
from paddle.optimizer.lr import LRScheduler
20+
21+
22+
class CosineAnnealingWithWarmupDecay(LRScheduler):
23+
def __init__(self,
24+
max_lr,
25+
min_lr,
26+
warmup_step,
27+
decay_step,
28+
last_epoch=0,
29+
verbose=False):
30+
31+
self.decay_step = decay_step
32+
self.warmup_step = warmup_step
33+
self.max_lr = max_lr
34+
self.min_lr = min_lr
35+
super(CosineAnnealingWithWarmupDecay, self).__init__(max_lr, last_epoch,
36+
verbose)
37+
38+
def get_lr(self):
39+
if self.warmup_step > 0 and self.last_epoch <= self.warmup_step:
40+
return float(self.max_lr) * (self.last_epoch) / self.warmup_step
41+
42+
if self.last_epoch > self.decay_step:
43+
return self.min_lr
44+
45+
num_step_ = self.last_epoch - self.warmup_step
46+
decay_step_ = self.decay_step - self.warmup_step
47+
decay_ratio = float(num_step_) / float(decay_step_)
48+
coeff = 0.5 * (math.cos(math.pi * decay_ratio) + 1.0)
49+
return self.min_lr + coeff * (self.max_lr - self.min_lr)

examples/language_model/gpt-3/dygraph/run_pretrain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# to import data_tools
3131
filepath = os.path.abspath(os.path.dirname(__file__))
32-
sys.path.insert(0, os.path.join(filepath, "../../"))
32+
sys.path.insert(0, os.path.join(filepath, "../"))
3333

3434
from dataset import create_pretrained_dataset
3535
from args import parse_args

examples/language_model/gpt-3/static/args.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)