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

support amp in pir dy2st mode. #8485

Merged
merged 1 commit into from
Aug 16, 2024
Merged
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
10 changes: 5 additions & 5 deletions paddlenlp/trainer/auto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@

def _wrap_amp_model(self, args, model):
logger.info("Using half precision")
if args.to_static:
return
self.enable_autocast_context_manager = True
self.do_grad_scaling = True if self.args.fp16 else False
self.amp_dtype = "float16" if self.args.fp16 else "bfloat16"
self.scaler = dist.shard_scaler(paddle.amp.GradScaler(init_loss_scaling=self.args.scale_loss))
if self.args.fp16_opt_level == "O2":
paddle.amp.decorate(
models=model,
Expand All @@ -144,6 +139,11 @@
master_grad=self.args.amp_master_grad,
excluded_layers=QuantizationLinear,
)
if args.to_static:
return
self.enable_autocast_context_manager = True
self.do_grad_scaling = True if self.args.fp16 else False
self.scaler = dist.shard_scaler(paddle.amp.GradScaler(init_loss_scaling=self.args.scale_loss))

Check warning on line 146 in paddlenlp/trainer/auto_trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L142-L146

Added lines #L142 - L146 were not covered by tests

def _get_item_from_loss(self, loss):
if isinstance(loss, paddle.Tensor):
Expand Down
Loading