@@ -66,6 +66,7 @@ void CUDASingleGPUTreeLearner::Init(const Dataset* train_data, bool is_constant_
66
66
leaf_best_split_default_left_.resize (config_->num_leaves , 0 );
67
67
leaf_num_data_.resize (config_->num_leaves , 0 );
68
68
leaf_data_start_.resize (config_->num_leaves , 0 );
69
+ leaf_sum_gradients_.resize (config_->num_leaves , 0 .0f );
69
70
leaf_sum_hessians_.resize (config_->num_leaves , 0 .0f );
70
71
71
72
if (!boosting_on_cuda_) {
@@ -122,6 +123,7 @@ void CUDASingleGPUTreeLearner::BeforeTrain() {
122
123
cuda_data_partition_->cuda_data_indices (),
123
124
root_num_data,
124
125
cuda_histogram_constructor_->cuda_hist_pointer (),
126
+ &leaf_sum_gradients_[0 ],
125
127
&leaf_sum_hessians_[0 ],
126
128
cuda_gradient_discretizer_->grad_scale_ptr (),
127
129
cuda_gradient_discretizer_->hess_scale_ptr ());
@@ -137,6 +139,7 @@ void CUDASingleGPUTreeLearner::BeforeTrain() {
137
139
cuda_data_partition_->cuda_data_indices (),
138
140
root_num_data,
139
141
cuda_histogram_constructor_->cuda_hist_pointer (),
142
+ &leaf_sum_gradients_[0 ],
140
143
&leaf_sum_hessians_[0 ]);
141
144
}
142
145
leaf_num_data_[0 ] = root_num_data;
@@ -162,6 +165,12 @@ Tree* CUDASingleGPUTreeLearner::Train(const score_t* gradients,
162
165
const bool track_branch_features = !(config_->interaction_constraints_vector .empty ());
163
166
std::unique_ptr<CUDATree> tree (new CUDATree (config_->num_leaves , track_branch_features,
164
167
config_->linear_tree , config_->gpu_device_id , has_categorical_feature_));
168
+ // set the root value by hand, as it is not handled by splits
169
+ tree->SetLeafOutput (0 , CUDALeafSplits::CalculateSplittedLeafOutput<true , false >(
170
+ leaf_sum_gradients_[smaller_leaf_index_], leaf_sum_hessians_[smaller_leaf_index_],
171
+ config_->lambda_l1 , config_->lambda_l2 , config_->path_smooth ,
172
+ static_cast <data_size_t >(num_data_), 0 ));
173
+ tree->SyncLeafOutputFromHostToCUDA ();
165
174
for (int i = 0 ; i < config_->num_leaves - 1 ; ++i) {
166
175
global_timer.Start (" CUDASingleGPUTreeLearner::ConstructHistogramForLeaf" );
167
176
const data_size_t num_data_in_smaller_leaf = leaf_num_data_[smaller_leaf_index_];
@@ -293,8 +302,6 @@ Tree* CUDASingleGPUTreeLearner::Train(const score_t* gradients,
293
302
best_split_info);
294
303
}
295
304
296
- double sum_left_gradients = 0 .0f ;
297
- double sum_right_gradients = 0 .0f ;
298
305
cuda_data_partition_->Split (best_split_info,
299
306
best_leaf_index_,
300
307
right_leaf_index,
@@ -313,10 +320,10 @@ Tree* CUDASingleGPUTreeLearner::Train(const score_t* gradients,
313
320
&leaf_data_start_[right_leaf_index],
314
321
&leaf_sum_hessians_[best_leaf_index_],
315
322
&leaf_sum_hessians_[right_leaf_index],
316
- &sum_left_gradients ,
317
- &sum_right_gradients );
323
+ &leaf_sum_gradients_[best_leaf_index_] ,
324
+ &leaf_sum_gradients_[right_leaf_index] );
318
325
#ifdef DEBUG
319
- CheckSplitValid (best_leaf_index_, right_leaf_index, sum_left_gradients, sum_right_gradients );
326
+ CheckSplitValid (best_leaf_index_, right_leaf_index);
320
327
#endif // DEBUG
321
328
smaller_leaf_index_ = (leaf_num_data_[best_leaf_index_] < leaf_num_data_[right_leaf_index] ? best_leaf_index_ : right_leaf_index);
322
329
larger_leaf_index_ = (smaller_leaf_index_ == best_leaf_index_ ? right_leaf_index : best_leaf_index_);
@@ -374,6 +381,7 @@ void CUDASingleGPUTreeLearner::ResetConfig(const Config* config) {
374
381
leaf_best_split_default_left_.resize (config_->num_leaves , 0 );
375
382
leaf_num_data_.resize (config_->num_leaves , 0 );
376
383
leaf_data_start_.resize (config_->num_leaves , 0 );
384
+ leaf_sum_gradients_.resize (config_->num_leaves , 0 .0f );
377
385
leaf_sum_hessians_.resize (config_->num_leaves , 0 .0f );
378
386
}
379
387
cuda_histogram_constructor_->ResetConfig (config);
@@ -562,9 +570,7 @@ void CUDASingleGPUTreeLearner::SelectFeatureByNode(const Tree* tree) {
562
570
#ifdef DEBUG
563
571
void CUDASingleGPUTreeLearner::CheckSplitValid (
564
572
const int left_leaf,
565
- const int right_leaf,
566
- const double split_sum_left_gradients,
567
- const double split_sum_right_gradients) {
573
+ const int right_leaf) {
568
574
std::vector<data_size_t > left_data_indices (leaf_num_data_[left_leaf]);
569
575
std::vector<data_size_t > right_data_indices (leaf_num_data_[right_leaf]);
570
576
CopyFromCUDADeviceToHost<data_size_t >(left_data_indices.data (),
@@ -585,9 +591,9 @@ void CUDASingleGPUTreeLearner::CheckSplitValid(
585
591
sum_right_gradients += host_gradients_[index ];
586
592
sum_right_hessians += host_hessians_[index ];
587
593
}
588
- CHECK_LE (std::fabs (sum_left_gradients - split_sum_left_gradients ), 1e-6f );
594
+ CHECK_LE (std::fabs (sum_left_gradients - leaf_sum_gradients_[left_leaf] ), 1e-6f );
589
595
CHECK_LE (std::fabs (sum_left_hessians - leaf_sum_hessians_[left_leaf]), 1e-6f );
590
- CHECK_LE (std::fabs (sum_right_gradients - split_sum_right_gradients ), 1e-6f );
596
+ CHECK_LE (std::fabs (sum_right_gradients - leaf_sum_gradients_[right_leaf] ), 1e-6f );
591
597
CHECK_LE (std::fabs (sum_right_hessians - leaf_sum_hessians_[right_leaf]), 1e-6f );
592
598
}
593
599
#endif // DEBUG
0 commit comments