DiSMEC++
dismec::TrainingTaskGenerator Class Reference

Generates tasks for training weights for the i'th label. More...

#include <training.h>

Inheritance diagram for dismec::TrainingTaskGenerator:
dismec::parallel::TaskGenerator

Public Member Functions

 TrainingTaskGenerator (std::shared_ptr< TrainingSpec > spec, label_id_t begin_label=label_id_t{0}, label_id_t end_label=label_id_t{-1})
 
 ~TrainingTaskGenerator () override
 
void run_tasks (long begin, long end, thread_id_t thread_id) override
 
void prepare (long num_threads, long chunk_size) override
 Called to notify the TaskGenerator about the number of threads. More...
 
void init_thread (thread_id_t thread_id) override
 Called once a thread has spun up, but before it runs its first task. More...
 
void finalize () override
 Called after all threads have finished their tasks. More...
 
long num_tasks () const override
 
const std::shared_ptr< model::Model > & get_model () const
 
const std::vector< solvers::MinimizationResult > & get_results () const
 
- Public Member Functions inherited from dismec::parallel::TaskGenerator
virtual ~TaskGenerator ()=default
 

Private Member Functions

void run_task (long task_id, thread_id_t thread_id)
 
solvers::MinimizationResult train_label (label_id_t label_id, thread_id_t thread_id)
 Runs the training of a single label. More...
 

Private Attributes

std::shared_ptr< TrainingSpecm_TaskSpec
 
label_id_t m_LabelRangeBegin
 
label_id_t m_LabelRangeEnd
 
std::shared_ptr< model::Modelm_Model
 
std::vector< solvers::MinimizationResultm_Results
 
std::vector< DenseRealVectorm_ThreadLocalWorkingVector
 
std::vector< std::unique_ptr< solvers::Minimizer > > m_ThreadLocalMinimizer
 
std::vector< std::shared_ptr< objective::Objective > > m_ThreadLocalObjective
 
std::vector< std::unique_ptr< init::WeightsInitializer > > m_ThreadLocalWeightInit
 
std::vector< std::unique_ptr< postproc::PostProcessor > > m_ThreadLocalPostProc
 
std::vector< std::unique_ptr< ResultStatsGatherer > > m_ResultGatherers
 

Additional Inherited Members

- Public Types inherited from dismec::parallel::TaskGenerator
using thread_id_t = dismec::parallel::thread_id_t
 

Detailed Description

Generates tasks for training weights for the i'th label.

This task generator produces tasks which train the weights for the different labels. The tasks are generated as specified by a TrainingSpec: Each thread generates a minimizer, an objective, and an initializer. The objective and optimizer are updated for each new label using the corresponding functions of the TrainingSpec object.

Definition at line 26 of file training.h.

Constructor & Destructor Documentation

◆ TrainingTaskGenerator()

TrainingTaskGenerator::TrainingTaskGenerator ( std::shared_ptr< TrainingSpec spec,
label_id_t  begin_label = label_id_t{0},
label_id_t  end_label = label_id_t{-1} 
)
explicit

Definition at line 20 of file training.cpp.

References m_LabelRangeBegin, m_LabelRangeEnd, m_Model, m_Results, and m_TaskSpec.

◆ ~TrainingTaskGenerator()

TrainingTaskGenerator::~TrainingTaskGenerator ( )
overridedefault

Member Function Documentation

◆ finalize()

void TrainingTaskGenerator::finalize ( )
overridevirtual

Called after all threads have finished their tasks.

This function is called from the main thread after all worker threads have finished their work. It can be used to perform single threaded reductions or clean up per-thread buffers.

Reimplemented from dismec::parallel::TaskGenerator.

Definition at line 108 of file training.cpp.

References m_TaskSpec, m_ThreadLocalMinimizer, m_ThreadLocalObjective, m_ThreadLocalPostProc, m_ThreadLocalWeightInit, and m_ThreadLocalWorkingVector.

◆ get_model()

const std::shared_ptr<model::Model>& dismec::TrainingTaskGenerator::get_model ( ) const
inline

Definition at line 38 of file training.h.

References m_Model.

◆ get_results()

const std::vector<solvers::MinimizationResult>& dismec::TrainingTaskGenerator::get_results ( ) const
inline

Definition at line 39 of file training.h.

References m_Results.

◆ init_thread()

void TrainingTaskGenerator::init_thread ( thread_id_t  thread_id)
overridevirtual

Called once a thread has spun up, but before it runs its first task.

This function is called from inside the thread that also will run the tasks.

Reimplemented from dismec::parallel::TaskGenerator.

Definition at line 93 of file training.cpp.

References m_ResultGatherers, m_TaskSpec, m_ThreadLocalMinimizer, m_ThreadLocalObjective, m_ThreadLocalPostProc, m_ThreadLocalWeightInit, m_ThreadLocalWorkingVector, and dismec::opaque_int_type< Tag, T >::to_index().

◆ num_tasks()

long TrainingTaskGenerator::num_tasks ( ) const
overridevirtual

Implements dismec::parallel::TaskGenerator.

Definition at line 118 of file training.cpp.

References m_Results.

◆ prepare()

