xgboost

generic_parameters.h
Go to the documentation of this file.
1
5 #ifndef XGBOOST_GENERIC_PARAMETERS_H_
6 #define XGBOOST_GENERIC_PARAMETERS_H_
7
8 #include <xgboost/logging.h>
9 #include <xgboost/parameter.h>
10
11 #include <string>
12
13 namespace xgboost {
14
15 struct GenericParameter : public XGBoostParameter<GenericParameter> {
16 // Constant representing the device ID of CPU.
17 static int32_t constexpr kCpuId = -1;
18 static int64_t constexpr kDefaultSeed = 0;
19
20 public:
21 // stored random seed
22 int64_t seed { kDefaultSeed };
23 // whether seed the PRNG each iteration
24 bool seed_per_iteration;
25 // number of threads to use if OpenMP is enabled
26 // if equals 0, use system default
27 int nthread;
28 // primary device, -1 means no gpu.
29 int gpu_id;
30 // fail when gpu_id is invalid
31 bool fail_on_invalid_gpu_id {false};
32 // gpu page size in external memory mode, 0 means using the default.
33 size_t gpu_page_size;
34 bool enable_experimental_json_serialization {true};
35 bool validate_parameters {false};
36
37 void CheckDeprecated() {
38 if (this->n_gpus != 0) {
39 LOG(WARNING)
40 << "\nn_gpus: "
41 << this->__MANAGER__()->Find("n_gpus")->GetFieldInfo().description;
42 }
43 }
49 void ConfigureGpuId(bool require_gpu);
50
51 // declare parameters
52 DMLC_DECLARE_PARAMETER(GenericParameter) {
53 DMLC_DECLARE_FIELD(seed).set_default(kDefaultSeed).describe(
54 "Random number seed during training.");
55 DMLC_DECLARE_ALIAS(seed, random_state);
56 DMLC_DECLARE_FIELD(seed_per_iteration)
57 .set_default(false)
58 .describe(
59 "Seed PRNG determnisticly via iterator number, "
60 "this option will be switched on automatically on distributed "
61 "mode.");
62 DMLC_DECLARE_FIELD(nthread).set_default(0).describe(
63 "Number of threads to use.");
64 DMLC_DECLARE_ALIAS(nthread, n_jobs);
65
66 DMLC_DECLARE_FIELD(gpu_id)
67 .set_default(-1)
68 .set_lower_bound(-1)
69 .describe("The primary GPU device ordinal.");
70 DMLC_DECLARE_FIELD(fail_on_invalid_gpu_id)
71 .set_default(false)
72 .describe("Fail with error when gpu_id is invalid.");
73 DMLC_DECLARE_FIELD(gpu_page_size)
74 .set_default(0)
75 .set_lower_bound(0)
76 .describe("GPU page size when running in external memory mode.");
77 DMLC_DECLARE_FIELD(enable_experimental_json_serialization)
78 .set_default(true)
79 .describe("Enable using JSON for memory serialization (Python Pickle, "
80 "rabit checkpoints etc.).");
81 DMLC_DECLARE_FIELD(validate_parameters)
82 .set_default(false)
83 .describe("Enable checking whether parameters are used or not.");
84 DMLC_DECLARE_FIELD(n_gpus)
85 .set_default(0)
86 .set_range(0, 1)
87 .describe(
88 "\n\tDeprecated. Single process multi-GPU training is no longer supported."
89 "\n\tPlease switch to distributed training with one process per GPU."
90 "\n\tThis can be done using Dask or Spark. See documentation for details.");
91 }
92
93 private:
94 // number of devices to use (deprecated).
95 int n_gpus {0}; // NOLINT
96 };
97 } // namespace xgboost
98
99 #endif // XGBOOST_GENERIC_PARAMETERS_H_
xgboost::GenericParameter::gpu_id
int gpu_id
Definition: generic_parameters.h:29
xgboost::GenericParameter::DMLC_DECLARE_PARAMETER
DMLC_DECLARE_PARAMETER(GenericParameter)
Definition: generic_parameters.h:52
xgboost::GenericParameter
Definition: generic_parameters.h:15
parameter.h
macro for using C++11 enum class as DMLC parameter
xgboost::GenericParameter::seed_per_iteration
bool seed_per_iteration
Definition: generic_parameters.h:24
xgboost::GenericParameter::CheckDeprecated
void CheckDeprecated()
Definition: generic_parameters.h:37
xgboost::GenericParameter::enable_experimental_json_serialization
bool enable_experimental_json_serialization
Definition: generic_parameters.h:34
xgboost::GenericParameter::fail_on_invalid_gpu_id
bool fail_on_invalid_gpu_id
Definition: generic_parameters.h:31
xgboost::XGBoostParameter
Definition: parameter.h:84
xgboost::GenericParameter::kDefaultSeed
static constexpr int64_t kDefaultSeed
Definition: generic_parameters.h:18
xgboost::GenericParameter::ConfigureGpuId
void ConfigureGpuId(bool require_gpu)
Configure the parameter ‘gpu_id’.
xgboost::GenericParameter::gpu_page_size
size_t gpu_page_size
Definition: generic_parameters.h:33
xgboost::GenericParameter::validate_parameters
bool validate_parameters
Definition: generic_parameters.h:35
xgboost::GenericParameter::nthread
int nthread
Definition: generic_parameters.h:27
xgboost::GenericParameter::kCpuId
static constexpr int32_t kCpuId
Definition: generic_parameters.h:17
xgboost::GenericParameter::seed
int64_t seed
Definition: generic_parameters.h:22
xgboost
namespace of xgboost
Definition: base.h:110