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] Don't cap global number of threads #10028

Merged
merged 4 commits into from Feb 20, 2024

Conversation

david-cortes
Copy link
Contributor

@david-cortes david-cortes commented Feb 2, 2024

ref #9810
ref #10027

This PR removes manual capping of number of threads in XGBoost functions that take it from a global config instead of being supplied as argument.

CRAN has a requirement of not using more than 2 threads in tests and examples, so it substitutes this workaround with a manual setting of OMP threads config, which is done through a new dependency RhpcBLASctl that provides such functionality; and adds silent calls to it before the tests that might execute something with the global number of OMP threads, the same way it was done in LightGBM: microsoft/LightGBM#6226

Note: I am not entirely sure that I added silent calls to this function that sets the OMP threads in all of the examples where it's needed.

@david-cortes
Copy link
Contributor Author

Regarding the failing CI job:

Quitting from lines 498-508 [loadModel] (xgboostPresentation.Rmd)
Error: processing vignette 'xgboostPresentation.Rmd' failed with diagnostics:
there is no package called 'RhpcBLASctl'

Looks like the vignette builder is not installing all the packages mentioned under Suggests.

@trivialfis
Copy link
Member

Looks like the vignette builder is not installing all the packages mentioned under Suggests.

Please help update the CI script: /R-package/tests/helper_scripts/install_deps.R.

Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

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

Overall, it looks good; I like the small utility library. Please see the comments around the documentation.

Comment on lines 10 to 11
#' controlling the number of parallel threads that will be used, but some functionalities
#' might execute functions before this parameter can be supplied.
Copy link
Member

Choose a reason for hiding this comment

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

The only feature that has problems with local nthread is the model serialization, let's be more specific here to reduce confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Comment on lines 13 to 17
#' In such cases, the global number of threads is taken from the configured number of OpenMP
#' (OMP) threads, which if not set, will default to the maximum number of available threads.
#' The number of OMP threads in turn can be configured through an environment variable
#' `OMP_NUM_THREADS` (which needs to be set before R is started), or alternatively, can be
#' changed in an R session through package `RhpcBLASctl`, by calling function `RhpcBLASctl::omp_set_num_threads`.
Copy link
Member

Choose a reason for hiding this comment

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

I think a simple note that in addition to the nthread parameter, XGBoost honors global configuration set by OMP_NUM_THREADS or RhpcBLASctl should suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified.

R-package/demo/basic_walkthrough.R Show resolved Hide resolved
@david-cortes
Copy link
Contributor Author

R tests are now passing.

@trivialfis trivialfis merged commit 6e3c899 into dmlc:master Feb 20, 2024
26 of 28 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.

None yet

3 participants