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

Error with gpu-enabled xgboost #1235

Open
mitchellmanware opened this issue Jan 27, 2025 · 3 comments
Open

Error with gpu-enabled xgboost #1235

mitchellmanware opened this issue Jan 27, 2025 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@mitchellmanware
Copy link

The problem

I am getting an error message when implementing tidymodels functions for xgboost boosted tree model with GPU acceleration. Error reports problem with evals parameter in xgb.train

Reproducible example

Utilizing GPU-enabled xgboost version 2.1.3, accessed from Releases.
Package installation:

# Build and install xgboost with GPU support
wget https://github.com/dmlc/xgboost/releases/download/v2.1.3/xgboost_r_gpu_linux_2.1.3.tar.gz    
Rscript -e "install.packages(c('data.table', 'jsonlite'))"
R CMD INSTALL ./xgboost_r_gpu_linux_2.1.3.tar.gz

Reprex with credit_data example data:

> library(xgboost); library(tibble); library(rsample); library(dplyr); library(purrr); library(parsnip); library(recipes); library(workflows); library(dials); library(tune); library(yardstick); library(tidymodels)
> data(credit_data, package = "modeldata")
> credit <- credit_data |> tibble::as_tibble()
> credit_split <- rsample::initial_split(
          credit, prop = 0.8, strata = "Status"
        )
> train <- rsample::training(credit_split)
        test <- rsample::testing(credit_split)
> cv_split <- rsample::vfold_cv(
          train, v = 5, repeats = 2, strata = "Status"
        )
> scaler <- train |>
          dplyr::count(Status) |>
          dplyr::pull(n) |>
          purrr::reduce(`/`)
> xg_spec <- parsnip::boost_tree(
          mode = "classification",
          trees = parsnip::tune(),
          tree_depth = parsnip::tune(),
          sample_size = parsnip::tune()
        ) |>
          parsnip::set_engine(
            "xgboost",
            params = list(tree_method = "gpu_hist"),
            scale_pos_weight = scaler
          )
> rec_xg_flow <- recipes::recipe(Status ~ ., data = train) |>
          recipes::step_unknown(
            all_nominal_predictors(), new_level = "missing"
          ) |>
          recipes::step_novel(all_nominal_predictors(), new_level = "Unseen") |>
          recipes::step_other(all_nominal_predictors(), other = "Misc") |>
          recipes::step_dummy(all_nominal_predictors(), one_hot = TRUE)
> xg_flow <- workflows::workflow(
          preprocessor = rec_xg_flow, spec = xg_spec
        )
> xg_trees <- dials::trees(range = c(10, 300))
        xg_tree_depth <- dials::tree_depth(range = c(2, 8))
        xg_sample_size <- dials::sample_prop(range = c(0.3, 1.0))
        xg_params <- dials::parameters(xg_trees, xg_tree_depth, xg_sample_size)
> xg_tune <- tune::tune_grid(
          xg_flow,
          resamples = cv_split,
          param_info = xg_params,
          metrics = yardstick::metric_set(
            yardstick::roc_auc, yardstick::accuracy
          ),
          grid = 30,
          control = tune::control_grid(allow_par = TRUE, save_pred = TRUE)
        )
→ A | error:   <text>:1:10: unexpected '<'
               1: evals <- <
                            ^
There were issues with some computations   A: x300
Warning message:
All models failed. Run `show_notes(.Last.tune.result)` for more information.
> tune::show_notes(.Last.tune.result)
unique notes:
───────────────────────────
<text>:1:10: unexpected '<'
1: evals <- <
             ^

Reprex derived from GPU Computing with R presentation (slides 61 - 75)
@sigmafelix @kyle-messier

@EmilHvitfeldt
Copy link
Member

Hello @mitchellmanware 👋

This appears to be related to #1227 and/or #1087

@EmilHvitfeldt EmilHvitfeldt added the bug an unexpected problem or unintended behavior label Jan 27, 2025
@mitchellmanware
Copy link
Author

Thanks for the prompt response @EmilHvitfeldt

I thought it was related to those issues as well since the info=list() param has been dropped from xgb.DMatrix.

However, I cloned the parsnip repo and excluded this parameter from xgb.DMatrix and the evals <- - error persists. I am installing this custom version of parsnip in my Apptainer definition file.

# Build and install xgboost with GPU support
wget https://github.com/dmlc/xgboost/releases/download/v2.1.3/xgboost_r_gpu_linux_2.1.3.tar.gz    
Rscript -e "install.packages(c('data.table', 'jsonlite'))"
R CMD INSTALL ./xgboost_r_gpu_linux_2.1.3.tar.gz

# Install R packages (mimicking rocker/ml-verse setup)
Rscript -e "install.packages(c('pak', 'devtools'))"
Rscript -e "devtools::install_version('targets', version = '1.10.0')"
Rscript -e "pak::pak('mitchellmanware/parsnip@beethoven')"
Rscript -e "install.packages(c('tarchetypes', \
    'testthat', 'tidymodels', 'bonsai', 'qs2', \
    'torch', 'tidyverse', 'glmnet'))"
Rscript -e "options(timeout = 1800); torch::install_torch(version = 'latest', type = 'gpu')"
Rscript -e "pak::pak('tidymodels/brulee@gpu')"
Rscript -e "pak::pak('shikokuchuo/nanonext'); pak::pak('shikokuchuo/mirai')"
Rscript -e "pak::pak('wlandau/crew'); pak::pak('wlandau/crew.cluster')"
Rscript -e "pak::pak('NIEHS/beethoven@dev-mm-0108')"

@EmilHvitfeldt
Copy link
Member

thank you! that will be helpful. we are working on making sure that parsnip work with CRAN versions of xgboost once it comes out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants