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

fix inflation of model object size on save #117

Merged
merged 4 commits into from
Apr 25, 2022
Merged

fix inflation of model object size on save #117

merged 4 commits into from
Apr 25, 2022

Conversation

simonpcouch
Copy link
Collaborator

Closes #116. :)

@simonpcouch
Copy link
Collaborator Author

library(tidymodels)
library(modeldata)
library(readr)
#> 
#> Attaching package: 'readr'
#> The following object is masked from 'package:yardstick':
#> 
#>     spec
#> The following object is masked from 'package:scales':
#> 
#>     col_factor
library(stacks)
library(butcher)

data("lending_club")

set.seed(1)
lending_club <- sample_n(lending_club, 1000)

folds <- vfold_cv(lending_club, v = 5)

lr_mod <- 
  linear_reg(penalty = tune(), mixture = tune()) %>%
  set_engine("glmnet") %>%
  workflow(
    preprocessor = funded_amnt ~ int_rate + total_bal_il,
    spec = .
  ) %>%
  tune_grid(
    resamples = folds,
    control = control_stack_grid(),
    grid = 4
  )

lr_stack <- stacks() %>%
  add_candidates(lr_mod) %>%
  blend_predictions() %>%
  fit_members()

write_rds(lr_stack, file = "saved_mod.Rds")

saved_lr_stack <- read_rds("saved_mod.Rds")

weigh(lr_stack)
#> # A tibble: 374 × 2
#>    object                                                              size
#>    <chr>                                                              <dbl>
#>  1 member_fits.lr_mod_1_3.pre.actions.formula.blueprint.mold.process 0.0172
#>  2 member_fits.lr_mod_1_3.pre.mold.blueprint.mold.process            0.0172
#>  3 member_fits.lr_mod_1_1.pre.actions.formula.blueprint.mold.process 0.0172
#>  4 member_fits.lr_mod_1_1.pre.mold.blueprint.mold.process            0.0172
#>  5 coefs.spec.method.pred.numeric.post                               0.0154
#>  6 member_fits.lr_mod_1_3.fit.fit.spec.method.pred.numeric.post      0.0154
#>  7 member_fits.lr_mod_1_1.fit.fit.spec.method.pred.numeric.post      0.0154
#>  8 member_fits.lr_mod_1_3.pre.actions.formula.blueprint.forge.clean  0.0139
#>  9 member_fits.lr_mod_1_3.pre.mold.blueprint.forge.clean             0.0139
#> 10 member_fits.lr_mod_1_1.pre.actions.formula.blueprint.forge.clean  0.0139
#> # … with 364 more rows
weigh(saved_lr_stack)
#> # A tibble: 374 × 2
#>    object                                                              size
#>    <chr>                                                              <dbl>
#>  1 member_fits.lr_mod_1_3.pre.actions.formula.blueprint.mold.process 0.0172
#>  2 member_fits.lr_mod_1_3.pre.mold.blueprint.mold.process            0.0172
#>  3 member_fits.lr_mod_1_1.pre.actions.formula.blueprint.mold.process 0.0172
#>  4 member_fits.lr_mod_1_1.pre.mold.blueprint.mold.process            0.0172
#>  5 coefs.spec.method.pred.numeric.post                               0.0154
#>  6 member_fits.lr_mod_1_3.fit.fit.spec.method.pred.numeric.post      0.0154
#>  7 member_fits.lr_mod_1_1.fit.fit.spec.method.pred.numeric.post      0.0154
#>  8 member_fits.lr_mod_1_3.pre.actions.formula.blueprint.forge.clean  0.0139
#>  9 member_fits.lr_mod_1_3.pre.mold.blueprint.forge.clean             0.0139
#> 10 member_fits.lr_mod_1_1.pre.actions.formula.blueprint.forge.clean  0.0139
#> # … with 364 more rows

Created on 2022-04-25 by the reprex package (v2.0.1)

@simonpcouch simonpcouch merged commit 30f46b5 into main Apr 25, 2022
@simonpcouch simonpcouch deleted the model-memory branch April 25, 2022 19:57
@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saved model memory issue
1 participant