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 for npu #669

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions ppgan/utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def setup(args, cfg):

if paddle.is_compiled_with_cuda():
paddle.set_device('gpu')
elif paddle.is_compiled_with_npu():
paddle.set_device('npu')
else:
paddle.set_device('cpu')

Expand Down
15 changes: 15 additions & 0 deletions test_tipc/prepare_npu_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

BASEDIR=$(dirname "$0")

function readlinkf() {
perl -MCwd -e 'print Cwd::abs_path shift' "$1";
}

REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../)

config_files=$(find ${REPO_ROOT_PATH}/test_tipc/configs -name "train_infer_python.txt")
for file in ${config_files}; do
echo $file
sed -i 's/--device:gpu/--device:npu/g' $file
done
4 changes: 2 additions & 2 deletions test_tipc/test_train_inference_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ else
if [ ${#gpu} -le 2 ];then # train with cpu or single gpu
cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_amp_config} "
elif [ ${#ips} -le 26 ];then # train with multi-gpu
cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_amp_config}"
cmd="${python} -m paddle.distributed.launch --devices=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_amp_config}"
else # train with multi-machine
cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_amp_config}"
cmd="${python} -m paddle.distributed.launch --ips=${ips} --devices=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_amp_config}"
fi
# run train
eval "unset CUDA_VISIBLE_DEVICES"
Expand Down
6 changes: 4 additions & 2 deletions tools/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def parse_args():
"--device",
default="gpu",
type=str,
choices=["cpu", "gpu", "xpu"],
help="The device to select to train the model, is must be cpu/gpu/xpu.")
choices=["cpu", "gpu", "xpu", "npu"],
help="The device to select to train the model, is must be cpu/gpu/xpu/npu.")
parser.add_argument('-c',
'--config-file',
metavar="FILE",
Expand Down Expand Up @@ -117,6 +117,8 @@ def create_predictor(model_path,
config.disable_gpu()
elif device == "xpu":
config.enable_xpu(100)
elif device == "npu":
config.enable_npu()
else:
config.disable_gpu()

Expand Down