Training neural network is not working on GPU
I'm having trouble with training mlp() specification by brulee. I know that brulee uses torch and I checked my torch & gpu relationship, seems okay. But in the example below, training goes on CPU.
suppressPackageStartupMessages({
library(tidymodels)
library(torch)
})
torch::cuda_is_available()
#> TRUE
torch::cuda_device_count()
#> [1] 1
set.seed(1)
modspec <- mlp(hidden_units = tune(),
penalty = tune(),
epochs = tune(),
activation = tune(),
learn_rate = tune()) %>%
set_mode('classification') %>%
set_engine('brulee')
fk_param <- modspec %>%
extract_parameter_set_dials %>%
grid_max_entropy(size = 50)
spl_obj <- initial_split(iris,.7)
cv_obj <- vfold_cv(training(spl_obj),5)
rcp <- recipe(formula = Species ~
Sepal.Width +
Sepal.Length +
Petal.Width +
Petal.Length,
data = training(spl_obj)) %>%
step_normalize(all_numeric_predictors())
wf <- workflow() %>%
add_model(modspec) %>%
add_recipe(rcp)
cv_fit <- wf %>%
tune_grid(resamples = cv_obj,grid = fk_param)
Hmmm, that sounds frustrating @sametsoekel!
- Can you train a "bare" torch model like this one or this one using your GPU?
- Can you train an unwrapped (non-parsnip) brulee model like this one using your GPU?
Hmmm, that sounds frustrating @sametsoekel!
- Can you train a "bare" torch model like this one or this one using your GPU?
- Can you train an unwrapped (non-parsnip) brulee model like this one using your GPU?
Hi @juliasilge I tried to train the first example you attached. At the beginning of training %4 of my GPU is used, about 5 minutes later I saw %15 of my GPU is being used. Shortly, I can say yes. I'm going to let you know if unwrapped brulee model still using my GPU.
Update :
I tried unwrapped brulee model you attached also, and set the epochs 200. While training, my GPU is never used.
Thanks for interest
Thank you @sametsoekel! That sounds like it is an issue with brulee then. 👍
I suspect this is because brulee pre-dates luz. It doesn't look like brulee does anything to auto-switch between cpu and gpu. For example, there would have to be code to switch between cpu and gpu as needed in here: https://github.com/tidymodels/brulee/blob/main/R/mlp-fit.R#L635
I think this might require a pretty big refactor to implement, although you might be able to do the switching based on cuda_is_available (I've already forgotten how to do that cleanly without luz, I'm spoiled!).
@sametsoekel Thanks for filing the issue. We currently don't support GPU's in brulee, we'll add support for it soon and let you know here.
Thank you all for the precious attention, I'll be looking forward to the feature being added.