diff --git a/PhysicsTools/ONNXRuntime/interface/ONNXSessionOptions.h b/PhysicsTools/ONNXRuntime/interface/ONNXSessionOptions.h index 44c0c37720c4b..98d38e9630157 100644 --- a/PhysicsTools/ONNXRuntime/interface/ONNXSessionOptions.h +++ b/PhysicsTools/ONNXRuntime/interface/ONNXSessionOptions.h @@ -1,6 +1,5 @@ -#ifndef PHYSICSTOOLS_ONNXRUNTIME_ONNXSESSIONOPTIONS_H -#define PHYSICSTOOLS_ONNXRUNTIME_ONNXSESSIONOPTIONS_H - +#ifndef PHYSICSTOOLS_ONNXRUNTIME_ONNXSESSIONOPTIONS_H +#define PHYSICSTOOLS_ONNXRUNTIME_ONNXSESSIONOPTIONS_H #include "HeterogeneousCore/CUDAServices/interface/CUDAService.h" #include "FWCore/ServiceRegistry/interface/Service.h" @@ -15,20 +14,19 @@ namespace cms::Ort { // cuda -> Use cuda backend // default -> Use best available inline ::Ort::SessionOptions getSessionOptions(const std::string ¶m_backend) { - auto backend = cms::Ort::Backend::cpu; - if ( param_backend == "cuda" ) + if (param_backend == "cuda") backend = cms::Ort::Backend::cuda; - if ( param_backend == "default" ) { + if (param_backend == "default") { edm::Service cs; if (cs.isAvailable() and cs->enabled()) { - backend = cms::Ort::Backend::cuda; + backend = cms::Ort::Backend::cuda; } - } + } return ONNXRuntime::defaultSessionOptions(backend); } -} +} // namespace cms::Ort #endif diff --git a/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc b/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc index 352da96513a2d..60ddb44b6e436 100644 --- a/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc +++ b/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc @@ -16,7 +16,6 @@ #include #include - namespace cms::Ort { using namespace ::Ort; diff --git a/RecoBTag/ONNXRuntime/plugins/BoostedJetONNXJetTagsProducer.cc b/RecoBTag/ONNXRuntime/plugins/BoostedJetONNXJetTagsProducer.cc index 2a8e0a46d37b1..d51d2811be1a0 100644 --- a/RecoBTag/ONNXRuntime/plugins/BoostedJetONNXJetTagsProducer.cc +++ b/RecoBTag/ONNXRuntime/plugins/BoostedJetONNXJetTagsProducer.cc @@ -126,19 +126,20 @@ void BoostedJetONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescripti "probQCDothers", }); desc.addOptionalUntracked("debugMode", false); - desc.add("onnx_backend","default"); + desc.add("onnx_backend", "default"); descriptions.addWithDefaultLabel(desc); } std::unique_ptr BoostedJetONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet &iConfig) { - std::string backend= iConfig.getParameter("onnx_backend"); - + std::string backend = iConfig.getParameter("onnx_backend"); + auto session_options = cms::Ort::getSessionOptions(backend); // Sept 8, 2022 - on gpu, this model crashes with all optimizations on - if ( backend != "cpu" ) + if (backend != "cpu") session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_BASIC); - return std::make_unique(iConfig.getParameter("model_path").fullPath(),&session_options); + return std::make_unique(iConfig.getParameter("model_path").fullPath(), + &session_options); } void BoostedJetONNXJetTagsProducer::globalEndJob(const ONNXRuntime *cache) {} diff --git a/RecoBTag/ONNXRuntime/plugins/DeepCombinedONNXJetTagsProducer.cc b/RecoBTag/ONNXRuntime/plugins/DeepCombinedONNXJetTagsProducer.cc index ec463d1fa2bee..d1a43103702d1 100644 --- a/RecoBTag/ONNXRuntime/plugins/DeepCombinedONNXJetTagsProducer.cc +++ b/RecoBTag/ONNXRuntime/plugins/DeepCombinedONNXJetTagsProducer.cc @@ -136,14 +136,15 @@ void DeepCombinedONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescrip desc.add>("flav_names", std::vector{"probb", "probc", "probuds", "probg"}); desc.add("min_jet_pt", 15.0); desc.add("max_jet_eta", 2.5); - desc.add("onnx_backend","default"); + desc.add("onnx_backend", "default"); descriptions.add("pfDeepCombinedJetTags", desc); } std::unique_ptr DeepCombinedONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) { auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter("onnx_backend")); - return std::make_unique(iConfig.getParameter("model_path").fullPath(),&session_options); + return std::make_unique(iConfig.getParameter("model_path").fullPath(), + &session_options); } void DeepCombinedONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {} diff --git a/RecoBTag/ONNXRuntime/plugins/DeepDoubleXONNXJetTagsProducer.cc b/RecoBTag/ONNXRuntime/plugins/DeepDoubleXONNXJetTagsProducer.cc index 432c1d60c5247..c6360d4f59cab 100644 --- a/RecoBTag/ONNXRuntime/plugins/DeepDoubleXONNXJetTagsProducer.cc +++ b/RecoBTag/ONNXRuntime/plugins/DeepDoubleXONNXJetTagsProducer.cc @@ -121,7 +121,7 @@ void DeepDoubleXONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescript "CvB" >> (PDPSD("flav_names", std::vector{"probHbb", "probHcc"}, true) and PDFIP("model_path", FIP("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.onnx"), true)); }; - desc.add("onnx_backend","default"); + desc.add("onnx_backend", "default"); auto descBvL(desc); descBvL.ifValue(edm::ParameterDescription("flavor", "BvL", true), flavorCases()); @@ -138,7 +138,8 @@ void DeepDoubleXONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescript std::unique_ptr DeepDoubleXONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) { auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter("onnx_backend")); - return std::make_unique(iConfig.getParameter("model_path").fullPath(),&session_options); + return std::make_unique(iConfig.getParameter("model_path").fullPath(), + &session_options); } void DeepDoubleXONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {} diff --git a/RecoBTag/ONNXRuntime/plugins/DeepFlavourONNXJetTagsProducer.cc b/RecoBTag/ONNXRuntime/plugins/DeepFlavourONNXJetTagsProducer.cc index 4d2135f64beea..7fe7b96cb3007 100644 --- a/RecoBTag/ONNXRuntime/plugins/DeepFlavourONNXJetTagsProducer.cc +++ b/RecoBTag/ONNXRuntime/plugins/DeepFlavourONNXJetTagsProducer.cc @@ -85,14 +85,15 @@ void DeepFlavourONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescript desc.add>("output_names", {"ID_pred/Softmax:0"}); desc.add>( "flav_names", std::vector{"probb", "probbb", "problepb", "probc", "probuds", "probg"}); - desc.add("onnx_backend","default"); + desc.add("onnx_backend", "default"); descriptions.add("pfDeepFlavourJetTags", desc); } std::unique_ptr DeepFlavourONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) { auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter("onnx_backend")); - return std::make_unique(iConfig.getParameter("model_path").fullPath(), &session_options); + return std::make_unique(iConfig.getParameter("model_path").fullPath(), + &session_options); } void DeepFlavourONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {} diff --git a/RecoBTag/ONNXRuntime/plugins/DeepVertexONNXJetTagsProducer.cc b/RecoBTag/ONNXRuntime/plugins/DeepVertexONNXJetTagsProducer.cc index a7a146a978f21..60b975d33fbc9 100644 --- a/RecoBTag/ONNXRuntime/plugins/DeepVertexONNXJetTagsProducer.cc +++ b/RecoBTag/ONNXRuntime/plugins/DeepVertexONNXJetTagsProducer.cc @@ -112,14 +112,15 @@ void DeepVertexONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescripti desc.add>("flav_names", std::vector{"probb", "probc", "probuds", "probg"}); desc.add("min_jet_pt", 15.0); desc.add("max_jet_eta", 2.5); - desc.add("onnx_backend","default"); + desc.add("onnx_backend", "default"); descriptions.add("pfDeepVertexJetTags", desc); } std::unique_ptr DeepVertexONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) { auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter("onnx_backend")); - return std::make_unique(iConfig.getParameter("model_path").fullPath(), &session_options); + return std::make_unique(iConfig.getParameter("model_path").fullPath(), + &session_options); } void DeepVertexONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {} diff --git a/RecoParticleFlow/PFProducer/plugins/MLPFProducer.cc b/RecoParticleFlow/PFProducer/plugins/MLPFProducer.cc index 0916925e8e8e4..cc791e464d251 100644 --- a/RecoParticleFlow/PFProducer/plugins/MLPFProducer.cc +++ b/RecoParticleFlow/PFProducer/plugins/MLPFProducer.cc @@ -175,7 +175,7 @@ void MLPFProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions edm::FileInPath( "RecoParticleFlow/PFProducer/data/mlpf/" "mlpf_2021_11_16__no_einsum__all_data_cms-best-of-asha-scikit_20211026_042043_178263.workergpu010.onnx")); - desc.add("onnx_backend","default"); + desc.add("onnx_backend", "default"); descriptions.addWithDefaultLabel(desc); }