void TrainingTaskGenerator::prepare ( long  num_threads,
long  chunk_size 
)
overridevirtual

Called to notify the TaskGenerator about the number of threads.

This function is called from the main thread, before distributed work is started. It gives the TaskGenerator a chance to allocate working memory for each thread, so these allocations don't need to be done and repeated in run_task().

Note
For memory that is used inside the computations done by each thread, the init_thread() should be used. This will be called from inside the thread that will do the actual computations, so that when using this on a NUMA system, first-touch policy has a chance to place the allocation in the correct RAM. In that case, this function should only allocate an array of pointers that will be filled in by init_thread().
Parameters
num_threadsNumber of threads that will be used.
chunk_sizeA hint for the size of chunks used when running this task. Note that if the total number of tasks is not a multiple of the chunk_size, there may be some calls to run_tasks() with less than chunk_size tasks.

Reimplemented from dismec::parallel::TaskGenerator.

Definition at line 84 of file training.cpp.

References m_ResultGatherers, m_ThreadLocalMinimizer, m_ThreadLocalObjective, m_ThreadLocalPostProc, m_ThreadLocalWeightInit, and m_ThreadLocalWorkingVector.

◆ run_task()

void TrainingTaskGenerator::run_task ( long  task_id,
thread_id_t  thread_id 
)
private

◆ run_tasks()

void TrainingTaskGenerator::run_tasks ( long  begin,
long  end,
thread_id_t  thread_id 
)
overridevirtual

Implements dismec::parallel::TaskGenerator.

Definition at line 37 of file training.cpp.

References run_task().

◆ train_label()

solvers::MinimizationResult TrainingTaskGenerator::train_label ( label_id_t  label_id,
thread_id_t  thread_id 
)
private

Runs the training of a single label.

Parameters
label_idThe id of the label which will be trained.
thread_idThe id of the thread on which training is running.
Returns
The return value of the minimizer.

Definition at line 50 of file training.cpp.

References m_Model, m_ResultGatherers, m_TaskSpec, m_ThreadLocalMinimizer, m_ThreadLocalObjective, m_ThreadLocalPostProc, m_ThreadLocalWeightInit, m_ThreadLocalWorkingVector, dismec::solvers::SUCCESS, and dismec::opaque_int_type< Tag, T >::to_index().

Referenced by run_task().

Member Data Documentation

◆ m_LabelRangeBegin

label_id_t dismec::TrainingTaskGenerator::m_LabelRangeBegin
private

Definition at line 56 of file training.h.

Referenced by run_task(), and TrainingTaskGenerator().

◆ m_LabelRangeEnd

label_id_t dismec::TrainingTaskGenerator::m_LabelRangeEnd
private

Definition at line 57 of file training.h.

Referenced by TrainingTaskGenerator().

◆ m_Model

std::shared_ptr<model::Model> dismec::TrainingTaskGenerator::m_Model
private

Definition at line 60 of file training.h.

Referenced by get_model(), train_label(), and TrainingTaskGenerator().

◆ m_ResultGatherers

std::vector<std::unique_ptr<ResultStatsGatherer> > dismec::TrainingTaskGenerator::m_ResultGatherers
private

Definition at line 69 of file training.h.

Referenced by init_thread(), prepare(), and train_label().

◆ m_Results

std::vector<solvers::MinimizationResult> dismec::TrainingTaskGenerator::m_Results
private

Definition at line 61 of file training.h.

Referenced by get_results(), num_tasks(), run_task(), and TrainingTaskGenerator().

◆ m_TaskSpec

std::shared_ptr<TrainingSpec> dismec::TrainingTaskGenerator::m_TaskSpec
private

Definition at line 53 of file training.h.

Referenced by finalize(), init_thread(), run_task(), train_label(), and TrainingTaskGenerator().

◆ m_ThreadLocalMinimizer

std::vector<std::unique_ptr<solvers::Minimizer> > dismec::TrainingTaskGenerator::m_ThreadLocalMinimizer
private

Definition at line 65 of file training.h.

Referenced by finalize(), init_thread(), prepare(), and train_label().

◆ m_ThreadLocalObjective

std::vector<std::shared_ptr<objective::Objective> > dismec::TrainingTaskGenerator::m_ThreadLocalObjective
private

Definition at line 66 of file training.h.

Referenced by finalize(), init_thread(), prepare(), and train_label().

◆ m_ThreadLocalPostProc

std::vector<std::unique_ptr<postproc::PostProcessor> > dismec::TrainingTaskGenerator::m_ThreadLocalPostProc
private

Definition at line 68 of file training.h.

Referenced by finalize(), init_thread(), prepare(), and train_label().

◆ m_ThreadLocalWeightInit

std::vector<std::unique_ptr<init::WeightsInitializer> > dismec::TrainingTaskGenerator::m_ThreadLocalWeightInit
private

Definition at line 67 of file training.h.

Referenced by finalize(), init_thread(), prepare(), and train_label().

◆ m_ThreadLocalWorkingVector

std::vector<DenseRealVector> dismec::TrainingTaskGenerator::m_ThreadLocalWorkingVector
private

Definition at line 64 of file training.h.

Referenced by finalize(), init_thread(), prepare(), and train_label().


The documentation for this class was generated from the following files: