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

Unified amp strategy in auto_trainner #9696

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions paddlenlp/trainer/auto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@
unified_strategy = dist.Strategy()
unified_strategy._from_legacy_strategy(self.args.strategy)

# same logic as autocast_smart_context_manager() in trainer.py
if self.enable_autocast_context_manager:
unified_strategy.amp.custom_black_list.extend(["reduce_sum", "c_softmax_with_cross_entropy"])
if self.args.fp16_opt_level == "O2":
unified_strategy.amp.custom_white_list.extend(["lookup_table", "lookup_table_v2"])
with self.autocast_smart_context_manager():
dygraph_tracer = paddle.paddle.base.framework._dygraph_tracer()
assert dygraph_tracer is not None, "dygraph_tracer is None, do you run in dynamic mode?"

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

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L147-L149

Added lines #L147 - L149 were not covered by tests

unified_strategy.amp.dtype = dygraph_tracer._amp_dtype
white_list, black_list = dygraph_tracer._get_amp_op_list()
unified_strategy.amp.custom_white_list += white_list
unified_strategy.amp.custom_black_list += black_list

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

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L151-L154

Added lines #L151 - L154 were not covered by tests

# dist.to_static() obtains the input spec information through next(dataloader), but this has side effects
# on the passed-in dataloader, altering the state of the sampler of the dataloader. In some cases, once
Expand Down