Skip to content
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
26 changes: 22 additions & 4 deletions ppdet/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
logger = setup_logger(__name__)

__all__ = [
'check_gpu', 'check_npu', 'check_xpu', 'check_mlu', 'check_gcu', 'check_iluvatar_gpu'
'check_gpu', 'check_metax_gpu', 'check_npu', 'check_xpu', 'check_mlu', 'check_gcu', 'check_iluvatar_gpu'
'check_version', 'check_config'
]

def check_iluvatar_gpu(use_iluvatar_gpu):
"""
Log error and exit when set use_iluvatar_gpu=true in paddlepaddle
cpu/gpu/xpu/npu version.
cpu/gpu/xpu/npu/metax_gpu version.
"""
err = "Config use_iluvatar_gpu cannot be set as true while you are " \
"using paddlepaddle cpu/gpu/xpu/npu/mlu version ! \nPlease try: \n" \
"using paddlepaddle cpu/gpu/xpu/npu/mlu/metax_gpu version ! \nPlease try: \n" \
"\t1. Install paddlepaddle-iluvatar-gpu to run model on Iluvatar_GPU \n" \
"\t2. Set use_iluvatar_gpu as false in config file to run " \
"model on CPU/GPU/XPU/NPU/MLU"
"model on CPU/GPU/XPU/NPU/MLU/METAX_GPU"

try:
if use_iluvatar_gpu and not 'iluvatar_gpu' in paddle.device.get_all_custom_device_type():
Expand Down Expand Up @@ -124,7 +124,25 @@ def check_gpu(use_gpu):
sys.exit(1)
except Exception as e:
pass

def check_metax_gpu(use_metax_gpu):
"""
Log error and exit when set use_gpu=true in paddlepaddle
cpu version.
"""
err = "Config use_gpu cannot be set as true while you are " \
"using paddlepaddle cpu version ! \nPlease try: \n" \
"\t1. Install paddlepaddle-gpu to run model on METAX_GPU \n" \
"\t2. Set use_gpu as false in config file to run " \
"model on CPU"

try:
if use_metax_gpu and not paddle.is_compiled_with_custom_device("metax_gpu"):
logger.error(err)
sys.exit(1)
except Exception as e:
pass

def check_gcu(use_gcu):
"""
Log error and exit when set use_gcu=true in paddlepaddle
Expand Down
10 changes: 8 additions & 2 deletions tools/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import paddle
from ppdet.core.workspace import create, load_config, merge_config
from ppdet.engine import Trainer, Trainer_ARSL
from ppdet.utils.check import check_gpu, check_npu, check_xpu, check_mlu, check_gcu, check_iluvatar_gpu, check_version, check_config
from ppdet.utils.check import check_gpu, check_metax_gpu, check_npu, check_xpu, check_mlu, check_gcu, check_iluvatar_gpu, check_version, check_config
from ppdet.utils.cli import ArgsParser, merge_args
from ppdet.slim import build_slim_model

Expand Down Expand Up @@ -241,7 +241,10 @@ def main():

if 'use_gpu' not in cfg:
cfg.use_gpu = False


if 'use_metax_gpu' not in cfg:
cfg.use__metax_gpu = False

# disable mlu in config by default
if 'use_mlu' not in cfg:
cfg.use_mlu = False
Expand All @@ -256,6 +259,8 @@ def main():

if cfg.use_gpu:
place = paddle.set_device('gpu')
elif cfg.use_metax_gpu:
place = paddle.set_device('metax_gpu')
elif cfg.use_npu:
place = paddle.set_device('npu')
elif cfg.use_xpu:
Expand All @@ -274,6 +279,7 @@ def main():

check_config(cfg)
check_gpu(cfg.use_gpu)
check_metax_gpu(cfg.use_metax_gpu)
check_npu(cfg.use_npu)
check_xpu(cfg.use_xpu)
check_mlu(cfg.use_mlu)
Expand Down
9 changes: 8 additions & 1 deletion tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def main():

if 'use_gpu' not in cfg:
cfg.use_gpu = False


# disable metax_gpu in config by default
if 'use_metax_gpu' not in cfg:
cfg.use_metax_gpu = False

# disable mlu in config by default
if 'use_mlu' not in cfg:
cfg.use_mlu = False
Expand All @@ -188,6 +192,8 @@ def main():

if cfg.use_gpu:
place = paddle.set_device('gpu')
elif cfg.use_metax_gpu:
place = paddle.set_device('metax_gpu')
elif cfg.use_npu:
place = paddle.set_device('npu')
elif cfg.use_xpu:
Expand All @@ -206,6 +212,7 @@ def main():
merge_config(FLAGS.opt)
check.check_config(cfg)
check.check_gpu(cfg.use_gpu)
check.check_metax_gpu(cfg.use_metax_gpu)
check.check_npu(cfg.use_npu)
check.check_xpu(cfg.use_xpu)
check.check_mlu(cfg.use_mlu)
Expand Down