Merge lossgude and depthwise strategies for CPU hist (#7007)

* fix java/scala test: max depth is also valid parameter for lossguide

Co-authored-by: Kirill Shvets <kirill.shvets@intel.com>
This commit is contained in:
ShvetsKS
2021-06-02 20:49:43 +03:00
committed by GitHub
parent ee4f51a631
commit 57c732655e
11 changed files with 415 additions and 484 deletions

View File

@@ -1,20 +1,21 @@
#include <gtest/gtest.h>
#include "../../../../src/tree/gpu_hist/driver.cuh"
#include "../../../../src/tree/driver.h"
#include "../../../../src/tree/gpu_hist/expand_entry.cuh"
namespace xgboost {
namespace tree {
TEST(GpuHist, DriverDepthWise) {
Driver driver(TrainParam::kDepthWise);
Driver<GPUExpandEntry> driver(TrainParam::kDepthWise);
EXPECT_TRUE(driver.Pop().empty());
DeviceSplitCandidate split;
split.loss_chg = 1.0f;
ExpandEntry root(0, 0, split, .0f, .0f, .0f);
GPUExpandEntry root(0, 0, split, .0f, .0f, .0f);
driver.Push({root});
EXPECT_EQ(driver.Pop().front().nid, 0);
driver.Push({ExpandEntry{1, 1, split, .0f, .0f, .0f}});
driver.Push({ExpandEntry{2, 1, split, .0f, .0f, .0f}});
driver.Push({ExpandEntry{3, 2, split, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{1, 1, split, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{2, 1, split, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{3, 2, split, .0f, .0f, .0f}});
// Should return entries from level 1
auto res = driver.Pop();
EXPECT_EQ(res.size(), 2);
@@ -32,14 +33,14 @@ TEST(GpuHist, DriverLossGuided) {
DeviceSplitCandidate low_gain;
low_gain.loss_chg = 1.0f;
Driver driver(TrainParam::kLossGuide);
Driver<GPUExpandEntry> driver(TrainParam::kLossGuide);
EXPECT_TRUE(driver.Pop().empty());
ExpandEntry root(0, 0, high_gain, .0f, .0f, .0f);
GPUExpandEntry root(0, 0, high_gain, .0f, .0f, .0f);
driver.Push({root});
EXPECT_EQ(driver.Pop().front().nid, 0);
// Select high gain first
driver.Push({ExpandEntry{1, 1, low_gain, .0f, .0f, .0f}});
driver.Push({ExpandEntry{2, 2, high_gain, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{1, 1, low_gain, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{2, 2, high_gain, .0f, .0f, .0f}});
auto res = driver.Pop();
EXPECT_EQ(res.size(), 1);
EXPECT_EQ(res[0].nid, 2);
@@ -48,8 +49,8 @@ TEST(GpuHist, DriverLossGuided) {
EXPECT_EQ(res[0].nid, 1);
// If equal gain, use nid
driver.Push({ExpandEntry{2, 1, low_gain, .0f, .0f, .0f}});
driver.Push({ExpandEntry{1, 1, low_gain, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{2, 1, low_gain, .0f, .0f, .0f}});
driver.Push({GPUExpandEntry{1, 1, low_gain, .0f, .0f, .0f}});
res = driver.Pop();
EXPECT_EQ(res[0].nid, 1);
res = driver.Pop();