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

decrease event size by storing PFCandidates with half precision float… #29513

Merged
merged 3 commits into from
May 5, 2020
Merged
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
17 changes: 16 additions & 1 deletion HLTrigger/JetMET/plugins/HLTScoutingPFProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Description: Producer for ScoutingPFJets from reco::PFJet objects, ScoutingVerte

#include "DataFormats/Math/interface/deltaR.h"

#include "DataFormats/Math/interface/libminifloat.h"

class HLTScoutingPFProducer : public edm::global::EDProducer<> {
public:
explicit HLTScoutingPFProducer(const edm::ParameterSet &);
Expand All @@ -60,6 +62,7 @@ class HLTScoutingPFProducer : public edm::global::EDProducer<> {
const double pfJetEtaCut;
const double pfCandidatePtCut;
const double pfCandidateEtaCut;
const bool storeWithHalfPrecisionFloatingPoint;

const bool doJetTags;
const bool doCandidates;
Expand All @@ -81,6 +84,7 @@ HLTScoutingPFProducer::HLTScoutingPFProducer(const edm::ParameterSet &iConfig)
pfJetEtaCut(iConfig.getParameter<double>("pfJetEtaCut")),
pfCandidatePtCut(iConfig.getParameter<double>("pfCandidatePtCut")),
pfCandidateEtaCut(iConfig.getParameter<double>("pfCandidateEtaCut")),
storeWithHalfPrecisionFloatingPoint(iConfig.getParameter<bool>("storeWithHalfPrecisionFloatingPoint")),
doJetTags(iConfig.getParameter<bool>("doJetTags")),
doCandidates(iConfig.getParameter<bool>("doCandidates")),
doMet(iConfig.getParameter<bool>("doMet")) {
Expand Down Expand Up @@ -151,7 +155,17 @@ void HLTScoutingPFProducer::produce(edm::StreamID sid, edm::Event &iEvent, edm::
break;
++index_counter;
}
outPFCandidates->emplace_back(cand.pt(), cand.eta(), cand.phi(), cand.mass(), cand.pdgId(), vertex_index);

if (storeWithHalfPrecisionFloatingPoint) {
outPFCandidates->emplace_back(MiniFloatConverter::float16to32(MiniFloatConverter::float32to16(cand.pt())),
MiniFloatConverter::float16to32(MiniFloatConverter::float32to16(cand.eta())),
MiniFloatConverter::float16to32(MiniFloatConverter::float32to16(cand.phi())),
MiniFloatConverter::float16to32(MiniFloatConverter::float32to16(cand.mass())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no way to just truncate the precision, without converting to 16 bits and back to 32 bits ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course there is: it is called bfloat16 (instead of halffloat)
https://en.wikipedia.org/wiki/Bfloat16_floating-point_format

BUT it really has low precision

bfloat16 is what it is mostly used for AI.

On Intel machines (AVX2 and more) one could use intrinsics to perform the conversion to/from halffloat (worth only if contiguous as in a SOA)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm, no, that doesn't seem like a good candidate here.

I just meant to ask if there is way to do MiniFloatConverter::float16to32(MiniFloatConverter::float32to16(x)) in a single call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under the assumption that the first call did not over/underflow it is trivial yes
(well, one must properly round, not truncate. still pretty trivial).

but at this point I do not understand what is going on, I was thinking data were stored in hf16 (aka int16), not in truncated float32
(ok I missed "let the compression reduce the information being stored.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but at this point I do not understand what is going on, I was thinking data were stored in hf16 (aka int16), not in truncated float32

that was my assumption as well

on the other hand, storing the truncated precision back in a float32 has the advantage of not affecting the data format, and apparently the compression is still good enough to reduce the size by ~37%

cand.pdgId(),
vertex_index);
} else {
outPFCandidates->emplace_back(cand.pt(), cand.eta(), cand.phi(), cand.mass(), cand.pdgId(), vertex_index);
}
}
}
}
Expand Down Expand Up @@ -253,6 +267,7 @@ void HLTScoutingPFProducer::fillDescriptions(edm::ConfigurationDescriptions &des
desc.add<double>("pfJetEtaCut", 3.0);
desc.add<double>("pfCandidatePtCut", 0.6);
desc.add<double>("pfCandidateEtaCut", 5.0);
desc.add<bool>("storeWithHalfPrecisionFloatingPoint", false);
desc.add<bool>("doJetTags", true);
desc.add<bool>("doCandidates", true);
desc.add<bool>("doMet", true);
Expand Down