Check deprecated n_gpus. (#4908)

This commit is contained in:
Jiaming Yuan 2019-10-02 02:05:14 -04:00 committed by GitHub
parent 7e24a8d245
commit 4ab1df5fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#define XGBOOST_GENERIC_PARAMETERS_H_
#include <dmlc/parameter.h>
#include <xgboost/logging.h>
#include <xgboost/enum_class_param.h>
#include <string>
@ -21,6 +22,15 @@ struct GenericParameter : public dmlc::Parameter<GenericParameter> {
int nthread;
// primary device, -1 means no gpu.
int gpu_id;
void CheckDeprecated() {
if (this->n_gpus != 0) {
LOG(WARNING)
<< "\nn_gpus: "
<< this->__MANAGER__()->Find("n_gpus")->GetFieldInfo().description;
}
}
// declare parameters
DMLC_DECLARE_PARAMETER(GenericParameter) {
DMLC_DECLARE_FIELD(seed).set_default(0).describe(
@ -41,15 +51,16 @@ struct GenericParameter : public dmlc::Parameter<GenericParameter> {
.describe("The primary GPU device ordinal.");
DMLC_DECLARE_FIELD(n_gpus)
.set_default(0)
.set_range(0, 0)
.describe("Deprecated. Single process multi-GPU training is no longer supported. "
"Please switch to distributed training with one process per GPU. "
"This can be done using Dask or Spark.");
.set_range(0, 1)
.describe(
"\n\tDeprecated. Single process multi-GPU training is no longer supported."
"\n\tPlease switch to distributed training with one process per GPU."
"\n\tThis can be done using Dask or Spark. See documentation for details.");
}
private:
// number of devices to use (deprecated).
int n_gpus;
int n_gpus {0};
};
} // namespace xgboost

View File

@ -154,7 +154,10 @@ class LearnerImpl : public Learner {
Args args = {cfg_.cbegin(), cfg_.cend()};
tparam_.InitAllowUnknown(args);
generic_param_.InitAllowUnknown(args);
generic_param_.CheckDeprecated();
ConsoleLogger::Configure(args);
if (generic_param_.nthread != 0) {
omp_set_num_threads(generic_param_.nthread);