Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions examples/language_model/gpt-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ GPT-[3](https://arxiv.org/pdf/2005.14165.pdf) 是以[Transformer](https://arxiv.

## 使用方法

### 环境依赖

- regex
- sentencepiece
- tqdm
- visualdl
- paddlepaddle-gpu >= 2.2rc

安装命令 `pip install regex sentencepiece tqdm visualdl`。
注:需要PaddlePaddle版本大于等于2.2rc,或者使用最新develop版本,安装方法请参见Paddle[官网](https://www.paddlepaddle.org.cn)。


```shell
cd static # 或者 cd dygraph
# 下载样例数据
Expand Down
46 changes: 15 additions & 31 deletions examples/language_model/gpt-3/static/run_pretrain_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,33 +294,17 @@ def do_train(args):
p.name for n, p in model.named_parameters()
if not any(nd in n for nd in ["bias", "norm"])
]
# TODO @ZHUI Use paddle.optimizer.AdamW
if ops.optimizer._jit_compile():
logger.info("Using paddlenlp custom AdamW optimizer.")
optimizer = ops.optimizer.AdamwOptimizer(
learning_rate=lr_scheduler,
beta1=args.adam_beta1,
beta2=args.adam_beta2,
epsilon=args.adam_epsilon,
grad_clip=clip,
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_param)
else:
if args.sharding_degree > 1:
raise ValueError(
"The paddle.optimizer.AdamW not compatible with Sharding!"
)
logger.info("Using paddle.optimizer.AdamW.")
optimizer = paddle.optimizer.AdamW(
learning_rate=lr_scheduler,
beta1=args.adam_beta1,
beta2=args.adam_beta2,
epsilon=args.adam_epsilon,
grad_clip=clip,
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_param)
# alias
optimizer.apply_optimize = optimizer._apply_optimize

optimizer = paddle.optimizer.AdamW(
learning_rate=lr_scheduler,
beta1=args.adam_beta1,
beta2=args.adam_beta2,
epsilon=args.adam_epsilon,
grad_clip=clip,
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_param)
# alias
optimizer.apply_optimize = optimizer._apply_optimize
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是个不兼容的修改,在文档中注明一下使用的paddlepaddle的版本吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if args.use_recompute:
dist_strategy.recompute = True
Expand All @@ -341,12 +325,12 @@ def do_train(args):
if not os.path.isdir(program_desc_dir):
os.mkdir(program_desc_dir)

with open(program_desc_dir + "/main_program.txt.%d" %
(int(os.environ.get('FLAGS_selected_gpus', 0))), 'w') as f:
with open(program_desc_dir + "/main_program.txt.%d" % worker_index,
'w') as f:
f.write(str(main_program))

with open(program_desc_dir + "/startup_program.txt.%d" %
(int(os.environ.get('FLAGS_selected_gpus', 0))), 'w') as f:
with open(program_desc_dir + "/startup_program.txt.%d" % worker_index,
'w') as f:
f.write(str(startup_program))

# Define the Executor for running the static model
Expand Down
6 changes: 5 additions & 1 deletion examples/language_model/gpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ GPT-[2](https://cdn.openai.com/better-language-models/language_models_are_unsupe
## 快速开始

### 环境依赖

- regex
- sentencepiece
- tqdm
- visualdl
安装命令 `pip install regex sentencepiece tqdm visualdl`
- paddlepaddle-gpu >= 2.2rc

安装命令 `pip install regex sentencepiece tqdm visualdl`。
注:需要PaddlePaddle版本大于等于2.2rc,或者使用最新develop版本,安装方法请参见Paddle[官网](https://www.paddlepaddle.org.cn)。

### 数据准备

Expand Down
47 changes: 16 additions & 31 deletions examples/language_model/gpt/run_pretrain_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,33 +294,18 @@ def do_train(args):
p.name for n, p in model.named_parameters()
if not any(nd in n for nd in ["bias", "norm"])
]
# TODO @ZHUI Use paddle.optimizer.AdamW
if ops.optimizer._jit_compile():
logger.info("Using paddlenlp custom AdamW optimizer.")
optimizer = ops.optimizer.AdamwOptimizer(
learning_rate=lr_scheduler,
beta1=args.adam_beta1,
beta2=args.adam_beta2,
epsilon=args.adam_epsilon,
grad_clip=clip,
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_param)
else:
if args.sharding_degree > 1:
raise ValueError(
"The paddle.optimizer.AdamW not compatible with Sharding!"
)
logger.info("Using paddle.optimizer.AdamW.")
optimizer = paddle.optimizer.AdamW(
learning_rate=lr_scheduler,
beta1=args.adam_beta1,
beta2=args.adam_beta2,
epsilon=args.adam_epsilon,
grad_clip=clip,
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_param)
# alias
optimizer.apply_optimize = optimizer._apply_optimize

optimizer = paddle.optimizer.AdamW(
learning_rate=lr_scheduler,
beta1=args.adam_beta1,
beta2=args.adam_beta2,
epsilon=args.adam_epsilon,
grad_clip=clip,
weight_decay=args.weight_decay,
apply_decay_param_fun=lambda x: x in decay_param)

# alias
optimizer.apply_optimize = optimizer._apply_optimize
Copy link
Contributor

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.

Done


if args.use_recompute:
dist_strategy.recompute = True
Expand All @@ -341,12 +326,12 @@ def do_train(args):
if not os.path.isdir(program_desc_dir):
os.mkdir(program_desc_dir)

with open(program_desc_dir + "/main_program.txt.%d" %
(int(os.environ.get('FLAGS_selected_gpus', 0))), 'w') as f:
with open(program_desc_dir + "/main_program.txt.%d" % worker_index,
'w') as f:
f.write(str(main_program))

with open(program_desc_dir + "/startup_program.txt.%d" %
(int(os.environ.get('FLAGS_selected_gpus', 0))), 'w') as f:
with open(program_desc_dir + "/startup_program.txt.%d" % worker_index,
'w') as f:
f.write(str(startup_program))

# Define the Executor for running the static model
Expand Down
Loading