Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R] Error out on unrecognized arguments and ... parameters #11074

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

david-cortes
Copy link
Contributor

@david-cortes david-cortes commented Dec 7, 2024

ref #9810

closes #10563

As a follow up from #11072

(requires changes from that PR)

This PR modifies the logic of xgboost functions to:

  • Accept training parameters only under the params argument (save for xgboost()).
  • Error out when receiving an argument that is not used.
  • Throw a warning instead of an error when the parameter is recognized as deprecated.
  • Change feval to custom_metric like it was done in the python package.
  • Use the checked xgb.params constructor for all tests and examples whenever possible.

Motivation

After all the changes in the R interface, we've now refocused xgb.train to be a low-level function that should stay as close as possible to the xgboost core library and the other language bindings and which should be preferred for production usage, while we now have xgboost() which is the user-friendly version following R idioms and meant for interactive usage.

Given that xgb.train() is a more low-level and production-oriented function, one would not want to find surprising or strange behaviors on it, such as silently accepting a parameter which is not used, or having undocumented ... parameters, or bumping into undefined behavior when something is passed as both ... and params.

As another motivation, the python package does not allow *args or **kwargs to pass parameters to xgb.train - this would make the R interface calls look more similar to those of other interfaces.

Even in XGBoost's own test suite, there have been many tests that were using removed arguments and no one noticed due to this behavior of accepting all arguments. The changes here allowed catching a few more tests that had unused parameters.

Since it might not be obvious that some arguments have been renamed, and this will be the first CRAN release to use the renamed versions, it would be quite helpful to throw informative errors to users and library authors such that they would know how to change their code.

new_par <- depr_par_lut[idx_lut[i], 2]
if (!ex_match[i]) {
warning("'", pars_par, "' was partially matched to '", old_par, "'")
check.deprecation <- function(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any test for this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is not tested directly as it uses the parent frame, but the tests currently there check that the function does what it is supposed to when called from inside xgb.train.

For example, if evals is not passed (either through evals or through watchlist which this function is automatically swapping), there would be no evaluation log left in the booster object.

@trivialfis trivialfis merged commit 94c6714 into dmlc:master Dec 9, 2024
70 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants