From 87f7421463fa7aa975f260d4402be24c369e29fd Mon Sep 17 00:00:00 2001 From: Murad Alibekov Date: Tue, 21 Nov 2023 16:16:32 +0300 Subject: [PATCH] Pull request #153: [AI-9579] Fixes for pytorch cpp Merge in AT/dl-benchmark from malibekov/AI-9579/pytorch_cpp_fix to develop --- .../pytorch_launcher/src/pytorch_launcher.cpp | 6 +++++- src/inference/inference_pytorch_cpp.py | 6 ++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cpp_dl_benchmark/pytorch_launcher/src/pytorch_launcher.cpp b/src/cpp_dl_benchmark/pytorch_launcher/src/pytorch_launcher.cpp index 2c215963c..837685244 100644 --- a/src/cpp_dl_benchmark/pytorch_launcher/src/pytorch_launcher.cpp +++ b/src/cpp_dl_benchmark/pytorch_launcher/src/pytorch_launcher.cpp @@ -77,7 +77,11 @@ void PytorchLauncher::read(const std::string& model_file, const std::string& wei } torch::Device torch_device(device_type, 0); - module = torch::jit::load(model_file, torch_device); + try { + module = torch::jit::load(model_file, torch_device); + } catch (const c10::Error& e) { + throw std::runtime_error("Failed to read model " + model_file); + } module.eval(); } diff --git a/src/inference/inference_pytorch_cpp.py b/src/inference/inference_pytorch_cpp.py index 7963defcb..e7b349eb8 100644 --- a/src/inference/inference_pytorch_cpp.py +++ b/src/inference/inference_pytorch_cpp.py @@ -200,7 +200,7 @@ def create_dict_from_args_for_process(args): def prepare_images_for_benchmark(inputs, tmp_dir): if os.path.isdir(inputs[0]): - return inputs + return inputs[0] for path in inputs[0].split(','): shutil.copy2(path, tmp_dir) return tmp_dir @@ -241,9 +241,7 @@ def main(): io.prepare_input(compiled_model, args.input) log.info('Preparing images for benchmark in temporary directory') - prepare_images_for_benchmark(args.input, tmp_input.name) - - args.input = tmp_input.name + args.input = prepare_images_for_benchmark(args.input, tmp_input.name) log.info('Initializing PyTorch process') proc = PyTorchProcess()