-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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] Use inplace predict #9829
[R] Use inplace predict #9829
Conversation
I see there's a failing MSVC job, but it doesn't seem to contain any test failure, only warnings. No idea what went wrong there. |
Always fun to have R failing on Windows when one thinks everything is ready. ;-) I restarted the CI and it seems to be failing again. I can help debug it on Monday next week. |
Let's hope the R update in the msvc job helps here. |
Let me try to reproduce it. |
R-package/R/xgb.Booster.R
Outdated
use_as_csr_matrix <- FALSE | ||
inplace_predict_supported <- !predcontrib && !predinteraction && !predleaf && is.null(ntreelimit) | ||
if (inplace_predict_supported) { | ||
if (config$learner$learner_train_param$booster != "gbtree") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dart is supported as well. Only gblinear is not supported.
I can reproduce the error on my machine, and somehow magically got it working by
|
Stupid question: wouldn't setting a proxy dmatrix inside the prediction function be slower and/or consume the same amount of memory as creating a dmatrix to use for |
BTW, while trying to add base margin here, I ran into an issue which manifested itself with both inplace predictions and dmatrix predictions: #9869 |
No, the proxy DMatrix is just a reference to the original data, so, don't free the data without first freeing the proxy dmatrix ... |
With hindsight, the inplace prediction can be completely implemented with proxy DMatrix without those special parameters for |
Added |
@trivialfis After adding support for categorical features for data frames, I just realized that passing them to What would be the best way to retrieve that information (which columns are categorical) from the booster? |
@david-cortes In Python, the booster has the same |
@trivialfis Thanks for the tip. Would be very helpful if you could investigate the failing MSVC job here so that we can merge this PR soon, as I'm finding some of the code here will be needed for the QuantileDMatrix and other PRs too. I unfortunately don't know how best to debug an MSVC-compiled module that needs to be imported in R, as it can't use typical tools like sanitizers with a regular R build. |
I can try, but I admit I don't use Windows very often. |
Is this PR independent of #9902? I use Windows as a daily driver, so should be able to help debug the error in this PR. |
yes. |
The compiler error with sanitizer was about a different file in XGB (refresher), I will try again tomorrow. |
I have made no progress on the Windows error, we will have to delay this PR for a while. |
Discussion with @hcho3 , we are likely to move away from MSVC for the R package, along with which, we will drop support for building R package with GPU on Windows using MSVC. We haven't ruled out the possibility of using rtools and CMake to build GPU support, in addition, recommending WSL2 is a potential option as well. |
Is that just for the R package, or also for the python package for windows? If just for R, have there been MSVC-specific issues like this before? Curious about what makes it problematic. |
It's just the R package,mostly because I couldn't figure out the compiler warning and the error in this PR. So far, it seems MSVC is not handling the C headers from R very well. |
Could you please help rebase the PR? |
Updated, but I'm now not 100% sure if everything is correct. I suddenly started getting an error in this test and the one right after it after merging the latest master: xgboost/R-package/tests/testthat/test_basic.R Line 142 in c5d0608
Before, it was using It looks like predictions from in-place match those from DMatrix and from BTW, would be ideal if you could merge the PR about data iterators before this one: |
Please let me know how things are going. ;-) Is there anything I can help? |
PR is ready for review. Would be ideal if you could look into this issue with loss of floating point precision for dart. Since the difference between inplace and dmatrix is below |
#' encoding (same as during DMatrix creation) - hence, one should not pass a `factor` | ||
#' under a column which during training had a different type. | ||
#' } | ||
#' @param missing Float value that represents missing values in data (e.g., 0 or some other extreme value). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use nan
as missing value, since XGBoost can handle 0 just as any other real number.
This is also a headache for us since many sparse matrix implementations assume 0 as missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, default value is R's NA
, which gets translated to either NAN
or R_NaInt
depending on the input type.
n_row <- NULL | ||
if (!is_dmatrix) { | ||
|
||
inplace_predict_supported <- !predcontrib && !predinteraction && !predleaf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to support leaf in the near future.
|
||
struct ProxyDmatrixError : public std::exception {}; | ||
|
||
struct ProxyDmatrixWrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this related to the R implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's used in order to break out of a C++ block, so that C++ objects get destructed before throwing an R error.
Thank you for the work on inplace prediction! The R package is looking much better now thanks to your great work. |
This PR switches the
predict
method to use inplace prediction when possible (dense matrix / CSR matrix as inputs).It seems that there are quite a lot of limitations around when it is or isn't possible to use these functions which are not documented in the readthedocs page, so I am not sure if the conditions that I am adding here to check for whether inplace predict is supported are correct.
I'm also not sure what's the most efficient way of dealing with all the JSON manipulation here.
Along the way, since it is refactoring some of the earlier code introduced for processing the "missing" parameter, it also modifies the function that creates DMatrix objects from CSR/CSC. It doesn't make a practical difference there though, since currently only classes inheriting from "DsparseMatrix" (float64 values) are supported, but might come handy in the future if other sparse matrix classes (like "LsparseMatrix") become supported in the future.