rstudio / vetiver-r

Version, share, deploy, and monitor models
https://rstudio.github.io/vetiver-r/
Other
180 stars 27 forks source link

vetiver_sm_build . Error in enc2utf8(data) : argument is not a character vector #256

Closed joscani closed 10 months ago

joscani commented 10 months ago

Hi. I've created a role with all sagemaker permissions . And I try to write docker using vetiver_sm_build. I've created an Ecr registry and in fact I've update a docker (not related with vetiver model) and use this docker in app runner. I've read this issue https://github.com/rstudio/vetiver-r/issues/215 but I have problems. My problem is with this when I try to use this from my local computer. My ecr is joscani-irlanda


execution_role <- "arn:aws:iam::969140037785:role/sagemaker-vetiver"

name = "bt_xgboost"

# Sends dockerfile to AWS Codebuild for docker build
image_uri <- vetiver_sm_build(
  board =  board,
  name = "bt_xgboost",
  # predict_args = predict_args,
  # docker_args = docker_args,
  repository = glue::glue("joscani_irlanda-{name}:{strftime(Sys.time(), '%Y-%m-%d')}") ,
  bucket = board$bucket,
  role = execution_role
)
- The lockfile is already up to date.  
Error in enc2utf8(data) : argument is not a character vector     

The role has been created using sagemakerfullaccess policy. Any idea. Thanks

juliasilge commented 10 months ago

I am predicting that you are seeing this error from here in the paws package, which is building up a signature for an AWS service when it is called. Both the S3 backend for the pins board and the smdocker R package use paws, so that doesn't help narrow it down a whole ton.

Can you walk through what vetiver_sm_build() does internally, step by step, and find out in more detail where the error is happening? If it is during vetiver_prepare_docker() I can definitely help debug but if it is from smdocker::sm_build() I may need to point you to that repo instead.

stefanlinner commented 10 months ago

Hello,

my guess would be that the repository name is not valid. In AWS I experienced that I'm not allowed to use "" (underscores) in names. So maybe try repository = glue::glue("joscani-irlanda-{name}:{strftime(Sys.time(), '%Y-%m-%d')}") instead. Maybe that already fixes your issue. Same for the name argument btw (I would in general try to avoid ).

If you make it run on your local computer, please let me know, as I'm also struggling, but at a different point (see #253) :)

joscani commented 10 months ago

@stefanlinner I don't think that the "_" is the problem.
Captura de pantalla_2023-11-04_08-44-08 . I have a docker image with a plumber inside this registry . A plumber api created to predict using a brms model, (without vetiver package) and it works fine, usin apprunner service.

joscani commented 10 months ago

Hi, again. I'm trying to run step by step. In vetiver_prepare_docker I don't understand the plumber.R generated file.

# Generated by the vetiver package; edit with care

library(pins)
library(plumber)
library(rapidoc)
library(vetiver)
c("b <- board_s3(bucket = \"taller-barna-ireland\", region = structure(\"eu-west-1\", tags = list(", "b <-     type = \"scalar\")))")
v <- vetiver_pin_read(b, "btxgboost", version = "20231105T075959Z-0f297")

#* @plumber
function(pr) {
    pr %>% vetiver_api(v, path = "/invocations")
}

How the objects defined inside the c function are passed to vetiver_pin? If I run this in my R console, it doesn't work

c("b <- board_s3(bucket = \"taller-barna-ireland\", region = structure(\"eu-west-1\", tags = list(", "b <-     type = \"scalar\")))")

Later I found that my error is in smdocker:::upload_zip_file and maybe in config <- smdocker:::smdocker_config() where I get

$credentials
$credentials$anonymous
[1] FALSE

$region
[1] "us-east-1"

$disable_ssl
[1] FALSE

Instead of the correct credentials. I'm going to check how smdocker_config works .

DyfanJones commented 10 months ago

@joscani if the error is coming from smdocker:::upload_zip_file please raise the ticket at https://github.com/DyfanJones/sm-docker/tree/main. I am more than happy to debug this.

