Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particlenet Ragged Batching Support (Post Rebase) #10

Open
wants to merge 5 commits into
base: TritonRaggedBatching125X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions RecoBTag/ONNXRuntime/plugins/ParticleNetSonicJetTagsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,39 +130,40 @@ void ParticleNetSonicJetTagsProducer::acquire(edm::Event const &iEvent, edm::Eve
edm::Handle<TagInfoCollection> tag_infos;
iEvent.getByToken(src_, tag_infos);
client_->setBatchSize(tag_infos->size());
skippedInference_ = false;
// skippedInference_ = false;
if (!tag_infos->empty()) {
unsigned int maxParticles = 0;
unsigned int maxVertices = 0;
for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) {
maxParticles = std::max(maxParticles,
static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get("pfcand_etarel").size()));
maxVertices =
std::max(maxVertices, static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get("sv_etarel").size()));
}
if (maxParticles == 0 && maxVertices == 0) {
client_->setBatchSize(0);
skippedInference_ = true;
return;
}
unsigned int minPartFromJSON = prep_info_map_.at(input_names_[0]).min_length;
unsigned int maxPartFromJSON = prep_info_map_.at(input_names_[0]).max_length;
unsigned int minVertFromJSON = prep_info_map_.at(input_names_[3]).min_length;
unsigned int maxVertFromJSON = prep_info_map_.at(input_names_[3]).max_length;
maxParticles = std::clamp(maxParticles, minPartFromJSON, maxPartFromJSON);
maxVertices = std::clamp(maxVertices, minVertFromJSON, maxVertFromJSON);
bool toSkipInference = true;

for (unsigned igroup = 0; igroup < input_names_.size(); ++igroup) {
const auto &group_name = input_names_[igroup];
auto &input = iInput.at(group_name);
unsigned target;
if (igroup < numParticleGroups_) {
input.setShape(1, maxParticles);
target = maxParticles;
} else {
input.setShape(1, maxVertices);
target = maxVertices;
for(unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n){
if (igroup == 0){
unsigned entry_target;
if (igroup < numParticleGroups_) {
entry_target = std::clamp(static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get("pfcand_etarel").size()), minPartFromJSON, maxPartFromJSON);
if (toSkipInference && ((*tag_infos)[jet_n]).features().get("pfcand_etarel").size() > 0) toSkipInference = false;
} else {
entry_target = std::clamp(static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get("sv_etarel").size()), minVertFromJSON, maxVertFromJSON);
if (toSkipInference && ((*tag_infos)[jet_n]).features().get("sv_etarel").size() > 0) toSkipInference = false;
}
input.setShape(1, entry_target, jet_n);
}
else{
input.setShape(1, static_cast<int64_t>(iInput.at(input_names_[igroup - 1]).shape(jet_n)[1]), jet_n);
}
}

if (toSkipInference){
client_->setBatchSize(0);
// skippedInference_ = true;
return;
}

auto tdata = input.allocate<float>(true);
for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) {
const auto &taginfo = (*tag_infos)[jet_n];
Expand All @@ -177,7 +178,7 @@ void ParticleNetSonicJetTagsProducer::acquire(edm::Event const &iEvent, edm::Eve
int insize = center_norm_pad_halfRagged(raw_value,
info.center,
info.norm_factor,
target,
static_cast<unsigned int>(input.shape(jet_n)[1]),
vdata,
curr_pos,
info.pad,
Expand All @@ -188,21 +189,23 @@ void ParticleNetSonicJetTagsProducer::acquire(edm::Event const &iEvent, edm::Eve
if (i == 0 && (!input_shapes_.empty())) {
input_shapes_[igroup][2] = insize;
}

if (debug_) {
LogDebug("acquire") << "<ParticleNetSonicJetTagsProducer::produce>:" << std::endl
<< " -- var=" << varname << ", center=" << info.center << ", scale=" << info.norm_factor
<< ", replace=" << info.replace_inf_value << ", pad=" << info.pad << std::endl;
LogDebug("accquire") << " -- var=" << varname << ", center=" << info.center << ", scale=" << info.norm_factor
<< ", replace=" << info.replace_inf_value << ", pad=" << info.pad << std::endl;
for (unsigned i = curr_pos - insize; i < curr_pos; i++) {
LogDebug("acquire") << vdata[i] << ",";
LogDebug("accquire") << vdata[i] << ",";
nirmalthomas2609 marked this conversation as resolved.
Show resolved Hide resolved
}
LogDebug("acquire") << std::endl;
LogDebug("accquire") << std::endl;
nirmalthomas2609 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
input.toServer(tdata);
}
}
else{
client_->setBatchSize(0);
// skippedInference_ = true;
}
}

void ParticleNetSonicJetTagsProducer::produce(edm::Event &iEvent,
Expand Down
4 changes: 2 additions & 2 deletions RecoBTag/ONNXRuntime/python/pfParticleNetAK4_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Client = cms.PSet(
timeout = cms.untracked.uint32(300),
mode = cms.string("Async"),
modelName = cms.string("particlenet_AK4"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_AK4/config.pbtxt"),
modelName = cms.string("particlenet_AK4_ragged"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_AK4_ragged/config.pbtxt"),
modelVersion = cms.string(""),
verbose = cms.untracked.bool(False),
allowedTries = cms.untracked.uint32(0),
Expand Down
12 changes: 6 additions & 6 deletions RecoBTag/ONNXRuntime/python/pfParticleNet_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Client = cms.PSet(
timeout = cms.untracked.uint32(300),
mode = cms.string("Async"),
modelName = cms.string("particlenet"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet/config.pbtxt"),
modelName = cms.string("particlenet_ragged"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_ragged/config.pbtxt"),
modelVersion = cms.string(""),
verbose = cms.untracked.bool(False),
allowedTries = cms.untracked.uint32(0),
Expand Down Expand Up @@ -59,9 +59,9 @@
preprocess_json = 'RecoBTag/Combined/data/ParticleNetAK8/MD-2prong/V01/preprocess.json',
Client = cms.PSet(
timeout = cms.untracked.uint32(300),
modelName = cms.string("particlenet_AK8_MD-2prong"),
modelName = cms.string("particlenet_AK8_MD-2prong_ragged"),
mode = cms.string("Async"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_AK8_MD-2prong/config.pbtxt"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_AK8_MD-2prong_ragged/config.pbtxt"),
modelVersion = cms.string(""),
verbose = cms.untracked.bool(False),
allowedTries = cms.untracked.uint32(0),
Expand Down Expand Up @@ -89,9 +89,9 @@
preprocess_json = 'RecoBTag/Combined/data/ParticleNetAK8/MassRegression/V01/preprocess.json',
Client = cms.PSet(
timeout = cms.untracked.uint32(300),
modelName = cms.string("particlenet_AK8_MassRegression"),
modelName = cms.string("particlenet_AK8_MassRegression_ragged"),
mode = cms.string("Async"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_AK8_MassRegression/config.pbtxt"),
modelConfigPath = cms.FileInPath("RecoBTag/Combined/data/models/particlenet_AK8_MassRegression_ragged/config.pbtxt"),
modelVersion = cms.string(""),
verbose = cms.untracked.bool(False),
allowedTries = cms.untracked.uint32(0),
Expand Down