16std::vector<RClusterRange> MergeConsecutiveClusters(
const std::vector<RClusterRange> &clusters)
18 std::vector<RClusterRange> merged;
19 for (
const auto &cluster : clusters) {
20 if (!merged.empty() && merged.back().rdfIdx == cluster.rdfIdx && merged.back().end == cluster.start) {
21 merged.back().end = cluster.end;
22 merged.back().SetNumEntries(merged.back().GetNumEntries() + cluster.GetNumEntries());
24 merged.push_back(cluster);
34 std::vector<RColumnLayout> layout;
35 layout.reserve(
fCols.size());
37 std::size_t vecIdx = 0;
39 for (
const auto &col :
fCols) {
40 const bool isVector =
fRdfs[0].GetColumnType(col).find(
"RVec") != std::string::npos;
50 : fEngine(engine), fIsTraining(isTraining)
66 fEngine.DeActivateTrainingEpoch();
68 fEngine.DeActivateValidationEpoch();
72 const std::size_t batchesInMemory,
const std::vector<std::string> &cols,
73 const std::vector<std::size_t> &vecSizes,
const float vecPadding,
74 const float testSize,
bool shuffle,
bool dropRemainder,
const std::size_t setSeed,
75 bool loadEager, std::string sampleType,
float sampleRatio,
bool replacement)
194 std::string_view outputFormat)
198 throw std::runtime_error(
"RDataLoaderEngine::Save: this dataset is already being iterated elsewhere "
199 "(e.g. inside a training loop). Finish or stop that iteration before saving.");
208 sink->FillBatch(batch);
290 auto validationEmpty = [&] {
300 const std::size_t numTrainingClusters =
fClusterLoader->GetNumTrainingClusters();
316 if (validationEmpty()) {
331 std::vector<RClusterRange> trainClustersToLoad;
332 std::size_t accumulatedEntries = 0;
335 (!discovering || trainClustersToLoad.empty())) {
337 trainClustersToLoad.push_back(cluster);
338 accumulatedEntries += cluster.GetNumEntries();
350 std::size_t rowOffset = 0;
355 trainClustersToLoad = MergeConsecutiveClusters(trainClustersToLoad);
358 for (
auto &cluster : trainClustersToLoad) {
360 fClusterLoader->LoadTrainingClusterInto(stagingBuffer, cluster.rdfIdx, cluster.start, cluster.end);
364 cluster.SetNumEntries(loadedEntries);
366 rowOffset += cluster.GetNumEntries();
381 stagingBuffer.
GetRows(), isLastBuffer);
386 if (isLastBuffer && discovering) {
394 const std::size_t numValidationClusters =
fClusterLoader->GetNumValidationClusters();
417 std::vector<RClusterRange> valClustersToLoad;
418 std::size_t accumulatedEntries = 0;
421 valClustersToLoad.push_back(cluster);
422 accumulatedEntries += cluster.GetNumEntries();
431 std::size_t rowOffset = 0;
433 valClustersToLoad = MergeConsecutiveClusters(valClustersToLoad);
434 for (
const auto &cluster : valClustersToLoad) {
435 fClusterLoader->LoadValidationClusterInto(stagingBuffer, cluster.rdfIdx, cluster.start, cluster.end);
436 rowOffset += cluster.GetNumEntries();
442 stagingBuffer.
GetRows(), isLastBuffer);
493 if (!
fShuffle && (rows.empty() || rows.back() - rows.front() + 1 == rows.size())) {
494 const std::size_t beginRow = rows.empty() ? 0 : rows.front();
495 return {&
fDataset, {}, beginRow, beginRow + rows.size()};
499 std::vector<std::size_t> permutation = rows;
501 const std::size_t numRows = permutation.size();
502 return {&
fDataset, std::move(permutation), 0, numRows};
514 const std::size_t endRow =
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Building and loading the batches from loaded chunks in RChunkLoader.
std::size_t GetBatchSize()
void CreateBatches(const RFlat2DMatrix &chunkTensor, const std::vector< std::size_t > &permutation, std::size_t beginRow, std::size_t endRow, bool isLastBatch)
Creating the batches from a chunk and add them to the queue.
void MarkProducerDone()
Signal that the producer has finished pushing all batches for this epoch.
std::size_t GetNumBatchQueue()
In this class, the processes of loading clusters (see RClusterLoader) and creating batches from those...
std::size_t TrainRemainderRows()
std::vector< ROOT::RDF::RNode > fRdfs
std::unique_ptr< RFlat2DMatrixOperators > fTensorOperators
RFlat2DMatrix GetValidationBatch()
Loads a validation batch from the queue.
std::unique_ptr< RDatasetLoader > fDatasetLoader
std::unique_ptr< std::thread > fLoadingThread
void Activate()
Activate the loading process by spawning the loading thread.
void Save(std::string_view dataset_name, std::string_view filename, bool isTraining, std::string_view outputFormat)
Materialize one train/test split to disk by draining a full epoch through the normal batch pipeline a...
std::unique_ptr< RClusterLoader > fClusterLoader
std::size_t fLowWatermark
void ActivateValidationEpoch()
bool IsValidationActive()
bool fValidationEpochActive
std::size_t fNumTrainingEntries
RFlat2DMatrix fSampledTrainingDataset
std::size_t fValidationEpochCount
std::vector< RColumnLayout > MakeColumnLayout()
Describe how the loader's columns map onto a batch-tensor row.
std::vector< std::size_t > fVecSizes
std::size_t fTrainingEpochCount
std::size_t fTrainingClusterIdx
std::vector< std::vector< std::size_t > > fValidationRows
std::unique_ptr< RSampler > fValidationSampler
void LoadData()
Main loop for loading clusters and creating batches.
std::unique_ptr< RSampler > fTrainingSampler
std::size_t fNumValidationEntries
REagerEpoch fValidationEagerEpoch
REagerEpoch fTrainingEagerEpoch
std::size_t fBufferCapacity
RFlat2DMatrix fSampledValidationDataset
std::size_t fValidationClusterIdx
std::size_t NumberOfTrainingBatches()
std::vector< RColumnLayout > fColumnLayout
void ActivateTrainingEpoch()
Activate the training epoch by starting the batchloader.
std::size_t ValidationRemainderRows()
void CreateValidationBatches()
Creates validation batches by first loading a chunk (see RClusterLoader), and then split it into batc...
std::vector< std::string > fCols
RDataLoaderEngine(const std::vector< ROOT::RDF::RNode > &rdfs, const std::size_t batchSize, const std::size_t batchesInMemory, const std::vector< std::string > &cols, const std::vector< std::size_t > &vecSizes={}, const float vecPadding=0.0, const float testSize=0.0, bool shuffle=true, bool dropRemainder=true, const std::size_t setSeed=0, bool loadEager=false, std::string sampleType="", float sampleRatio=1.0, bool replacement=false)
void DeActivateValidationEpoch()
RFlat2DMatrix GetTrainBatch()
Loads a training batch from the queue.
void DeActivateTrainingEpoch()
std::vector< std::vector< std::size_t > > fTrainingRows
bool fTrainingEpochActive
REagerEpoch MakeEagerEpoch(const std::vector< std::size_t > &rows)
The eager epoch reading the given rows of the dataset, in shuffled order when shuffling.
std::size_t NumberOfValidationBatches()
void CreateNextEagerBatch(RBatchLoader &batchLoader, REagerEpoch &epoch)
Create the next batch of an eager epoch, unless one is already queued or the epoch is done.
std::condition_variable fLoadingCondition
void CreateTrainBatches()
Create training batches by first loading a chunk (see RClusterLoader) and split it into batches (see ...
std::unique_ptr< RBatchLoader > fTrainingBatchLoader
std::unique_ptr< RBatchLoader > fValidationBatchLoader
std::unique_ptr< RBatchSink > CreateBatchSink(std::string_view dataset_name, std::string_view filename, std::vector< RColumnLayout > layout, std::string_view format)
Create the sink matching format.
Rows of an eager epoch, turned into batches as they are requested.
const RFlat2DMatrix * fSource
std::vector< std::size_t > fPermutation
Opens a training or validation epoch and closes it again when done.
RDataLoaderEngine & fEngine
REpochGuard(RDataLoaderEngine &engine, bool isTraining)
Wrapper around ROOT::RVec<float> representing a 2D matrix.
void Resize(std::size_t rows, std::size_t cols)
std::size_t GetSize() const
std::size_t GetRows() const
void Reserve(std::size_t rows, std::size_t cols)