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

[TIPC]Support @to_static train for base-transformer #3277

Merged
merged 3 commits into from
Sep 17, 2022
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
Prev Previous commit
Fix to_static args
  • Loading branch information
0x45f committed Sep 15, 2022
commit d465aaa7019830b2a31befaf0f5b7b183953b501
29 changes: 18 additions & 11 deletions examples/machine_translation/transformer/train.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import time

Expand Down Expand Up @@ -86,11 +100,6 @@ def parse_args():
type=str,
choices=['true', 'false', 'True', 'False'],
help="Whether to use amp to train Transformer. ")
parser.add_argument("--to_static",
default=None,
type=str,
choices=['true', 'false', 'True', 'False'],
help="Whether use to_static to train Transformer. ")
parser.add_argument(
"--amp_level",
default=None,
Expand All @@ -106,6 +115,9 @@ def parse_args():
help=
'The option of profiler, which should be in format \"key1=value1;key2=value2;key3=value3\".'
)
parser.add_argument("--to_static",
action="store_true",
help="Whether to_static to train Transformer. ")
args = parser.parse_args()
return args

Expand Down Expand Up @@ -388,12 +400,7 @@ def do_train(args):
args.unk_token = ARGS.unk_token
args.bos_token = ARGS.bos_token
args.eos_token = ARGS.eos_token
if ARGS.to_static:
ARGS.to_static = ARGS.to_static.lower()
if ARGS.to_static == "true":
args.to_static = True
else:
args.to_static = False
args.to_static = ARGS.to_static
pprint(args)

args.profiler_options = ARGS.profiler_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ norm_train:../examples/machine_translation/transformer/train.py --config ../exam
pact_train:null
fpgm_train:null
distill_train:null
to_static_train:--to_static=True
to_static_train:--to_static
null:null
##
===========================eval_params===========================
Expand Down
17 changes: 16 additions & 1 deletion tests/test_tipc/test_train_inference_python.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/bash

# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

source test_tipc/common_func.sh

FILENAME=$1
Expand Down Expand Up @@ -296,7 +311,7 @@ else
run_train=${distill_trainer}
run_export=${distill_export}
# In case of @to_static, we re-used norm_traier,
# but append "--to_static=True" for config
# but append "--to_static" for config
# to trigger "apply_to_static" logic in 'train.py'
elif [ ${trainer} = "${to_static_key}" ]; then
run_train="${norm_trainer} ${to_static_trainer}"
Expand Down