rstudio / pins-r

Pin, Discover and Share Resources
https://pins.rstudio.com
Other
301 stars 62 forks source link

Support `board_deparse` for Google Drive #820

Open aephidayatuloh opened 6 months ago

aephidayatuloh commented 6 months ago

Hi,

I use google drive as a board and get error when write plumber.

library(pins)
library(vetiver)
library(plumber)

mc <- lm(mpg ~., data = mtcars)
v <- vetiver_model(model = mc, "mtcars")

model_board <- board_gdrive("https://drive.google.com/drive/folders/1NjzouASz0omeWbejGj0r2p3TzsVhAeTN")

model_board |> 
  vetiver_pin_write(v)

pr() |> 
  vetiver_api(v, debug = TRUE) 
vetiver_write_plumber(model_board, "mtcars", rsconnect = FALSE)
Error in `pins::board_deparse()`:
! This board doesn't support deparsing
Run `rlang::last_trace()` to see where the error occurred.

> rlang::last_trace()
<error/rlang_error>
Error in `pins::board_deparse()`:
! This board doesn't support deparsing
---
Backtrace:
    ▆
 1. └─vetiver::vetiver_write_plumber(model_board, "mtcars", rsconnect = FALSE)
 2.   ├─rlang::expr_deparse(pins::board_deparse(board))
 3.   │ └─rlang:::quo_deparse(x, deparser)
 4.   │   └─rlang::is_quosure(x)
 5.   ├─pins::board_deparse(board)
 6.   └─pins:::board_deparse.pins_board(board)
Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.
> packageVersion("pins")
[1] ‘1.3.0’
> packageVersion("vetiver")
[1] ‘0.2.5’
> packageVersion("plumber")
[1] ‘1.2.1’

Anyone can help me to understand and solve this problem? Thank you.

juliasilge commented 6 months ago

Ah, what is happening here is that vetiver_write_plumber() is trying to automatically generate a plumber file for you, but the Google Drive pins board doesn't support that kind of automated code generation because we don't have a method for it in pins.

The main reason we haven't added that is that Google Drive is S L O W for reading big objects like models (even for small files, too, in my experience) and I don't expect it to be useful for realistic use cases. If you use Google Drive to store your model, it will take a really long time for your vetiver API to be up and ready to go. In the framing of my recent MLOps talk, it will have really terrible performance in the software sense (not statistical sense).

Is it possible for you to use another pins backend to store your model? One more suited to serving predictions via an API? Or can you share a little more about why you are wanting to use Google Drive?

aephidayatuloh commented 5 months ago

Thank you @juliasilge for your explanation.

First, I'm new to vetiver but I found it is very useful. I'm just trying to use Google Drive as my board because my company uses Google Drive as cloud storage services. So Ithink "why not I use it to store my model?". FYI, I've successfully deploy vetiver model using pins board_folder().

If I still want to use Google Drive as my board, can I just use board_folder() to generate model file, plumber.R, dockerfile and vetiver_renv.lock and then upload all the files to my gdrive manually So I still can use gdrive as my board? And how about the computational performance after my API ready?

juliasilge commented 5 months ago

I am afraid that Google Drive will be just super duper slow no matter how you use it, but certainly your constraints might be different than what I am picturing.

Would you be willing to try this out:

If this works OK for your constraints, then certainly I could add the board_deparse method to pins so this will work more as you expected it to.