DiSMEC++
|
Generates tasks for training weights for the i'th label. More...
#include <training.h>
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 |
![]() | |
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< TrainingSpec > | m_TaskSpec |
label_id_t | m_LabelRangeBegin |
label_id_t | m_LabelRangeEnd |
std::shared_ptr< model::Model > | m_Model |
std::vector< solvers::MinimizationResult > | m_Results |
std::vector< DenseRealVector > | m_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 | |
![]() | |
using | thread_id_t = dismec::parallel::thread_id_t |
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.
|
explicit |
Definition at line 20 of file training.cpp.
References m_LabelRangeBegin, m_LabelRangeEnd, m_Model, m_Results, and m_TaskSpec.
|
overridedefault |
|
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.
|
inline |
Definition at line 38 of file training.h.
References m_Model.
|
inline |
Definition at line 39 of file training.h.
References m_Results.
|
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().
|
overridevirtual |
Implements dismec::parallel::TaskGenerator.
Definition at line 118 of file training.cpp.
References m_Results.
|
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()
.
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()
. num_threads | Number of threads that will be used. |
chunk_size | A 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.
|
private |
Definition at line 43 of file training.cpp.
References m_LabelRangeBegin, m_Results, m_TaskSpec, dismec::opaque_int_type< Tag, T >::to_index(), and train_label().
Referenced by run_tasks().
|
overridevirtual |
Implements dismec::parallel::TaskGenerator.
Definition at line 37 of file training.cpp.
References run_task().
|
private |
Runs the training of a single label.
label_id | The id of the label which will be trained. |
thread_id | The id of the thread on which training is running. |
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().
|
private |
Definition at line 56 of file training.h.
Referenced by run_task(), and TrainingTaskGenerator().
|
private |
Definition at line 57 of file training.h.
Referenced by TrainingTaskGenerator().
|
private |
Definition at line 60 of file training.h.
Referenced by get_model(), train_label(), and TrainingTaskGenerator().
|
private |
Definition at line 69 of file training.h.
Referenced by init_thread(), prepare(), and train_label().
|
private |
Definition at line 61 of file training.h.
Referenced by get_results(), num_tasks(), run_task(), and TrainingTaskGenerator().
|
private |
Definition at line 53 of file training.h.
Referenced by finalize(), init_thread(), run_task(), train_label(), and TrainingTaskGenerator().
|
private |
Definition at line 65 of file training.h.
Referenced by finalize(), init_thread(), prepare(), and train_label().
|
private |
Definition at line 66 of file training.h.
Referenced by finalize(), init_thread(), prepare(), and train_label().
|
private |
Definition at line 68 of file training.h.
Referenced by finalize(), init_thread(), prepare(), and train_label().
|
private |
Definition at line 67 of file training.h.
Referenced by finalize(), init_thread(), prepare(), and train_label().
|
private |
Definition at line 64 of file training.h.
Referenced by finalize(), init_thread(), prepare(), and train_label().