config <- smdocker::smdocker_config() set and keep a consistent config for paws (for example: https://www.paws-r-sdk.com/docs/s3/). However we can work it out in the same smdocker ticket if that is ok :) I don't want to clog vetiver tickets with an error on my end :P

juliasilge commented 10 months ago

@joscani Oh, that would definitely be the problem! I am not currently able to reproduce this and would love some help tracking it down. Can you run this code with reprex(session_info = TRUE)?

library(vetiver)
library(pins)
tmp_plumber <- tempfile()
b <- board_temp(versioned = TRUE)
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear")
vetiver_pin_write(b, v)
#> Creating new version '20231106T171138Z-a34d4'
#> Writing to pin 'cars_linear'
#> 
#> Create a Model Card for your published model
#> • Model Cards provide a framework for transparent, responsible reporting
#> • Use the vetiver `.Rmd` template as a place to start
vetiver_write_plumber(b, "cars_linear", file = tmp_plumber)

cat(readr::read_lines(tmp_plumber), sep = "\n")
#> # Generated by the vetiver package; edit with care
#> 
#> library(pins)
#> library(plumber)
#> library(rapidoc)
#> library(vetiver)
#> b <- board_folder(path = "/var/folders/hv/hzsmmyk9393_m7q3nscx1slc0000gn/T/RtmprtXpz4/pins-59ba732f7ef5")
#> v <- vetiver_pin_read(b, "cars_linear", version = "20231106T171138Z-a34d4")
#> 
#> #* @plumber
#> function(pr) {
#>     pr %>% vetiver_api(v)
#> }

Created on 2023-11-06 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.1 (2023-06-16) #> os macOS Ventura 13.5.2 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Denver #> date 2023-11-06 #> pandoc 2.17.1.1 @ /usr/local/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> archive 1.1.5 2022-05-06 [1] CRAN (R 4.3.0) #> bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.0) #> bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.0) #> bundle 0.1.1.9000 2023-11-02 [1] local #> butcher 0.3.3 2023-08-23 [1] CRAN (R 4.3.0) #> cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> digest 0.6.33 2023-07-07 [1] CRAN (R 4.3.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.3.0) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1) #> fansi 1.0.5 2023-10-08 [1] CRAN (R 4.3.1) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) #> fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) #> hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) #> htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.1) #> jsonlite 1.8.7 2023-06-29 [1] CRAN (R 4.3.0) #> knitr 1.45 2023-10-30 [1] CRAN (R 4.3.1) #> later 1.3.1 2023-05-02 [1] CRAN (R 4.3.0) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) #> pins * 1.2.2.9000 2023-10-31 [1] Github (rstudio/pins-r@f6c6f50) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) #> plumber 1.2.1 2022-09-06 [1] CRAN (R 4.3.0) #> promises 1.2.1 2023-08-10 [1] CRAN (R 4.3.0) #> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.3.0) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.3.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.3.0) #> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> rappdirs 0.3.3 2021-01-31 [1] CRAN (R 4.3.0) #> Rcpp 1.0.11 2023-07-06 [1] CRAN (R 4.3.0) #> readr 2.1.4 2023-02-10 [1] CRAN (R 4.3.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0) #> rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0) #> rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.3.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) #> stringi 1.7.12 2023-01-11 [1] CRAN (R 4.3.0) #> styler 1.10.2 2023-08-29 [1] CRAN (R 4.3.0) #> swagger 3.33.1 2020-10-02 [1] CRAN (R 4.3.0) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) #> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0) #> tzdb 0.4.0 2023-05-12 [1] CRAN (R 4.3.0) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.1) #> vctrs 0.6.4 2023-10-12 [1] CRAN (R 4.3.1) #> vetiver * 0.2.4 2023-09-12 [1] CRAN (R 4.3.0) #> vroom 1.6.4 2023-10-02 [1] CRAN (R 4.3.1) #> webutils 1.1 2020-04-28 [1] CRAN (R 4.3.0) #> withr 2.5.2 2023-10-30 [1] CRAN (R 4.3.1) #> xfun 0.41 2023-11-01 [1] CRAN (R 4.3.1) #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
juliasilge commented 10 months ago

Turns out this is a bug in the latest version of vetiver! 🐛 😬

I believe I have a fix set up in #257 but if you are needing to deploy to SageMaker very immediately, I recommend installing back to vetiver 0.2.3 which is from before this bug was introduced:

pak::pak("vetiver@0.2.3")
juliasilge commented 10 months ago

You can now also install the development version of vetiver via pak::pak("rstudio/vetiver-r") to get this fix. Let me know if this does not fix the problem or you run into any further troubles!

joscani commented 10 months ago

Thanks @juliasilge . I'll check next weekend