10 #include "spdlog/fmt/chrono.h"
22 m_TaskSpec(std::move(spec)),
23 m_LabelRangeBegin(begin_label),
24 m_LabelRangeEnd(end_label.to_index() > 0 ? end_label :
label_id_t{m_TaskSpec->get_data().num_labels()})
30 static_cast<long>(
m_TaskSpec->get_data().num_labels())};
38 for(
long t = begin; t < end; ++t) {
57 m_TaskSpec->update_minimizer(*minimizer, label_id);
65 auto result = minimizer->minimize(*
objective, target);
72 spdlog::warn(
"Minimization for label {:5} failed after {:4} iterations", label_id.
to_index(), result.NumIters);
77 "Thread {} finished minimization for label {:5} in {:4} iterations ({}) with loss {:6.3} -> {:6.3} and gradient {:6.3} -> {:6.3}.",
78 thread_id.
to_index(), label_id.
to_index(), result.NumIters, result.Duration, result.InitialValue,
79 result.FinalValue, result.InitialGrad, result.FinalGrad);
115 m_TaskSpec->get_statistics_gatherer().finalize();
126 auto result = runner.
run(task);
130 for(
const auto& r : task.get_results()) {
131 total_loss += r.FinalValue;
132 total_grad += r.FinalGrad;
135 auto model = task.get_model();
138 if(!result.IsFinished)
141 model = std::make_shared<SubWrapperType>(model, model->labels_begin(),
145 return {result.IsFinished, std::move(model), total_loss, total_grad};
Generates tasks for training weights for the i'th label.
long num_tasks() const override
std::vector< DenseRealVector > m_ThreadLocalWorkingVector
label_id_t m_LabelRangeEnd
std::vector< std::unique_ptr< postproc::PostProcessor > > m_ThreadLocalPostProc
void prepare(long num_threads, long chunk_size) override
Called to notify the TaskGenerator about the number of threads.
void run_task(long task_id, thread_id_t thread_id)
label_id_t m_LabelRangeBegin
std::shared_ptr< TrainingSpec > m_TaskSpec
void finalize() override
Called after all threads have finished their tasks.
std::vector< std::unique_ptr< ResultStatsGatherer > > m_ResultGatherers
~TrainingTaskGenerator() override
std::vector< std::unique_ptr< init::WeightsInitializer > > m_ThreadLocalWeightInit
std::vector< std::unique_ptr< solvers::Minimizer > > m_ThreadLocalMinimizer
TrainingTaskGenerator(std::shared_ptr< TrainingSpec > spec, label_id_t begin_label=label_id_t{0}, label_id_t end_label=label_id_t{-1})
solvers::MinimizationResult train_label(label_id_t label_id, thread_id_t thread_id)
Runs the training of a single label.
std::shared_ptr< model::Model > m_Model
void run_tasks(long begin, long end, thread_id_t thread_id) override
std::vector< solvers::MinimizationResult > m_Results
std::vector< std::shared_ptr< objective::Objective > > m_ThreadLocalObjective
void init_thread(thread_id_t thread_id) override
Called once a thread has spun up, but before it runs its first task.
Strong typedef for an int to signify a label id.
constexpr T to_index() const
! Explicitly convert to an integer.
RunResult run(TaskGenerator &tasks, long start=0)
Strong typedef for an int to signify a thread id.
@ SUCCESS
The returned result is a minimum according to the stopping criterion of the algorithm.
Main namespace in which all types, classes, and functions are defined.
TrainingResult run_training(parallel::ParallelRunner &runner, std::shared_ptr< TrainingSpec > spec, label_id_t begin_label=label_id_t{0}, label_id_t end_label=label_id_t{-1})
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
float real_t
The default type for floating point values.
Specifies how to interpret a weight matrix for a partial model.