add the pynative test case for dcn and yolov5 on gpu

This commit is contained in:
hanhuifeng2020 2022-12-10 17:57:06 +08:00
parent bf3d750647
commit 376f438615
3 changed files with 29 additions and 9 deletions

View File

@ -209,12 +209,11 @@ def get_train_loss(numeric_columns, sparse_columns, data_list, mode):
loss_callback = LossCallback()
model = Model(train_net)
sink_step = dataset.get_dataset_size()
model.train(sink_step, dataset, callbacks=loss_callback, sink_size=1)
model.train(sink_step, dataset, callbacks=loss_callback, sink_size=1, dataset_sink_mode=True)
loss_list = loss_callback.loss_list
return loss_list
@pytest.mark.skip(reason="Do not support yet.")
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
@ -230,8 +229,8 @@ def test_train():
SparseFeature = namedtuple("SparseFeature", ['name', 'voc_size', 'embed_size'])
sparse_columns = [SparseFeature('a', 7, 6), SparseFeature('b', 136, 18), SparseFeature('c', 3, 6)]
data_list = gen_data(numeric_columns, sparse_columns, batch_size_list)
# For graph mode
# GRAPH_MODE is temporarily not supported due to some new features that are not completely complete
set_seed(0)
graph_loss = get_train_loss(numeric_columns, sparse_columns, data_list, context.GRAPH_MODE)
graph_loss = get_train_loss(numeric_columns, sparse_columns, data_list, context.PYNATIVE_MODE)
expect_loss = [6.687461, 2928.5852, 8715.267]
assert np.allclose(graph_loss, expect_loss, 1e-3, 1e-3)

View File

@ -46,7 +46,11 @@ def train_preprocess():
if config.lr_scheduler == 'cosine_annealing' and config.max_epoch > config.T_max:
config.T_max = config.max_epoch
ms.set_context(mode=ms.GRAPH_MODE, device_target=config.device_target)
ms.set_context(device_target=config.device_target)
if config.mode_name == "GRAPH":
ms.set_context(mode=ms.GRAPH_MODE)
else:
ms.set_context(mode=ms.PYNATIVE_MODE)
if config.is_distributed:
# init distributed
@ -106,7 +110,7 @@ def run_train():
loss_callback = LossMonitor(1)
model = Model(network)
sink_step = dataset.get_dataset_size()
model.train(sink_step, dataset, callbacks=loss_callback, sink_size=1)
model.train(sink_step, dataset, callbacks=loss_callback, sink_size=1, dataset_sink_mode=True)
if __name__ == "__main__":

View File

@ -20,7 +20,7 @@ from mindspore import log as logger
from tests.st.model_zoo_tests import utils
def run_yolov5_dynamic_case(device_target):
def run_yolov5_dynamic_case(device_target, mode="GRAPH"):
cur_path = os.getcwd()
model_path = "{}/../../../../tests/models/official/cv".format(cur_path)
model_name = "yolov5"
@ -31,9 +31,10 @@ def run_yolov5_dynamic_case(device_target):
# pylint: disable=anomalous-backslash-in-string
new_list = ["-1"]
utils.exec_sed_command(old_list, new_list, os.path.join(cur_model_path, "src/yolo.py"))
os.system("""sed -i '1i\mode_name: "GRAPH"' {}""".format(os.path.join(cur_model_path, "default_config.yaml")))
os.system("cp -r {} {}".format(os.path.join(cur_path, "run_yolov5_dynamic.py"), cur_model_path))
exec_network_shell = "cd {}; python run_yolov5_dynamic.py --device_target={} > log &".format(
cur_model_path, device_target)
exec_network_shell = "cd {}; python run_yolov5_dynamic.py --device_target={} --mode_name={} > log &".format(
cur_model_path, device_target, mode)
logger.warning("cmd [{}] is running...".format(exec_network_shell))
os.system(exec_network_shell)
cmd = "ps -ef | grep python | grep run_yolov5_dynamic.py | grep -v grep"
@ -49,6 +50,22 @@ def run_yolov5_dynamic_case(device_target):
return loss_list
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_yolov5_dynamic_gpu_pynative():
"""
Feature: yolov5_dynamic
Description: test yolov5_dynamic run
Expectation: loss is same with the expect on PYNATIVE_MODE
"""
loss_list = run_yolov5_dynamic_case("GPU", "PYNATIVE")
expect_loss = [7200.505, 544.873, 600.88]
# Different gpu device (such as V100 and 3090) lead to some differences
# in the calculation results, so atol and rtol is large
assert np.allclose(loss_list, expect_loss, 1e-2, 1e-2)
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard