1#ifndef LIGHTGBM_TREELEARNER_PARALLEL_TREE_LEARNER_H_
2#define LIGHTGBM_TREELEARNER_PARALLEL_TREE_LEARNER_H_
4#include "serial_tree_learner.h"
5#include "gpu_tree_learner.h"
6#include <LightGBM/network.h>
8#include <LightGBM/utils/array_args.h>
21template <
typename TREELEARNER_T>
26 void Init(
const Dataset* train_data,
bool is_constant_hessian)
override;
29 void BeforeTrain()
override;
30 void FindBestSplitsFromHistograms(
const std::vector<int8_t>& is_feature_used,
bool use_subtract)
override;
37 std::vector<char> input_buffer_;
39 std::vector<char> output_buffer_;
47template <
typename TREELEARNER_T>
52 void Init(
const Dataset* train_data,
bool is_constant_hessian)
override;
53 void ResetConfig(
const Config* config)
override;
56 void BeforeTrain()
override;
57 void FindBestSplits()
override;
58 void FindBestSplitsFromHistograms(
const std::vector<int8_t>& is_feature_used,
bool use_subtract)
override;
59 void Split(
Tree* tree,
int best_Leaf,
int* left_leaf,
int* right_leaf)
override;
61 inline data_size_t GetGlobalDataCountInLeaf(
int leaf_idx)
const override {
63 return global_data_count_in_leaf_[leaf_idx];
75 std::vector<char> input_buffer_;
77 std::vector<char> output_buffer_;
80 std::vector<bool> is_feature_aggregated_;
82 std::vector<comm_size_t> block_start_;
84 std::vector<comm_size_t> block_len_;
86 std::vector<comm_size_t> buffer_write_start_pos_;
88 std::vector<comm_size_t> buffer_read_start_pos_;
90 comm_size_t reduce_scatter_size_;
92 std::vector<data_size_t> global_data_count_in_leaf_;
101template <
typename TREELEARNER_T>
106 void Init(
const Dataset* train_data,
bool is_constant_hessian)
override;
107 void ResetConfig(
const Config* config)
override;
110 void BeforeTrain()
override;
111 bool BeforeFindBestSplit(
const Tree* tree,
int left_leaf,
int right_leaf)
override;
112 void FindBestSplits()
override;
113 void FindBestSplitsFromHistograms(
const std::vector<int8_t>& is_feature_used,
bool use_subtract)
override;
114 void Split(
Tree* tree,
int best_Leaf,
int* left_leaf,
int* right_leaf)
override;
116 inline data_size_t GetGlobalDataCountInLeaf(
int leaf_idx)
const override {
118 return global_data_count_in_leaf_[leaf_idx];
129 void GlobalVoting(
int leaf_idx,
const std::vector<LightSplitInfo>& splits,
130 std::vector<int>* out);
137 const std::vector<int>& larger_top_features);
149 std::vector<char> input_buffer_;
151 std::vector<char> output_buffer_;
154 std::vector<bool> smaller_is_feature_aggregated_;
157 std::vector<bool> larger_is_feature_aggregated_;
159 std::vector<comm_size_t> block_start_;
161 std::vector<comm_size_t> block_len_;
163 std::vector<comm_size_t> smaller_buffer_read_start_pos_;
165 std::vector<comm_size_t> larger_buffer_read_start_pos_;
167 comm_size_t reduce_scatter_size_;
169 std::vector<data_size_t> global_data_count_in_leaf_;
171 std::unique_ptr<LeafSplits> smaller_leaf_splits_global_;
173 std::unique_ptr<LeafSplits> larger_leaf_splits_global_;
175 std::unique_ptr<FeatureHistogram[]> smaller_leaf_histogram_array_global_;
177 std::unique_ptr<FeatureHistogram[]> larger_leaf_histogram_array_global_;
179 std::vector<HistogramBinEntry> smaller_leaf_histogram_data_;
180 std::vector<HistogramBinEntry> larger_leaf_histogram_data_;
181 std::vector<FeatureMetainfo> feature_metas_;
185inline void SyncUpGlobalBestSplit(
char* input_buffer_,
char* output_buffer_,
SplitInfo* smaller_best_split,
SplitInfo* larger_best_split,
int max_cat_threshold) {
187 int size = SplitInfo::Size(max_cat_threshold);
188 smaller_best_split->CopyTo(input_buffer_);
189 larger_best_split->CopyTo(input_buffer_ + size);
191 [] (
const char* src,
char* dst,
int size, comm_size_t len) {
192 comm_size_t used_size = 0;
194 while (used_size < len) {
198 std::memcpy(dst, src, size);
206 smaller_best_split->CopyFrom(output_buffer_);
207 larger_best_split->CopyFrom(output_buffer_ + size);
Data parallel learning algorithm. Workers use local data to construct histograms locally,...
Definition parallel_tree_learner.h:48
The main class of data set, which are used to traning or validation.
Definition dataset.h:278
Feature parallel learning algorithm. Different machine will find best split on different features,...
Definition parallel_tree_learner.h:22
static void Allreduce(char *input, comm_size_t input_size, int type_size, char *output, const ReduceFunction &reducer)
Perform all_reduce. if data size is small, will perform AllreduceByAllGather, else with call ReduceSc...
Definition network.cpp:64
Tree model.
Definition tree.h:20
Voting based data parallel learning algorithm. Like data parallel, but not aggregate histograms for a...
Definition parallel_tree_learner.h:102
void GlobalVoting(int leaf_idx, const std::vector< LightSplitInfo > &splits, std::vector< int > *out)
Perform global voting.
Definition voting_parallel_tree_learner.cpp:166
void CopyLocalHistogram(const std::vector< int > &smaller_top_features, const std::vector< int > &larger_top_features)
Copy local histgram to buffer.
Definition voting_parallel_tree_learner.cpp:198
desc and descl2 fields must be written in reStructuredText format
Definition application.h:10
int32_t data_size_t
Type of data size, it is better to use signed type.
Definition meta.h:14
Definition split_info.hpp:190
Used to store some information for gain split point.
Definition split_info.hpp:17