Refactor the CLI. (#5574)
* Enable parameter validation. * Enable JSON. * Catch `dmlc::Error`. * Show help message.
This commit is contained in:
@@ -7,8 +7,6 @@
|
||||
#ifndef XGBOOST_COMMON_CONFIG_H_
|
||||
#define XGBOOST_COMMON_CONFIG_H_
|
||||
|
||||
#include <xgboost/logging.h>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
@@ -18,6 +16,8 @@
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
#include "xgboost/logging.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
/*!
|
||||
@@ -40,10 +40,16 @@ class ConfigParser {
|
||||
|
||||
std::string LoadConfigFile(const std::string& path) {
|
||||
std::ifstream fin(path, std::ios_base::in | std::ios_base::binary);
|
||||
CHECK(fin) << "Failed to open: " << path;
|
||||
std::string content{std::istreambuf_iterator<char>(fin),
|
||||
std::istreambuf_iterator<char>()};
|
||||
return content;
|
||||
CHECK(fin) << "Failed to open config file: \"" << path << "\"";
|
||||
try {
|
||||
std::string content{std::istreambuf_iterator<char>(fin),
|
||||
std::istreambuf_iterator<char>()};
|
||||
return content;
|
||||
} catch (std::ios_base::failure const &e) {
|
||||
LOG(FATAL) << "Failed to read config file: \"" << path << "\"\n"
|
||||
<< e.what();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
#ifdef XGBOOST_USE_NCCL
|
||||
#include "nccl.h"
|
||||
#include "../common/io.h"
|
||||
#endif
|
||||
|
||||
#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600 || defined(__clang__)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <random>
|
||||
|
||||
#include "xgboost/host_device_vector.h"
|
||||
#include "io.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
|
||||
Reference in New Issue
Block a user