From 867c88e7068baad8dccfeec94648c8fdb49d9639 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Wed, 17 Sep 2025 17:08:40 +0800 Subject: [PATCH 01/20] feat: experimental parallel compile graph --- mindspore-lite/src/common/common.h | 6 +++++ .../src/extendrt/session/delegate_session.cc | 25 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/mindspore-lite/src/common/common.h b/mindspore-lite/src/common/common.h index cd229acd..8d79bbdb 100644 --- a/mindspore-lite/src/common/common.h +++ b/mindspore-lite/src/common/common.h @@ -143,6 +143,12 @@ static const char *const kAclInitOptionParam = "acl_init_options"; static const char *const kAclBuildOptionParam = "acl_build_options"; static const char *const kSplitGraph = "SplitGraph"; +// experimental section +static const char *const kExperimentalSection = "experimental"; +static const char *const kCompileGraphParallel = "compile_graph_parallel"; +static const char *const kEnableValue = "on"; +static const char *const kDisableValue = "off"; + static const char *const kNameAttrWeightDir = "weight_dir"; static const char *const kOutputShapes = "outputs_shape"; diff --git a/mindspore-lite/src/extendrt/session/delegate_session.cc b/mindspore-lite/src/extendrt/session/delegate_session.cc index 579efa3a..eeff5049 100644 --- a/mindspore-lite/src/extendrt/session/delegate_session.cc +++ b/mindspore-lite/src/extendrt/session/delegate_session.cc @@ -50,9 +50,25 @@ Status GraphSinkSession::Init(const std::shared_ptr &context, const Con return kSuccess; } +bool CheckCompileGraphParallel(const std::string &option) { + if (option.empty() || option == lite::kDisableValue) { + return false; + } + if (option == lite::kEnableValue) { + return true; + } + MS_LOG(WARNING) << "compile_graph_parallel=off is default, please set " + "compile_graph_parallel=on to enable compile graph in parallel between different threads. got: " + << option << ", fallback to default."; + return false; +} + Status GraphSinkSession::CompileGraph(const void *model_data, size_t data_size, uint32_t *graph_id) { // This lock can be removed when LiteRT supports concurrent multithreading compilation. - std::lock_guard lock(g_build_graph_mutex); + std::unique_lock lock(g_build_graph_mutex); + if (CheckCompileGraphParallel(GetConfigOption(lite::kExperimentalSection, lite::kCompileGraphParallel))) { + lock.unlock(); + } auto ret = graph_executor_->CompileGraph(model_data, data_size, options_, graph_id); if (!ret) { MS_LOG(ERROR) << "GraphSinkSession::CompileGraph compile graph failed"; @@ -72,7 +88,7 @@ Status GraphSinkSession::CompileGraph(const void *model_data, size_t data_size, Status GraphSinkSession::CompileGraph(FuncGraphPtr graph, const void *data, size_t size, uint32_t *graph_id) { MS_LOG(INFO) << "GraphSinkSession::CompileGraph"; // This lock can be removed when LiteRT supports concurrent multithreading compilation. - std::lock_guard lock(g_build_graph_mutex); + std::unique_lock lock(g_build_graph_mutex); // kernel graph will be removed from GraphSinkSession, and this code will be moved to TensorRT plugin if (context_ && !context_->MutableDeviceInfo().empty()) { auto device_info = context_->MutableDeviceInfo()[0]; @@ -84,6 +100,11 @@ Status GraphSinkSession::CompileGraph(FuncGraphPtr graph, const void *data, size graph->set_attr(kIsAdapted, MakeValue(true)); } } + // Ensure always protect AscendGeExecutorPlugin. It's a singleton without lock. + // The following parts can be parallelized. + if (CheckCompileGraphParallel(GetConfigOption(lite::kExperimentalSection, lite::kCompileGraphParallel))) { + lock.unlock(); + } DelegateGraphInfo graph_info; // the funcgraph constructed by flowgraph has no inputs and outputs. auto status = InitGraphInputsOutputs(graph, &graph_info); -- Gitee From 970218a2641eeb1b203e763e3fbf0c64f77889a2 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 14:22:35 +0800 Subject: [PATCH 02/20] test compile graph parallel --- .../test/st/python/test_build_parallel.py | 91 +++++++++++++++++++ .../scripts/ascend/run_python_api_ascend.sh | 8 ++ 2 files changed, 99 insertions(+) create mode 100644 mindspore-lite/test/st/python/test_build_parallel.py diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py new file mode 100644 index 00000000..b4c9a38a --- /dev/null +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -0,0 +1,91 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +""" +Test lite python API. +""" +import sys +import os +import mindspore_lite as mslite +import numpy as np +import pytest +import time +from concurrent.futures import ThreadPoolExecutor, as_completed + + +class ScopeTimeRecord: + """ + time record + """ + + def __enter__(self): + self.start_time = time.time() + return self + + def __exit__(self, *args): + self.record_time = (time.time() - self.start_time) * 1000 + + +MODEL_BASE_PATH = "ms_models" + +PARALLEL_CONFIG_DICT = { + "experimental": {"compile_graph_parallel": "on"}, +} + + +def build_model(model_path, parallel_enable=True): + """ + build model + """ + context = mslite.Context() + context.target = ["ascend"] + model = mslite.Model() + model.build_from_file( + model_path, + mslite.ModelType.MINDIR, + context, + config_dict=PARALLEL_CONFIG_DICT if parallel_enable else None, + ) + + +@pytest.mark.parametrize( + "model_name", ["cbg_ai_gender_resnet34_mutiscal_v1_1012.onnx.mindir"] +) +def test_build_parallel(model_name, parallel=2): + """ + test build parallel + """ + + model_path = os.path.join(MODEL_BASE_PATH, model_name) + record_disable_parallel = ScopeTimeRecord() + pool = ThreadPoolExecutor(max_workers=parallel) + with record_disable_parallel: + tasks = [] + for _ in range(parallel): + tasks.append(pool.submit(build_model, model_path, False)) + + as_completed(tasks, timeout=300) + + record_enable_parallel = ScopeTimeRecord() + with record_enable_parallel: + tasks = [] + for _ in range(parallel): + tasks.append(pool.submit(build_model, model_path, True)) + as_completed(tasks, timeout=300) + + print(f"build time disable parallel: {record_disable_parallel.record_time} ms") + print(f"build time enable parallel: {record_enable_parallel.record_time} ms") + assert ( + record_enable_parallel.record_time < record_disable_parallel.record_time * 0.8 + ) diff --git a/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh index f97bc0cf..77bcd3e1 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh @@ -62,6 +62,14 @@ function RunAscendST() { exit ${RET} fi echo "Run test_check_ascend success" + + pytest ${base_path}/python/test_build_parallel.py -s + RET=$? + if [ ${RET} -ne 0 ]; then + echo "Failed to run test_build_parallel.py" + exit ${RET} + fi + echo "Run test_build_parallel success" # pytest ${base_path}/python/python_api/test_lite_llm_engine_api.py -s # RET=$? # if [ ${RET} -ne 0 ]; then -- Gitee From 765425436204d684a87dae324992d9864fd61f28 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 15:13:44 +0800 Subject: [PATCH 03/20] test --- .../test/st/python/test_build_parallel.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index b4c9a38a..1a027df5 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -21,7 +21,7 @@ import mindspore_lite as mslite import numpy as np import pytest import time -from concurrent.futures import ThreadPoolExecutor, as_completed +from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED class ScopeTimeRecord: @@ -71,18 +71,13 @@ def test_build_parallel(model_name, parallel=2): record_disable_parallel = ScopeTimeRecord() pool = ThreadPoolExecutor(max_workers=parallel) with record_disable_parallel: - tasks = [] - for _ in range(parallel): - tasks.append(pool.submit(build_model, model_path, False)) - - as_completed(tasks, timeout=300) + tasks = [pool.submit(build_model, model_path, True) for _ in range(parallel)] + wait(tasks, timeout=300) record_enable_parallel = ScopeTimeRecord() with record_enable_parallel: - tasks = [] - for _ in range(parallel): - tasks.append(pool.submit(build_model, model_path, True)) - as_completed(tasks, timeout=300) + tasks = [pool.submit(build_model, model_path, True) for _ in range(parallel)] + wait(tasks, timeout=300) print(f"build time disable parallel: {record_disable_parallel.record_time} ms") print(f"build time enable parallel: {record_enable_parallel.record_time} ms") -- Gitee From 11e8e3a4ced41d572a44059a67ba1e6e579a6040 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 15:21:11 +0800 Subject: [PATCH 04/20] format --- mindspore-lite/test/st/python/test_build_parallel.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index 1a027df5..e5d587f2 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -15,13 +15,11 @@ """ Test lite python API. """ -import sys import os -import mindspore_lite as mslite -import numpy as np -import pytest import time -from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED +from concurrent.futures import ThreadPoolExecutor, wait +import pytest +import mindspore_lite as mslite class ScopeTimeRecord: -- Gitee From e2d7343c61f252fe2e687038aabf968ad03b1d60 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 17:09:07 +0800 Subject: [PATCH 05/20] test --- .../test/st/python/test_build_parallel.py | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index e5d587f2..92aeebfd 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -17,7 +17,7 @@ Test lite python API. """ import os import time -from concurrent.futures import ThreadPoolExecutor, wait +from concurrent.futures import ThreadPoolExecutor, as_completed import pytest import mindspore_lite as mslite @@ -35,7 +35,7 @@ class ScopeTimeRecord: self.record_time = (time.time() - self.start_time) * 1000 -MODEL_BASE_PATH = "ms_models" +MODEL_BASE_PATH = "/home/workspace/mindspore_dataset/mslite/models/hiai" PARALLEL_CONFIG_DICT = { "experimental": {"compile_graph_parallel": "on"}, @@ -46,20 +46,23 @@ def build_model(model_path, parallel_enable=True): """ build model """ - context = mslite.Context() - context.target = ["ascend"] - model = mslite.Model() - model.build_from_file( - model_path, - mslite.ModelType.MINDIR, - context, - config_dict=PARALLEL_CONFIG_DICT if parallel_enable else None, - ) + try: + context = mslite.Context() + context.target = ["ascend"] + model = mslite.Model() + model.build_from_file( + model_path, + mslite.ModelType.MINDIR, + context, + config_dict=PARALLEL_CONFIG_DICT if parallel_enable else None, + ) + except Exception as e: + print(e) + return False + return True -@pytest.mark.parametrize( - "model_name", ["cbg_ai_gender_resnet34_mutiscal_v1_1012.onnx.mindir"] -) +@pytest.mark.parametrize("model_name", ["bert_mindir.mindir"]) def test_build_parallel(model_name, parallel=2): """ test build parallel @@ -69,13 +72,13 @@ def test_build_parallel(model_name, parallel=2): record_disable_parallel = ScopeTimeRecord() pool = ThreadPoolExecutor(max_workers=parallel) with record_disable_parallel: - tasks = [pool.submit(build_model, model_path, True) for _ in range(parallel)] - wait(tasks, timeout=300) + tasks = [pool.submit(build_model, model_path, False) for _ in range(parallel)] + assert all([task.result() for task in as_completed(tasks, timeout=300)]) record_enable_parallel = ScopeTimeRecord() with record_enable_parallel: tasks = [pool.submit(build_model, model_path, True) for _ in range(parallel)] - wait(tasks, timeout=300) + assert all([task.result() for task in as_completed(tasks, timeout=300)]) print(f"build time disable parallel: {record_disable_parallel.record_time} ms") print(f"build time enable parallel: {record_enable_parallel.record_time} ms") -- Gitee From fed8a08feb32f8a87225a242677fd7aee24a2d85 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 17:14:20 +0800 Subject: [PATCH 06/20] test --- mindspore-lite/test/st/python/test_build_parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index 92aeebfd..53cb5245 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -56,7 +56,7 @@ def build_model(model_path, parallel_enable=True): context, config_dict=PARALLEL_CONFIG_DICT if parallel_enable else None, ) - except Exception as e: + except (RuntimeError, TypeError) as e: print(e) return False return True -- Gitee From c82e49e8a57345d351eeae8b34f176fafdd72143 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 19:05:11 +0800 Subject: [PATCH 07/20] test --- .../test/st/python/test_build_parallel.py | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index 53cb5245..abdea63d 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -35,21 +35,18 @@ class ScopeTimeRecord: self.record_time = (time.time() - self.start_time) * 1000 -MODEL_BASE_PATH = "/home/workspace/mindspore_dataset/mslite/models/hiai" +MODEL_BASE_PATH = "ms_models" PARALLEL_CONFIG_DICT = { "experimental": {"compile_graph_parallel": "on"}, } -def build_model(model_path, parallel_enable=True): +def build_model(model_path, context, model, parallel_enable=True): """ build model """ try: - context = mslite.Context() - context.target = ["ascend"] - model = mslite.Model() model.build_from_file( model_path, mslite.ModelType.MINDIR, @@ -62,22 +59,38 @@ def build_model(model_path, parallel_enable=True): return True -@pytest.mark.parametrize("model_name", ["bert_mindir.mindir"]) +@pytest.mark.parametrize("model_name", ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"]) def test_build_parallel(model_name, parallel=2): """ test build parallel """ + def create_context_and_model(): + context = [mslite.Context() for _ in range(parallel)] + model = [mslite.Model() for _ in range(parallel)] + for i in range(parallel): + context[i].target = ["ascend"] + return context, model + model_path = os.path.join(MODEL_BASE_PATH, model_name) + + context, model = create_context_and_model() record_disable_parallel = ScopeTimeRecord() pool = ThreadPoolExecutor(max_workers=parallel) with record_disable_parallel: - tasks = [pool.submit(build_model, model_path, False) for _ in range(parallel)] + tasks = [ + pool.submit(build_model, model_path, context[i], model[i], False) + for i in range(parallel) + ] assert all([task.result() for task in as_completed(tasks, timeout=300)]) + context, model = create_context_and_model() record_enable_parallel = ScopeTimeRecord() with record_enable_parallel: - tasks = [pool.submit(build_model, model_path, True) for _ in range(parallel)] + tasks = [ + pool.submit(build_model, model_path, context[i], model[i], True) + for i in range(parallel) + ] assert all([task.result() for task in as_completed(tasks, timeout=300)]) print(f"build time disable parallel: {record_disable_parallel.record_time} ms") -- Gitee From 735b1842018a96af3f2ed5443515bfa28b871290 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 19:38:32 +0800 Subject: [PATCH 08/20] test --- .../test/st/python/test_build_parallel.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index abdea63d..1ce5011b 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -1,4 +1,4 @@ -# Copyright 2022 Huawei Technologies Co., Ltd +# Copyright 2025 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,11 +28,12 @@ class ScopeTimeRecord: """ def __enter__(self): - self.start_time = time.time() + self.start_time = time.perf_counter() return self def __exit__(self, *args): - self.record_time = (time.time() - self.start_time) * 1000 + self.finish_time = time.perf_counter() + self.record_time = (self.finish_time - self.start_time) * 1000 MODEL_BASE_PATH = "ms_models" @@ -59,8 +60,11 @@ def build_model(model_path, context, model, parallel_enable=True): return True -@pytest.mark.parametrize("model_name", ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"]) -def test_build_parallel(model_name, parallel=2): +@pytest.mark.parametrize( + "model_name", + ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"], +) +def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.6): """ test build parallel """ @@ -82,7 +86,7 @@ def test_build_parallel(model_name, parallel=2): pool.submit(build_model, model_path, context[i], model[i], False) for i in range(parallel) ] - assert all([task.result() for task in as_completed(tasks, timeout=300)]) + assert all([task.result() for task in as_completed(tasks, timeout=thread_pool_timeout)]) context, model = create_context_and_model() record_enable_parallel = ScopeTimeRecord() @@ -91,10 +95,8 @@ def test_build_parallel(model_name, parallel=2): pool.submit(build_model, model_path, context[i], model[i], True) for i in range(parallel) ] - assert all([task.result() for task in as_completed(tasks, timeout=300)]) + assert all([task.result() for task in as_completed(tasks, timeout=thread_pool_timeout)]) print(f"build time disable parallel: {record_disable_parallel.record_time} ms") print(f"build time enable parallel: {record_enable_parallel.record_time} ms") - assert ( - record_enable_parallel.record_time < record_disable_parallel.record_time * 0.8 - ) + assert record_enable_parallel.record_time < record_disable_parallel.record_time * time_threshold -- Gitee From 85d94fecf913ef9e0c12ce5bab38c03ac33781a1 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Thu, 9 Oct 2025 20:18:28 +0800 Subject: [PATCH 09/20] test --- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 9 +++++++++ .../test/st/scripts/ascend/run_python_api_ascend.sh | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index cc6becaa..9c84194c 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -210,6 +210,15 @@ else scp ${user_name}@${device_ip}:${benchmark_test_path}/run_benchmark_log.txt ${run_benchmark_log_file} || exit 1 scp ${user_name}@${device_ip}:${benchmark_test_path}/run_benchmark_result.txt ${run_benchmark_result_file} || exit 1 fi + +pytest "$(pwd)/python/test_build_parallel.py" -s +RET=$? +if [ ${RET} -ne 0 ]; then + echo "Failed to run test_build_parallel.py" + exit ${RET} +fi +echo "Run test_build_parallel success" + echo "Run in ${backend} ended" cat ${run_ascend_result_file} exit ${Run_ascend_status} diff --git a/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh index 77bcd3e1..f97bc0cf 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_python_api_ascend.sh @@ -62,14 +62,6 @@ function RunAscendST() { exit ${RET} fi echo "Run test_check_ascend success" - - pytest ${base_path}/python/test_build_parallel.py -s - RET=$? - if [ ${RET} -ne 0 ]; then - echo "Failed to run test_build_parallel.py" - exit ${RET} - fi - echo "Run test_build_parallel success" # pytest ${base_path}/python/python_api/test_lite_llm_engine_api.py -s # RET=$? # if [ ${RET} -ne 0 ]; then -- Gitee From 750c68d186b4d96a3b8ab021705c675cb5129eda Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 09:23:56 +0800 Subject: [PATCH 10/20] test --- .../test/st/python/test_build_parallel.py | 1 + mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index 1ce5011b..854d2efe 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -64,6 +64,7 @@ def build_model(model_path, context, model, parallel_enable=True): "model_name", ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"], ) +@pytest.mark.extendrt_build def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.6): """ test build parallel diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 9c84194c..f0a34f3e 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -211,12 +211,15 @@ else scp ${user_name}@${device_ip}:${benchmark_test_path}/run_benchmark_result.txt ${run_benchmark_result_file} || exit 1 fi -pytest "$(pwd)/python/test_build_parallel.py" -s -RET=$? -if [ ${RET} -ne 0 ]; then - echo "Failed to run test_build_parallel.py" - exit ${RET} +if [[ $backend == "arm_ascend310_cloud" ]];then + pytest "$(pwd)/python/test_build_parallel.py" -s + RET=$? + if [ ${RET} -ne 0 ]; then + echo "Failed to run test_build_parallel.py" + exit ${RET} + fi fi + echo "Run test_build_parallel success" echo "Run in ${backend} ended" -- Gitee From bf7334664c3bf0cc9c6a72bb8f86498c17c582cb Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 10:18:53 +0800 Subject: [PATCH 11/20] test --- mindspore-lite/test/st/python/test_build_parallel.py | 3 +-- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/test_build_parallel.py index 854d2efe..9b037ccf 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/test_build_parallel.py @@ -64,8 +64,7 @@ def build_model(model_path, context, model, parallel_enable=True): "model_name", ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"], ) -@pytest.mark.extendrt_build -def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.6): +def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.8): """ test build parallel """ diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index f0a34f3e..1564295c 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -212,6 +212,7 @@ else fi if [[ $backend == "arm_ascend310_cloud" ]];then + echo "${backend} run pytest at $(pwd)" pytest "$(pwd)/python/test_build_parallel.py" -s RET=$? if [ ${RET} -ne 0 ]; then -- Gitee From c14bdd4a6fec114e82ef04ebc8088cb7929aede4 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 11:47:52 +0800 Subject: [PATCH 12/20] test --- .../test/st/python/pytest/conftest.py | 27 +++++++++++++++++++ .../test/st/python/pytest/pytest.ini | 3 +++ .../{ => pytest}/test_build_parallel.py | 5 ++-- .../test/st/scripts/ascend/run_ascend.sh | 17 ++++++------ 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 mindspore-lite/test/st/python/pytest/conftest.py create mode 100644 mindspore-lite/test/st/python/pytest/pytest.ini rename mindspore-lite/test/st/python/{ => pytest}/test_build_parallel.py (92%) diff --git a/mindspore-lite/test/st/python/pytest/conftest.py b/mindspore-lite/test/st/python/pytest/conftest.py new file mode 100644 index 00000000..93fc0d9d --- /dev/null +++ b/mindspore-lite/test/st/python/pytest/conftest.py @@ -0,0 +1,27 @@ +def pytest_addoption(parser): + parser.addoption( + "--backend", + action="store", + nargs="+", + default=[], + help="testcase can run on targets backend. example: --backend arm_ascend310_cloud cpu", + ) + + +def pytest_collection_modifyitems(config, items): + backend_types = config.getoption("--backend") + if not backend_types: + return + + selected = [] + for item in items: + marker = item.get_closest_marker("backend") + if marker: + supported_backends = marker.args + if not supported_backends and ( + "all" in supported_backends + or any([backend in supported_backends for backend in backend_types]) + ): + selected.append(item) + + items[:] = selected diff --git a/mindspore-lite/test/st/python/pytest/pytest.ini b/mindspore-lite/test/st/python/pytest/pytest.ini new file mode 100644 index 00000000..5be41bbb --- /dev/null +++ b/mindspore-lite/test/st/python/pytest/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + backend(targets...): testcase can run on targets backend. example: @pytest.mark.backend("arm_ascend310_cloud", "cpu") diff --git a/mindspore-lite/test/st/python/test_build_parallel.py b/mindspore-lite/test/st/python/pytest/test_build_parallel.py similarity index 92% rename from mindspore-lite/test/st/python/test_build_parallel.py rename to mindspore-lite/test/st/python/pytest/test_build_parallel.py index 9b037ccf..bb08f485 100644 --- a/mindspore-lite/test/st/python/test_build_parallel.py +++ b/mindspore-lite/test/st/python/pytest/test_build_parallel.py @@ -64,6 +64,7 @@ def build_model(model_path, context, model, parallel_enable=True): "model_name", ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"], ) +@pytest.mark.backend("arm_ascend310_cloud") def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.8): """ test build parallel @@ -97,6 +98,6 @@ def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_th ] assert all([task.result() for task in as_completed(tasks, timeout=thread_pool_timeout)]) - print(f"build time disable parallel: {record_disable_parallel.record_time} ms") - print(f"build time enable parallel: {record_enable_parallel.record_time} ms") + print(f"build time disable compile_graph_parallel: {record_disable_parallel.record_time} ms") + print(f"build time enable compile_graph_parallel: {record_enable_parallel.record_time} ms") assert record_enable_parallel.record_time < record_disable_parallel.record_time * time_threshold diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 1564295c..8202f37d 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -211,17 +211,16 @@ else scp ${user_name}@${device_ip}:${benchmark_test_path}/run_benchmark_result.txt ${run_benchmark_result_file} || exit 1 fi -if [[ $backend == "arm_ascend310_cloud" ]];then - echo "${backend} run pytest at $(pwd)" - pytest "$(pwd)/python/test_build_parallel.py" -s - RET=$? - if [ ${RET} -ne 0 ]; then - echo "Failed to run test_build_parallel.py" - exit ${RET} - fi + +echo "${backend} run pytest at $(pwd)" +pytest "$(pwd)/python/pytest" -s -m ${backend} -c "$(pwd)/python/pytest.ini" --backend ${backend} +RET=$? +if [ ${RET} -ne 0 ]; then + echo "Failed to run pytest st" + exit ${RET} fi -echo "Run test_build_parallel success" +echo "Run pytest st success" echo "Run in ${backend} ended" cat ${run_ascend_result_file} -- Gitee From b30282d632371bd5152aa5faa281ed9eb6fad9f0 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 14:06:17 +0800 Subject: [PATCH 13/20] test --- mindspore-lite/test/st/python/pytest/conftest.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mindspore-lite/test/st/python/pytest/conftest.py b/mindspore-lite/test/st/python/pytest/conftest.py index 93fc0d9d..dc727ae4 100644 --- a/mindspore-lite/test/st/python/pytest/conftest.py +++ b/mindspore-lite/test/st/python/pytest/conftest.py @@ -18,9 +18,10 @@ def pytest_collection_modifyitems(config, items): marker = item.get_closest_marker("backend") if marker: supported_backends = marker.args - if not supported_backends and ( - "all" in supported_backends - or any([backend in supported_backends for backend in backend_types]) + if not supported_backends: + raise ValueError(f"item {item} marked with backend but no backend specified.") + if "all" in supported_backends or any( + [backend in supported_backends for backend in backend_types] ): selected.append(item) -- Gitee From db5416690bcae6477493afc9eb080750708abeac Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 14:10:27 +0800 Subject: [PATCH 14/20] test --- mindspore-lite/test/st/python/pytest/conftest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mindspore-lite/test/st/python/pytest/conftest.py b/mindspore-lite/test/st/python/pytest/conftest.py index dc727ae4..7861a5b1 100644 --- a/mindspore-lite/test/st/python/pytest/conftest.py +++ b/mindspore-lite/test/st/python/pytest/conftest.py @@ -20,9 +20,7 @@ def pytest_collection_modifyitems(config, items): supported_backends = marker.args if not supported_backends: raise ValueError(f"item {item} marked with backend but no backend specified.") - if "all" in supported_backends or any( - [backend in supported_backends for backend in backend_types] - ): + if "all" in supported_backends or any([backend in supported_backends for backend in backend_types]): selected.append(item) items[:] = selected -- Gitee From 40fa5b8be4a84ab24cf14177246e5ea53d559979 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 14:28:19 +0800 Subject: [PATCH 15/20] test --- .../test/st/python/pytest/conftest.py | 17 +++++++++++++++++ ...rallel.py => test_compile_graph_parallel.py} | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) rename mindspore-lite/test/st/python/pytest/{test_build_parallel.py => test_compile_graph_parallel.py} (96%) diff --git a/mindspore-lite/test/st/python/pytest/conftest.py b/mindspore-lite/test/st/python/pytest/conftest.py index 7861a5b1..fe66b863 100644 --- a/mindspore-lite/test/st/python/pytest/conftest.py +++ b/mindspore-lite/test/st/python/pytest/conftest.py @@ -1,3 +1,20 @@ +# Copyright 2025 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +""" +Pytest ST configuration +""" def pytest_addoption(parser): parser.addoption( "--backend", diff --git a/mindspore-lite/test/st/python/pytest/test_build_parallel.py b/mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py similarity index 96% rename from mindspore-lite/test/st/python/pytest/test_build_parallel.py rename to mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py index bb08f485..9c39a4f9 100644 --- a/mindspore-lite/test/st/python/pytest/test_build_parallel.py +++ b/mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py @@ -65,7 +65,7 @@ def build_model(model_path, context, model, parallel_enable=True): ["sar_resnet31_sequential-decoder_5e_st-sub_mj-sub_sa_real.onnx.mindir"], ) @pytest.mark.backend("arm_ascend310_cloud") -def test_build_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.8): +def test_compile_graph_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.8): """ test build parallel """ -- Gitee From 68a27a8587b4dd91408ce3e4a653daae64b95490 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 14:45:38 +0800 Subject: [PATCH 16/20] test --- mindspore-lite/test/st/python/pytest/conftest.py | 2 +- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mindspore-lite/test/st/python/pytest/conftest.py b/mindspore-lite/test/st/python/pytest/conftest.py index fe66b863..f12eaa51 100644 --- a/mindspore-lite/test/st/python/pytest/conftest.py +++ b/mindspore-lite/test/st/python/pytest/conftest.py @@ -21,7 +21,7 @@ def pytest_addoption(parser): action="store", nargs="+", default=[], - help="testcase can run on targets backend. example: --backend arm_ascend310_cloud cpu", + help="only test specified backend testcases. example: --backend arm_ascend310_cloud cpu", ) diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 8202f37d..831f6bf1 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -213,9 +213,9 @@ fi echo "${backend} run pytest at $(pwd)" -pytest "$(pwd)/python/pytest" -s -m ${backend} -c "$(pwd)/python/pytest.ini" --backend ${backend} +pytest "$(pwd)/python/pytest" -s -m ${backend} -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} RET=$? -if [ ${RET} -ne 0 ]; then +if [ ${RET} -ne 0 -a ${RET} -ne 5 ]; then # 5 means no test collected, ignore it echo "Failed to run pytest st" exit ${RET} fi -- Gitee From 851c17acd5f45d10ded5a906a12dd53c65ce2f42 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 14:48:26 +0800 Subject: [PATCH 17/20] test --- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 831f6bf1..5b864c14 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -215,7 +215,7 @@ fi echo "${backend} run pytest at $(pwd)" pytest "$(pwd)/python/pytest" -s -m ${backend} -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} RET=$? -if [ ${RET} -ne 0 -a ${RET} -ne 5 ]; then # 5 means no test collected, ignore it +if [ ${RET} -ne 0 ] && [ ${RET} -ne 5 ]; then # 5 means no test collected, ignore it echo "Failed to run pytest st" exit ${RET} fi -- Gitee From 6ff709d70e73426015adff59e6c8fdd3e2d18950 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 15:18:32 +0800 Subject: [PATCH 18/20] test --- mindspore-lite/test/st/python/pytest/conftest.py | 3 ++- mindspore-lite/test/st/python/pytest/pytest.ini | 2 +- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mindspore-lite/test/st/python/pytest/conftest.py b/mindspore-lite/test/st/python/pytest/conftest.py index f12eaa51..e053c46a 100644 --- a/mindspore-lite/test/st/python/pytest/conftest.py +++ b/mindspore-lite/test/st/python/pytest/conftest.py @@ -21,7 +21,8 @@ def pytest_addoption(parser): action="store", nargs="+", default=[], - help="only test specified backend testcases. example: --backend arm_ascend310_cloud cpu", + choices=("arm_ascend310_cloud", "arm_ascend310_ge_cloud"), + help="only test specified backend testcases. example: --backend arm_ascend310_cloud arm_ascend310_ge_cloud", ) diff --git a/mindspore-lite/test/st/python/pytest/pytest.ini b/mindspore-lite/test/st/python/pytest/pytest.ini index 5be41bbb..756c7f22 100644 --- a/mindspore-lite/test/st/python/pytest/pytest.ini +++ b/mindspore-lite/test/st/python/pytest/pytest.ini @@ -1,3 +1,3 @@ [pytest] markers = - backend(targets...): testcase can run on targets backend. example: @pytest.mark.backend("arm_ascend310_cloud", "cpu") + backend(targets...): testcase can run on targets backend. Example: @pytest.mark.backend("arm_ascend310_cloud", "arm_ascend310_ge_cloud") diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 5b864c14..2ea924f6 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -213,7 +213,7 @@ fi echo "${backend} run pytest at $(pwd)" -pytest "$(pwd)/python/pytest" -s -m ${backend} -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} +pytest "$(pwd)/python/pytest" -s -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} RET=$? if [ ${RET} -ne 0 ] && [ ${RET} -ne 5 ]; then # 5 means no test collected, ignore it echo "Failed to run pytest st" -- Gitee From f5c44f30c1bc9bb35f21352e1f258f70ce4c8c9f Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 15:45:41 +0800 Subject: [PATCH 19/20] test --- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 2ea924f6..444d562a 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -213,7 +213,8 @@ fi echo "${backend} run pytest at $(pwd)" -pytest "$(pwd)/python/pytest" -s -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} +ls -l "$(pwd)/python/pytest" +pytest "$(pwd)/python/pytest" -s -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} --collect-only -v RET=$? if [ ${RET} -ne 0 ] && [ ${RET} -ne 5 ]; then # 5 means no test collected, ignore it echo "Failed to run pytest st" -- Gitee From ae9c763186c22677c6e53a7d6ce40762da8a7105 Mon Sep 17 00:00:00 2001 From: yiguangzheng Date: Fri, 10 Oct 2025 15:56:30 +0800 Subject: [PATCH 20/20] test --- .../test/st/python/pytest/test_compile_graph_parallel.py | 2 +- mindspore-lite/test/st/scripts/ascend/run_ascend.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py b/mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py index 9c39a4f9..9ab16d21 100644 --- a/mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py +++ b/mindspore-lite/test/st/python/pytest/test_compile_graph_parallel.py @@ -67,7 +67,7 @@ def build_model(model_path, context, model, parallel_enable=True): @pytest.mark.backend("arm_ascend310_cloud") def test_compile_graph_parallel(model_name, parallel=2, thread_pool_timeout=300, time_threshold=0.8): """ - test build parallel + test config compile_graph_parallel """ def create_context_and_model(): diff --git a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh index 444d562a..fd047797 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_ascend.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_ascend.sh @@ -214,7 +214,8 @@ fi echo "${backend} run pytest at $(pwd)" ls -l "$(pwd)/python/pytest" -pytest "$(pwd)/python/pytest" -s -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} --collect-only -v +cat "$(pwd)/python/pytest/pytest.ini" +pytest "$(pwd)/python/pytest" -s -c "$(pwd)/python/pytest/pytest.ini" --backend ${backend} -v RET=$? if [ ${RET} -ne 0 ] && [ ${RET} -ne 5 ]; then # 5 means no test collected, ignore it echo "Failed to run pytest st" -- Gitee