dfalbel / torch

torch from R!
http://dfalbel.github.io/torch
Other
51 stars 5 forks source link

Error handling #27

Closed dfalbel closed 5 years ago

dfalbel commented 5 years ago

For some reason, on travis and on my Mac, when an error is raised from libtorch the error is printed in the R console, for example:

>   x <- tensor(runif(100), requires_grad = TRUE)
>   s <- tensor(runif(100))
>   x$sub_(s)
 Error in tensor_sub_tensor__(self$pointer, other$pointer, alpha) : 
  a leaf Variable that requires grad has been used in an in-place operation. (check_inplace at /Users/administrator/nightlies/pytorch-1.0.0/wheel_build_dirs/libtorch_2.7/pytorch/torch/csrc/autograd/VariableTypeUtils.h:49)
frame #0: c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 135 (0x119712f37 in libc10.dylib)
frame #1: torch::autograd::check_inplace(at::Tensor const&) + 231 (0x116947137 in libtorch.1.dylib)
frame #2: torch::autograd::VariableType::sub_(at::Tensor&, at::Tensor const&, c10::Scalar) const + 109 (0x1169c954d in libtorch.1.dylib)
frame #3: tensor_sub_tensor__(Rcpp::XPtr<at::Tensor, Rcpp::PreserveStorage, &(void Rcpp::standard_delete_finalizer<at::Tensor>(at::Tensor*)), false>, Rcpp::XPtr<at::Tensor, Rcpp::PreserveStorage, &(void Rcpp::standard_delete_finalizer<at::Tensor>(at::Tensor*)), false>, SEXPREC*) + 130 (0x1167fc232 in torch.so)
frame #4: _torch_tensor_sub_tensor__ + 109 

On my ubuntu, I hav a seg fault:

 *** caught segfault ***
address 0x54, cause 'memory not mapped'

Traceback:
 1: .Call("_torch_tensor_sub_tensor__", PACKAGE = "torch", x, other,     alpha)
 2: tensor_sub_tensor__(self$pointer, other$pointer, alpha)
 3: x$sub_(s)
 4: eval_bare(get_expr(quo), get_env(quo))
 5: doTryCatch(return(expr), name, parentenv, handler)
 6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 7: tryCatchList(expr, classes, parentenv, handlers)
 8: tryCatch({    code    NULL}, error = function(e) e)
 9: capture(act$val <- eval_bare(get_expr(quo), get_env(quo)))
10: quasi_capture(enquo(object), capture_error, label = label)
11: expect_error(x$sub_(s))
12: eval(code, test_env)
13: eval(code, test_env)
14: withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error)
15: doTryCatch(return(expr), name, parentenv, handler)
16: tryCatchOne(expr, names, parentenv, handlers[[1L]])
17: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
18: doTryCatch(return(expr), name, parentenv, handler)
19: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
20: tryCatchList(expr, classes, parentenv, handlers)
21: tryCatch(withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error), error = handle_fatal,     skip = function(e) {    })
22: test_code(desc, code, env = parent.frame())
23: test_that("grad_mode works", {    x <- tensor(runif(100), requires_grad = TRUE)    s <- tensor(runif(100))    expect_error(x$sub_(s))    expect_silent(with_no_grad(x$sub_(s)))})
24: eval(code, test_env)
25: eval(code, test_env)
26: withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error)
27: doTryCatch(return(expr), name, parentenv, handler)
28: tryCatchOne(expr, names, parentenv, handlers[[1L]])
29: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
30: doTryCatch(return(expr), name, parentenv, handler)
31: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
32: tryCatchList(expr, classes, parentenv, handlers)
33: tryCatch(withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error), error = handle_fatal,     skip = function(e) {    })
34: test_code(NULL, exprs, env)
35: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
36: force(code)
37: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter,     {        lister$start_file(basename(path))        source_file(path, new.env(parent = env), chdir = TRUE,             wrap = wrap)        end_context()    })
38: FUN(X[[i]], ...)
39: lapply(paths, test_file, env = env, reporter = current_reporter,     start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
40: force(code)
41: with_reporter(reporter = current_reporter, results <- lapply(paths,     test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE,     load_helpers = FALSE, wrap = wrap))
42: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure,     stop_on_warning = stop_on_warning, wrap = wrap)
43: (function (path, filter = NULL, reporter = default_reporter(),     env = test_env(), ..., encoding = "unknown", load_helpers = TRUE,     stop_on_failure = FALSE, stop_on_warning = FALSE, wrap = TRUE) {    if (!missing(encoding) && !identical(encoding, "UTF-8")) {        warning("`encoding` is deprecated; all files now assumed to be UTF-8",             call. = FALSE)    }    if (load_helpers) {        source_test_helpers(path, env)    }    source_test_setup(path, env)    on.exit(source_test_teardown(path, env), add = TRUE)    withr::local_envvar(list(R_TESTS = "", TESTTHAT = "true"))    if (identical(Sys.getenv("NOT_CRAN"), "true")) {        withr::local_options(list(lifecycle_verbose_retirement = TRUE))    }    paths <- find_test_scripts(path, filter, ...)    test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure,         stop_on_warning = stop_on_warning, wrap = wrap)})("/home/dani/torch/tests/testthat", filter = NULL, env = <environment>,     load_helpers = FALSE)
44: do.call(testthat::test_dir, testthat_args)
45: force(code)
46: withr::with_envvar(r_env_vars(), do.call(testthat::test_dir,     testthat_args))
47: force(code)
48: withr::with_options(c(useFancyQuotes = FALSE), withr::with_envvar(r_env_vars(),     do.call(testthat::test_dir, testthat_args)))
49: devtools::test()
An irrecoverable exception occurred. R is aborting now ...

Does anyone have any idea of what could cause this?

dfalbel commented 5 years ago

I can now reproduce the problem on travis. Something different Ubuntu Xenial vs Ubuntu trusty is causing the problem.

dfalbel commented 5 years ago

I opened an SO post here

dfalbel commented 5 years ago

The solution is to use an older version of g++, eg. g++-4.9. I will add note to the docs.