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

Patterns do not marshal properly #1266

Closed
wlandau opened this issue Apr 13, 2024 · 3 comments
Closed

Patterns do not marshal properly #1266

wlandau opened this issue Apr 13, 2024 · 3 comments
Assignees

Comments

@wlandau
Copy link
Member

wlandau commented Apr 13, 2024

The cause of #1264 and njtierney/geotargets#52 is actually a bug in targets. It turns out that aggregates of dynamic branches are unaware of marshaling. I am surprised this went unnoticed for so long. Anyway, here is a reprex with torch:

# _targets.R
library(targets)
tar_option_set(controller = crew::crew_controller_local())
list(
  tar_target(x, c(1L, 2L)),
  tar_target(
    y,
    torch::torch_tensor(x),
    pattern = map(x),
    format = "torch",
    iteration = "list",
    storage = "worker",
    retrieval = "worker"
  ),
  tar_target(
    z,
    y[[1]] + y[[2]],
    format = "torch",
    storage = "worker",
    retrieval = "main"
  )
)
# R console
> library(targets)
> tar_make()
▶ dispatched target xcompleted target x [0.005 seconds]
▶ dispatched branch y_5015dfa5778ec11dcompleted branch y_5015dfa5778ec11d [1.487 seconds]
▶ dispatched branch y_5ea9d15a285adf66completed branch y_5ea9d15a285adf66 [0 seconds]
● completed pattern ydispatched target zerrored target zerrored pipeline [5.649 seconds]
Error:
! Error running targets::tar_make()
Error messages: targets::tar_meta(fields = error, complete_only = TRUE)
Debugging guide: https://books.ropensci.org/targets/debugging.html
How to ask for help: https://books.ropensci.org/targets/help.html
Last error message:
    external pointer is not valid
Last error traceback:
    `+.torch_tensor`(y[[1]], y[[2]])
    torch_add(e1, e2)
    call_c_function(fun_name = "add", args = args, expected_types = expected...
    do_call(f, args)
    do.call(fun, args)
    (function (self, other, alpha)  {     .Call(`_torch_cpp_torch_namespace_...
    stop(list("external pointer is not valid", (function (self, other,      ...
    (function (condition)  {     state$error <- build_message(condition)    ...
@wlandau wlandau self-assigned this Apr 13, 2024
@wlandau
Copy link
Member Author

wlandau commented Apr 13, 2024

If storage is "main" in the last target, I get the original error reported:

# _targets.R
library(targets)
tar_option_set(controller = crew::crew_controller_local())
list(
  tar_target(x, c(1L, 2L)),
  tar_target(
    y,
    torch::torch_tensor(x),
    pattern = map(x),
    format = "torch",
    iteration = "list",
    storage = "worker",
    retrieval = "worker"
  ),
  tar_target(
    z,
    y[[1]] + y[[2]],
    format = "torch",
    storage = "main",
    retrieval = "main"
  )
)
# R console
> tar_make()
▶ dispatched target xcompleted target x [0.011 seconds]
▶ dispatched branch y_5015dfa5778ec11dcompleted branch y_5015dfa5778ec11d [0.943 seconds]
▶ dispatched branch y_5ea9d15a285adf66completed branch y_5ea9d15a285adf66 [0 seconds]
● completed pattern ydispatched target zended pipeline [4.551 seconds]
Error:
! Error running targets::tar_make()
Error messages: targets::tar_meta(fields = error, complete_only = TRUE)
Debugging guide: https://books.ropensci.org/targets/debugging.html
How to ask for help: https://books.ropensci.org/targets/help.html
Last error message:
    target z error: no applicable method for 'torch_save' applied to an object of class "NULL"
Last error traceback:
    tryCatch(withCallingHandlers({ NULL saveRDS(do.call(do.call, c(readRDS("...
    tryCatchList(expr, classes, parentenv, handlers)
    tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), na...
    doTryCatch(return(expr), name, parentenv, handler)
    tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
    tryCatchOne(expr, names, parentenv, handlers[[1L]])
    doTryCatch(return(expr), name, parentenv, handler)
    withCallingHandlers({ NULL saveRDS(do.call(do.call, c(readRDS("/tmp/Rtmp...
    saveRDS(do.call(do.call, c(readRDS("/tmp/RtmpnrQQS4/callr-fun-8d1d70b5ac...
    do.call(do.call, c(readRDS("/tmp/RtmpnrQQS4/callr-fun-8d1d70b5ac59"), li...
    (function (what, args, quote = FALSE, envir = parent.frame()) { if (!is....
    (function (targets_function, targets_arguments, options, envir = NULL, s...
    tryCatch(out <- withCallingHandlers(targets::tar_callr_inner_try(targets...
    tryCatchList(expr, classes, parentenv, handlers)
    tryCatchOne(expr, names, parentenv, handlers[[1L]])
    doTryCatch(return(expr), name, parentenv, handler)
    withCallingHandlers(targets::tar_callr_inner_try(targets_function = targ...
    targets::tar_callr_inner_try(targets_function = targets_function, target...
    do.call(targets_function, targets_arguments)
    (function (pipeline, path_store, names_quosure, shortcut, reporter, seco...
    crew_init(pipeline = pipeline, meta = meta_init(path_store = path_store)...
    self$run_crew()
    self$iterate()
    self$conclude_worker_task()
    tar_assert_all_na(result$error, msg = paste("target", result$name, "erro...
    tar_throw_validate(msg %|||% default)
    tar_error(message = paste0(...), class = c("tar_condition_validate", "ta...
    rlang::abort(message = message, class = class, call = tar_empty_envir)
    signal_abort(cnd, .file)

@wlandau
Copy link
Member Author

wlandau commented Apr 13, 2024

I think this is now fixed in https://github.com/ropensci/targets/tree/1266, but I have to run non-automated regression tests to confirm.

@wlandau
Copy link
Member Author

wlandau commented Apr 14, 2024

Fixed in #1267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant