Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add management functions for global configuration: XGBSetGlobalConfig(), XGBGetGlobalConfig(). * Add Python interface: set_config(), get_config(), and config_context(). * Add unit tests for Python * Add R interface: xgb.set.config(), xgb.get.config() * Add unit tests for R Co-authored-by: Jiaming Yuan <jm.yuan@outlook.com>
- Loading branch information
1 parent
c2ba4fb
commit fb56da5
Showing
29 changed files
with
639 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Global configuration consists of a collection of parameters that can be applied in the global | ||
#' scope. See \url{https://xgboost.readthedocs.io/en/stable/parameter.html} for the full list of | ||
#' parameters supported in the global configuration. Use \code{xgb.set.config} to update the | ||
#' values of one or more global-scope parameters. Use \code{xgb.get.config} to fetch the current | ||
#' values of all global-scope parameters (listed in | ||
#' \url{https://xgboost.readthedocs.io/en/stable/parameter.html}). | ||
#' | ||
#' @rdname xgbConfig | ||
#' @title Set and get global configuration | ||
#' @name xgb.set.config, xgb.get.config | ||
#' @export xgb.set.config xgb.get.config | ||
#' @param ... List of parameters to be set, as keyword arguments | ||
#' @return | ||
#' \code{xgb.set.config} returns \code{TRUE} to signal success. \code{xgb.get.config} returns | ||
#' a list containing all global-scope parameters and their values. | ||
#' | ||
#' @examples | ||
#' # Set verbosity level to silent (0) | ||
#' xgb.set.config(verbosity = 0) | ||
#' # Now global verbosity level is 0 | ||
#' config <- xgb.get.config() | ||
#' print(config$verbosity) | ||
#' # Set verbosity level to warning (1) | ||
#' xgb.set.config(verbosity = 1) | ||
#' # Now global verbosity level is 1 | ||
#' config <- xgb.get.config() | ||
#' print(config$verbosity) | ||
xgb.set.config <- function(...) { | ||
new_config <- list(...) | ||
.Call(XGBSetGlobalConfig_R, jsonlite::toJSON(new_config, auto_unbox = TRUE)) | ||
return(TRUE) | ||
} | ||
|
||
#' @rdname xgbConfig | ||
xgb.get.config <- function() { | ||
config <- .Call(XGBGetGlobalConfig_R) | ||
return(jsonlite::fromJSON(config)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
context('Test global configuration') | ||
|
||
test_that('Global configuration works with verbosity', { | ||
old_verbosity <- xgb.get.config()$verbosity | ||
for (v in c(0, 1, 2, 3)) { | ||
xgb.set.config(verbosity = v) | ||
expect_equal(xgb.get.config()$verbosity, v) | ||
} | ||
xgb.set.config(verbosity = old_verbosity) | ||
expect_equal(xgb.get.config()$verbosity, old_verbosity) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*! | ||
* Copyright 2020 by Contributors | ||
* \file global_config.h | ||
* \brief Global configuration for XGBoost | ||
* \author Hyunsu Cho | ||
*/ | ||
#ifndef XGBOOST_GLOBAL_CONFIG_H_ | ||
#define XGBOOST_GLOBAL_CONFIG_H_ | ||
|
||
#include <xgboost/parameter.h> | ||
#include <vector> | ||
#include <string> | ||
|
||
namespace xgboost { | ||
class Json; | ||
|
||
struct GlobalConfiguration : public XGBoostParameter<GlobalConfiguration> { | ||
int verbosity; | ||
DMLC_DECLARE_PARAMETER(GlobalConfiguration) { | ||
DMLC_DECLARE_FIELD(verbosity) | ||
.set_range(0, 3) | ||
.set_default(1) // shows only warning | ||
.describe("Flag to print out detailed breakdown of runtime."); | ||
} | ||
}; | ||
|
||
using GlobalConfigThreadLocalStore = dmlc::ThreadLocalStore<GlobalConfiguration>; | ||
} // namespace xgboost | ||
|
||
#endif // XGBOOST_GLOBAL_CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.