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

pre-compute metrics_info(metrics) #642

Merged
merged 4 commits into from
Mar 20, 2023
Merged

pre-compute metrics_info(metrics) #642

merged 4 commits into from
Mar 20, 2023

Conversation

simonpcouch
Copy link
Contributor

The metrics_info helper is a small helper to reformat as_tibble.metric_set for easier filtering/selecting. It's reasonably fast, but was called in a couple places inside the tune_grid_loop_iter interior loops, so ends up being called thousands of times even for small grid searches. We can thus pre-compute that output and pass it as an argument to tune_grid_loop_iter. Note that this introduces merge conflicts with #641—glad to take care of that once we get there.

With main dev:

library(tidymodels)

set.seed(1)

bench::mark(
  total = fit_resamples(linear_reg(), mpg ~ ., bootstraps(mtcars, 100)),
  iterations = 5
)
#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 total         2.71s    2.73s     0.363    46.3MB     6.96

...with a 4% decrease in evaluation time with this PR:

#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 total          2.6s    2.62s     0.377    45.3MB     7.23

That effect is more substantial when tuning hyperparameters. :)

Created on 2023-03-17 with reprex v2.0.2

Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Looking good

@simonpcouch simonpcouch merged commit 009b433 into main Mar 20, 2023
@simonpcouch simonpcouch deleted the metrics-info branch March 20, 2023 15:14
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

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 Apr 4, 2023
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.

2 participants