Skip to content

Commit

Permalink
code checks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlange6 committed Sep 15, 2022
1 parent 28bcc71 commit 9433eda
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
16 changes: 7 additions & 9 deletions PhysicsTools/ONNXRuntime/interface/ONNXSessionOptions.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -15,20 +14,19 @@ namespace cms::Ort {
// cuda -> Use cuda backend
// default -> Use best available
inline ::Ort::SessionOptions getSessionOptions(const std::string &param_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<CUDAService> 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
1 change: 0 additions & 1 deletion PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <memory>
#include <numeric>


namespace cms::Ort {

using namespace ::Ort;
Expand Down
11 changes: 6 additions & 5 deletions RecoBTag/ONNXRuntime/plugins/BoostedJetONNXJetTagsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,20 @@ void BoostedJetONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescripti
"probQCDothers",
});
desc.addOptionalUntracked<bool>("debugMode", false);
desc.add<std::string>("onnx_backend","default");
desc.add<std::string>("onnx_backend", "default");

descriptions.addWithDefaultLabel(desc);
}

std::unique_ptr<ONNXRuntime> BoostedJetONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet &iConfig) {
std::string backend= iConfig.getParameter<std::string>("onnx_backend");
std::string backend = iConfig.getParameter<std::string>("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<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),&session_options);
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),
&session_options);
}

void BoostedJetONNXJetTagsProducer::globalEndJob(const ONNXRuntime *cache) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ void DeepCombinedONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescrip
desc.add<std::vector<std::string>>("flav_names", std::vector<std::string>{"probb", "probc", "probuds", "probg"});
desc.add<double>("min_jet_pt", 15.0);
desc.add<double>("max_jet_eta", 2.5);
desc.add<std::string>("onnx_backend","default");
desc.add<std::string>("onnx_backend", "default");

descriptions.add("pfDeepCombinedJetTags", desc);
}

std::unique_ptr<ONNXRuntime> DeepCombinedONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) {
auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter<std::string>("onnx_backend"));
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),&session_options);
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),
&session_options);
}

void DeepCombinedONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void DeepDoubleXONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescript
"CvB" >> (PDPSD("flav_names", std::vector<std::string>{"probHbb", "probHcc"}, true) and
PDFIP("model_path", FIP("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.onnx"), true));
};
desc.add<std::string>("onnx_backend","default");
desc.add<std::string>("onnx_backend", "default");

auto descBvL(desc);
descBvL.ifValue(edm::ParameterDescription<std::string>("flavor", "BvL", true), flavorCases());
Expand All @@ -138,7 +138,8 @@ void DeepDoubleXONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescript

std::unique_ptr<ONNXRuntime> DeepDoubleXONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) {
auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter<std::string>("onnx_backend"));
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),&session_options);
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),
&session_options);
}

void DeepDoubleXONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ void DeepFlavourONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescript
desc.add<std::vector<std::string>>("output_names", {"ID_pred/Softmax:0"});
desc.add<std::vector<std::string>>(
"flav_names", std::vector<std::string>{"probb", "probbb", "problepb", "probc", "probuds", "probg"});
desc.add<std::string>("onnx_backend","default");
desc.add<std::string>("onnx_backend", "default");

descriptions.add("pfDeepFlavourJetTags", desc);
}

std::unique_ptr<ONNXRuntime> DeepFlavourONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) {
auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter<std::string>("onnx_backend"));
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(), &session_options);
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),
&session_options);
}

void DeepFlavourONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {}
Expand Down
5 changes: 3 additions & 2 deletions RecoBTag/ONNXRuntime/plugins/DeepVertexONNXJetTagsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ void DeepVertexONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescripti
desc.add<std::vector<std::string>>("flav_names", std::vector<std::string>{"probb", "probc", "probuds", "probg"});
desc.add<double>("min_jet_pt", 15.0);
desc.add<double>("max_jet_eta", 2.5);
desc.add<std::string>("onnx_backend","default");
desc.add<std::string>("onnx_backend", "default");

descriptions.add("pfDeepVertexJetTags", desc);
}

std::unique_ptr<ONNXRuntime> DeepVertexONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) {
auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter<std::string>("onnx_backend"));
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(), &session_options);
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),
&session_options);
}

void DeepVertexONNXJetTagsProducer::globalEndJob(const ONNXRuntime* cache) {}
Expand Down
2 changes: 1 addition & 1 deletion RecoParticleFlow/PFProducer/plugins/MLPFProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>("onnx_backend","default");
desc.add<std::string>("onnx_backend", "default");
descriptions.addWithDefaultLabel(desc);
}

Expand Down

0 comments on commit 9433eda

Please sign in to comment.