Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
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
248 changes: 0 additions & 248 deletions paddlenlp/ops/optimizer/AdamwOptimizer.py

This file was deleted.

Loading