File: test_driver.cu

package info (click to toggle)
xgboost 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,796 kB
  • sloc: cpp: 67,502; python: 35,503; java: 4,676; ansic: 1,426; sh: 1,320; xml: 1,197; makefile: 204; javascript: 19
file content (78 lines) | stat: -rw-r--r-- 2,405 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <gtest/gtest.h>
#include "../../../../src/tree/driver.h"
#include "../../../../src/tree/gpu_hist/expand_entry.cuh"

namespace xgboost {
namespace tree {

TEST(GpuHist, DriverDepthWise) {
  TrainParam p;
  p.UpdateAllowUnknown(Args{{"grow_policy", "depthwise"}});

  Driver<GPUExpandEntry> driver(p, 2);
  EXPECT_TRUE(driver.Pop().empty());
  DeviceSplitCandidate split;
  split.loss_chg = 1.0f;
  split.left_sum = {0, 1};
  split.right_sum = {0, 1};
  GPUExpandEntry root(0, 0, split, 2.0f, 1.0f, 1.0f);
  driver.Push({root});
  EXPECT_EQ(driver.Pop().front().nid, 0);
  driver.Push({GPUExpandEntry{1, 1, split, 2.0f, 1.0f, 1.0f}});
  driver.Push({GPUExpandEntry{2, 1, split, 2.0f, 1.0f, 1.0f}});
  driver.Push({GPUExpandEntry{3, 1, split, 2.0f, 1.0f, 1.0f}});
  driver.Push({GPUExpandEntry{4, 2, split, 2.0f, 1.0f, 1.0f}});
  // Should return 2 entries from level 1
  // as we limited the driver to pop maximum 2 nodes
  auto res = driver.Pop();
  EXPECT_EQ(res.size(), 2);
  for (auto &e : res) {
    EXPECT_EQ(e.depth, 1);
  }

  // Should now return 1 entry from level 1
  res = driver.Pop();
  EXPECT_EQ(res.size(), 1);
  EXPECT_EQ(res.at(0).depth, 1);

  res = driver.Pop();
  EXPECT_EQ(res.at(0).depth, 2);
  EXPECT_TRUE(driver.Pop().empty());
}

TEST(GpuHist, DriverLossGuided) {
  DeviceSplitCandidate high_gain;
  high_gain.left_sum = {0, 1};
  high_gain.right_sum = {0, 1};
  high_gain.loss_chg = 5.0f;
  DeviceSplitCandidate low_gain = high_gain;
  low_gain.loss_chg = 1.0f;

  TrainParam p;
  p.UpdateAllowUnknown(Args{{"grow_policy", "lossguide"}});

  Driver<GPUExpandEntry> driver(p);
  EXPECT_TRUE(driver.Pop().empty());
  GPUExpandEntry root(0, 0, high_gain, 2.0f, 1.0f, 1.0f );
  driver.Push({root});
  EXPECT_EQ(driver.Pop().front().nid, 0);
  // Select high gain first
  driver.Push({GPUExpandEntry{1, 1, low_gain, 2.0f, 1.0f, 1.0f}});
  driver.Push({GPUExpandEntry{2, 2, high_gain, 2.0f, 1.0f, 1.0f}});
  auto res = driver.Pop();
  EXPECT_EQ(res.size(), 1);
  EXPECT_EQ(res[0].nid, 2);
  res = driver.Pop();
  EXPECT_EQ(res.size(), 1);
  EXPECT_EQ(res[0].nid, 1);

  // If equal gain, use nid
  driver.Push({GPUExpandEntry{2, 1, low_gain, 2.0f, 1.0f, 1.0f}});
  driver.Push({GPUExpandEntry{1, 1, low_gain, 2.0f, 1.0f, 1.0f}});
  res = driver.Pop();
  EXPECT_EQ(res[0].nid, 1);
  res = driver.Pop();
  EXPECT_EQ(res[0].nid, 2);
}
}  // namespace tree
}  // namespace xgboost