-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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] Add scripts for npu and xpu, test=develop #3377
Changes from all commits
260c2a2
40138aa
e076e13
ea95055
5715e20
05b9d37
cf66a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 yaml | ||
import logging | ||
|
@@ -60,6 +74,11 @@ def parse_args(): | |
type=str, | ||
help="The eos token. It should be provided when use custom vocab_file. " | ||
) | ||
parser.add_argument("--device", | ||
default="gpu", | ||
choices=["gpu", "cpu", "xpu", "npu"], | ||
help="Device selected for inference.") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add arguement "--device" to enable npu/xpu |
||
args = parser.parse_args() | ||
return args | ||
|
||
|
@@ -83,6 +102,10 @@ def post_process_seq(seq, bos_idx, eos_idx, output_bos=False, output_eos=False): | |
def do_predict(args): | ||
if args.device == "gpu": | ||
place = "gpu" | ||
elif args.device == "xpu": | ||
place = "xpu" | ||
elif args.device == "npu": | ||
place = "npu" | ||
else: | ||
place = "cpu" | ||
|
||
|
@@ -157,6 +180,7 @@ def do_predict(args): | |
args.unk_token = ARGS.unk_token | ||
args.bos_token = ARGS.bos_token | ||
args.eos_token = ARGS.eos_token | ||
args.device = ARGS.device | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. transform ARGS.device to args.device |
||
pprint(args) | ||
|
||
do_predict(args) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/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 | ||
|
||
function readlinkf() { | ||
perl -MCwd -e 'print Cwd::abs_path shift' "$1"; | ||
} | ||
|
||
function func_parser_config() { | ||
strs=$1 | ||
IFS=" " | ||
array=(${strs}) | ||
tmp=${array[2]} | ||
echo ${tmp} | ||
} | ||
|
||
BASEDIR=$(dirname "$0") | ||
REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../) | ||
|
||
FILENAME=$1 | ||
|
||
# change gpu to npu in tipc txt configs | ||
sed -i "s/--device:gpu/--device:npu/g" $FILENAME | ||
sed -i "s/state=GPU/state=NPU/g" $FILENAME | ||
sed -i "s/trainer:pact_train/trainer:norm_train/g" $FILENAME | ||
sed -i "s/trainer:fpgm_train/trainer:norm_train/g" $FILENAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change "pact_train" or "fpgm_train" to "norm_train" |
||
sed -i "s/--device:cpu|gpu/--device:cpu|npu/g" $FILENAME | ||
sed -i "s/--device:gpu|cpu/--device:cpu|npu/g" $FILENAME | ||
sed -i "s/--benchmark:True/--benchmark:False/g" $FILENAME | ||
sed -i "s/--use_tensorrt:False|True/--use_tensorrt:False/g" $FILENAME | ||
sed -i 's/\"gpu\"/\"npu\"/g' test_tipc/test_train_inference_python.sh | ||
|
||
# parser params | ||
dataline=`cat $FILENAME` | ||
IFS=$'\n' | ||
lines=(${dataline}) | ||
|
||
# pass parameters to test_train_inference_python.sh | ||
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $2" | ||
echo $cmd | ||
eval $cmd | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/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 | ||
|
||
function readlinkf() { | ||
perl -MCwd -e 'print Cwd::abs_path shift' "$1"; | ||
} | ||
|
||
function func_parser_config() { | ||
strs=$1 | ||
IFS=" " | ||
array=(${strs}) | ||
tmp=${array[2]} | ||
echo ${tmp} | ||
} | ||
|
||
BASEDIR=$(dirname "$0") | ||
REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../) | ||
|
||
FILENAME=$1 | ||
|
||
# change gpu to npu in tipc txt configs | ||
sed -i "s/--device:gpu/--device:xpu/g" $FILENAME | ||
sed -i "s/state=GPU/state=XPU/g" $FILENAME | ||
sed -i "s/trainer:pact_train/trainer:norm_train/g" $FILENAME | ||
sed -i "s/trainer:fpgm_train/trainer:norm_train/g" $FILENAME | ||
sed -i "s/--device:cpu|gpu/--device:cpu|xpu/g" $FILENAME | ||
sed -i "s/--device:gpu|cpu/--device:cpu|xpu/g" $FILENAME | ||
sed -i "s/--benchmark:True/--benchmark:False/g" $FILENAME | ||
sed -i "s/--use_tensorrt:False|True/--use_tensorrt:False/g" $FILENAME | ||
sed -i 's/\"gpu\"/\"npu\"/g' test_tipc/test_train_inference_python.sh | ||
|
||
# parser params | ||
dataline=`cat $FILENAME` | ||
IFS=$'\n' | ||
lines=(${dataline}) | ||
|
||
# pass parameters to test_train_inference_python.sh | ||
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $2" | ||
echo $cmd | ||
eval $cmd | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add npu device