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

Add bundle support for LightGBM #55

Closed
EKtheSage opened this issue Aug 23, 2023 · 8 comments
Closed

Add bundle support for LightGBM #55

EKtheSage opened this issue Aug 23, 2023 · 8 comments
Labels
feature a feature request or enhancement

Comments

@EKtheSage
Copy link

I was able to save LightGBM to pin using vetiver, loading it from pin board seems to work too, but when it comes to prediction, I got an error below, it seems that the model was incorrectly saved.

v_mod <- vetiver_model(model_final, 'lightgbm_model',
                       description = 'lightgbm model',
                       save_prototype = FALSE)

board %>% 
  vetiver_pin_write(v_mod, check_renv = TRUE)

mod <- board %>% 
      vetiver_pin_read('lightgbm_model')

test_dat %>%
      dplyr::slice(1)  %>% 
      mutate(.pred = predict(mod$model, test_dat %>%
                               select(!!x) %>% as.matrix()))
Error in `mutate()`:
ℹ In argument: `.pred = predict(...)`.
Caused by error in `predictor$predict()`:
! Attempting to use a Booster which no longer exists. This can happen if you have called Booster$finalize() or 
if this Booster was saved with saveRDS(). To avoid this error in the future, use saveRDS.lgb.Booster() or 
Booster$save_model() to save lightgbm Boosters.
@juliasilge juliasilge transferred this issue from rstudio/vetiver-r Aug 23, 2023
@juliasilge
Copy link
Member

Thanks so much for the report @EKtheSage! This model needs to be "bundled" because it can't be saved directly as .rds.

@juliasilge juliasilge added the feature a feature request or enhancement label Aug 23, 2023
@juliasilge juliasilge changed the title Add LightGBM to vetiver Add bundle support for LightGBM Aug 23, 2023
@simonpcouch
Copy link
Collaborator

Some additional context at #24!

lightgbm 4.0.0 will include support for serialization via .rds in its upcoming release. 4.0.0 is already in PyPI and is in submission on CRAN. This should resolve itself soon, so I'd recommend we not move forward with lightgbm bundle methods. :)

@juliasilge
Copy link
Member

Ah, fantastic! Thank you so much @simonpcouch 🙌

I'll close this and we can reopen if we find further problems.

@EKtheSage you will want to wait to see when the new version of lightgbm makes it to CRAN:
https://cran.r-project.org/package=lightgbm

@jameslamb
Copy link

👋🏻 hi all, James from LightGBM here.

I heard from a friend who went to posit::conf that you all are waiting on {lightgbm} 4.x to get to CRAN, to take advantage of the ability to saveRDS() / readRDS() LightGBM models, added here: microsoft/LightGBM#4685

Just wanted to add... here's the relevant issue to follow to be notified of progress towards {lightgbm} v4.x making it to CRAN: microsoft/LightGBM#5987

We (and {xgboost}, dmlc/xgboost#9497 (comment)) are struggling to meet CRAN's changed practices around the use of multithreading in package code. Sorry for the delay.

@juliasilge
Copy link
Member

Thank you so much for the update @jameslamb! 🙌 Good luck as you work on the CRAN submission.

@simonpcouch
Copy link
Collaborator

LightGBM 4.2.0 on CRAN! https://cran.r-project.org/web/packages/lightgbm/index.html.

@jameslamb
Copy link

jameslamb commented Dec 11, 2023

Hey @simonpcouch thanks so much to you and your team for the help with this release!!!

Just note, I haven't announced this on social media or come back here to this issue yet because CRAN isn't done checking the submission.

Screen Shot 2023-12-11 at 1 14 58 PM

(https://cran.r-project.org/web/checks/check_results_lightgbm.html)

I'm also paranoid about calling a release to CRAN "done" so soon because I've observed cases where checks pass for every check flavor in that table, and then a few days later an error is reported for one of the extra checks like rchk or valgrind (https://cran.r-project.org/web/checks/check_issue_kinds.html).

But so far so good! 😁

@jameslamb
Copy link

@simonpcouch v4.2.0 of {lightgbm} passed all the CRAN main checks and binaries have been built for all the platforms CRAN supports: microsoft/LightGBM#6191 (comment)

You can safely rely on saveRDS() / readRDS() of Booster objects from {lightgbm} now 😁

We'll remove the old lightgbm::readRDS.lgb.Booster() and lightgbm::saveRDS.lgb.Booster() in an upcoming release.

@ me any time if you have questions or need help! And thanks again for all your help getting LightGBM v4.2.0 out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants