Skip to content

M1 Mac appears to abort when running reticulate::py_module_available("tensorflow") #465

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

Closed
njtierney opened this issue May 10, 2021 · 8 comments

Comments

@njtierney
Copy link

I wasn't able to reproduce this running reprex as this crashes R, but when using the CRAN version of greta, when I run reticulate::py_module_available("tensorflow"), I get

This reprex appears to crash R.
See standard output and standard error for more details.

Standard output and error

 *** caught illegal operation ***
address 0x189ddd024, cause 'illegal trap'

Traceback:
 1: py_module_import(module, convert = convert)
 2: import(module)
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch({    import(module)    TRUE}, error = clear_error_handler(FALSE))
 7: reticulate::py_module_available("tensorflow")
 8: eval(expr, envir, enclos)
 9: eval(expr, envir, enclos)
10: withVisible(eval(expr, envir, enclos))
11: withCallingHandlers(withVisible(eval(expr, envir, enclos)), warning = wHandler,     error = eHandler, message = mHandler)
12: doTryCatch(return(expr), name, parentenv, handler)
13: tryCatchOne(expr, names, parentenv, handlers[[1L]])
14: tryCatchList(expr, classes, parentenv, handlers)
15: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if (!is.null(call)) {        if (identical(call[[1L]], quote(doTryCatch)))             call <- sys.call(-4L)        dcall <- deparse(call)[1L]        prefix <- paste("Error in", dcall, ": ")        LONG <- 75L        sm <- strsplit(conditionMessage(e), "\n")[[1L]]        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")        if (is.na(w))             w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],                 type = "b")        if (w > LONG)             prefix <- paste0(prefix, "\n  ")    }    else prefix <- "Error : "    msg <- paste0(prefix, conditionMessage(e), "\n")    .Internal(seterrmessage(msg[1L]))    if (!silent && isTRUE(getOption("show.error.messages"))) {        cat(msg, file = outFile)        .Internal(printDeferredWarnings())    }    invisible(structure(msg, class = "try-error", condition = e))})
16: try(f, silent = TRUE)
17: handle(ev <- withCallingHandlers(withVisible(eval(expr, envir,     enclos)), warning = wHandler, error = eHandler, message = mHandler))
18: timing_fn(handle(ev <- withCallingHandlers(withVisible(eval(expr,     envir, enclos)), warning = wHandler, error = eHandler, message = mHandler)))
19: evaluate_call(expr, parsed$src[[i]], envir = envir, enclos = enclos,     debug = debug, last = i == length(out), use_try = stop_on_error !=         2L, keep_warning = keep_warning, keep_message = keep_message,     output_handler = output_handler, include_timing = include_timing)
20: evaluate::evaluate(...)
21: evaluate(code, envir = env, new_device = FALSE, keep_warning = !isFALSE(options$warning),     keep_message = !isFALSE(options$message), stop_on_error = if (is.numeric(options$error)) options$error else {        if (options$error && options$include)             0L        else 2L    }, output_handler = knit_handlers(options$render, options))
22: in_dir(input_dir(), evaluate(code, envir = env, new_device = FALSE,     keep_warning = !isFALSE(options$warning), keep_message = !isFALSE(options$message),     stop_on_error = if (is.numeric(options$error)) options$error else {        if (options$error && options$include)             0L        else 2L    }, output_handler = knit_handlers(options$render, options)))
23: eng_r(options)
24: block_exec(params)
25: call_block(x)
26: process_group.block(group)
27: process_group(group)
28: withCallingHandlers(if (tangle) process_tangle(group) else process_group(group),     error = function(e) {        setwd(wd)        cat(res, sep = "\n", file = output %n% "")        message("Quitting from lines ", paste(current_lines(i),             collapse = "-"), " (", knit_concord$get("infile"),             ") ")    })
29: process_file(text, output)
30: knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
31: rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8")
32: (function (input) {    rmarkdown::render(input, quiet = TRUE, envir = globalenv(),         encoding = "UTF-8")})(input = base::quote("soot-cub_reprex.R"))
33: (function (what, args, quote = FALSE, envir = parent.frame()) {    if (!is.list(args))         stop("second argument must be a list")    if (quote)         args <- lapply(args, enquote)    .Internal(do.call(what, args, envir))})(base::quote(function (input) {    rmarkdown::render(input, quiet = TRUE, envir = globalenv(),         encoding = "UTF-8")}), base::quote(list(input = "soot-cub_reprex.R")), envir = base::quote(<environment>),     quote = base::quote(TRUE))
34: do.call(do.call, c(readRDS("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-fun-9387fb88307"),     list(envir = .GlobalEnv, quote = TRUE)), envir = .GlobalEnv,     quote = TRUE)
35: saveRDS(do.call(do.call, c(readRDS("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-fun-9387fb88307"),     list(envir = .GlobalEnv, quote = TRUE)), envir = .GlobalEnv,     quote = TRUE), file = "/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1")
36: withCallingHandlers({    NULL    saveRDS(do.call(do.call, c(readRDS("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-fun-9387fb88307"),         list(envir = .GlobalEnv, quote = TRUE)), envir = .GlobalEnv,         quote = TRUE), file = "/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1")    flush(stdout())    flush(stderr())    NULL    invisible()}, error = function(e) {    {        callr_data <- as.environment("tools:callr")$`__callr_data__`        err <- callr_data$err        assign(".Traceback", .traceback(4), envir = callr_data)        dump.frames("__callr_dump__")        assign(".Last.dump", .GlobalEnv$`__callr_dump__`, envir = callr_data)        rm("__callr_dump__", envir = .GlobalEnv)        e$call <- deparse(conditionCall(e), nlines = 6)        e2 <- err$new_error(conditionMessage(e), call. = conditionCall(e))        class(e2) <- c("callr_remote_error", class(e2))        e2$error <- e        calls <- sys.calls()        dcframe <- which(vapply(calls, function(x) length(x) >=             1 && identical(x[[1]], quote(do.call)), logical(1)))[1]        if (!is.na(dcframe))             e2$`_ignore` <- list(c(1, dcframe + 1L))        e2$`_pid` <- Sys.getpid()        e2$`_timestamp` <- Sys.time()        if (inherits(e, "rlib_error_2_0"))             e2$parent <- e$parent        e2 <- err$add_trace_back(e2, embed = FALSE)        saveRDS(list("error", e2), file = paste0("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1",             ".error"))    }}, interrupt = function(e) {    {        callr_data <- as.environment("tools:callr")$`__callr_data__`        err <- callr_data$err        assign(".Traceback", .traceback(4), envir = callr_data)        dump.frames("__callr_dump__")        assign(".Last.dump", .GlobalEnv$`__callr_dump__`, envir = callr_data)        rm("__callr_dump__", envir = .GlobalEnv)        e$call <- deparse(conditionCall(e), nlines = 6)        e2 <- err$new_error(conditionMessage(e), call. = conditionCall(e))        class(e2) <- c("callr_remote_error", class(e2))        e2$error <- e        calls <- sys.calls()        dcframe <- which(vapply(calls, function(x) length(x) >=             1 && identical(x[[1]], quote(do.call)), logical(1)))[1]        if (!is.na(dcframe))             e2$`_ignore` <- list(c(1, dcframe + 1L))        e2$`_pid` <- Sys.getpid()        e2$`_timestamp` <- Sys.time()        if (inherits(e, "rlib_error_2_0"))             e2$parent <- e$parent        e2 <- err$add_trace_back(e2, embed = FALSE)        saveRDS(list("error", e2), file = paste0("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1",             ".error"))    }}, callr_message = function(e) {    try(signalCondition(e))})
37: doTryCatch(return(expr), name, parentenv, handler)
38: tryCatchOne(expr, names, parentenv, handlers[[1L]])
39: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
40: doTryCatch(return(expr), name, parentenv, handler)
41: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
42: tryCatchList(expr, classes, parentenv, handlers)
43: tryCatch(withCallingHandlers({    NULL    saveRDS(do.call(do.call, c(readRDS("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-fun-9387fb88307"),         list(envir = .GlobalEnv, quote = TRUE)), envir = .GlobalEnv,         quote = TRUE), file = "/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1")    flush(stdout())    flush(stderr())    NULL    invisible()}, error = function(e) {    {        callr_data <- as.environment("tools:callr")$`__callr_data__`        err <- callr_data$err        assign(".Traceback", .traceback(4), envir = callr_data)        dump.frames("__callr_dump__")        assign(".Last.dump", .GlobalEnv$`__callr_dump__`, envir = callr_data)        rm("__callr_dump__", envir = .GlobalEnv)        e$call <- deparse(conditionCall(e), nlines = 6)        e2 <- err$new_error(conditionMessage(e), call. = conditionCall(e))        class(e2) <- c("callr_remote_error", class(e2))        e2$error <- e        calls <- sys.calls()        dcframe <- which(vapply(calls, function(x) length(x) >=             1 && identical(x[[1]], quote(do.call)), logical(1)))[1]        if (!is.na(dcframe))             e2$`_ignore` <- list(c(1, dcframe + 1L))        e2$`_pid` <- Sys.getpid()        e2$`_timestamp` <- Sys.time()        if (inherits(e, "rlib_error_2_0"))             e2$parent <- e$parent        e2 <- err$add_trace_back(e2, embed = FALSE)        saveRDS(list("error", e2), file = paste0("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1",             ".error"))    }}, interrupt = function(e) {    {        callr_data <- as.environment("tools:callr")$`__callr_data__`        err <- callr_data$err        assign(".Traceback", .traceback(4), envir = callr_data)        dump.frames("__callr_dump__")        assign(".Last.dump", .GlobalEnv$`__callr_dump__`, envir = callr_data)        rm("__callr_dump__", envir = .GlobalEnv)        e$call <- deparse(conditionCall(e), nlines = 6)        e2 <- err$new_error(conditionMessage(e), call. = conditionCall(e))        class(e2) <- c("callr_remote_error", class(e2))        e2$error <- e        calls <- sys.calls()        dcframe <- which(vapply(calls, function(x) length(x) >=             1 && identical(x[[1]], quote(do.call)), logical(1)))[1]        if (!is.na(dcframe))             e2$`_ignore` <- list(c(1, dcframe + 1L))        e2$`_pid` <- Sys.getpid()        e2$`_timestamp` <- Sys.time()        if (inherits(e, "rlib_error_2_0"))             e2$parent <- e$parent        e2 <- err$add_trace_back(e2, embed = FALSE)        saveRDS(list("error", e2), file = paste0("/var/folders/fs/clgy1jd123b6cjk9ffx51tgdv5kdzr/T//Rtmpzkt86P/callr-res-93871aa248a1",             ".error"))    }}, callr_message = function(e) {    try(signalCondition(e))}), error = function(e) {    NULL    try(stop(e))}, interrupt = function(e) {    NULL    e})
An irrecoverable exception occurred. R is aborting now ...

This is also a laptop that (currently, at least), does not let me have administrator access, so it is possible that perhaps that is causing other issues?

system info is below:

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.5 (2021-03-31)
#>  os       macOS Big Sur 10.16         
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_AU.UTF-8                 
#>  ctype    en_AU.UTF-8                 
#>  tz       Australia/Perth             
#>  date     2021-05-10                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.0.2)
#>  cli           2.5.0   2021-04-26 [1] CRAN (R 4.0.2)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.2)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.0.2)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.1)
#>  fansi         0.4.2   2021-01-15 [1] CRAN (R 4.0.2)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.0.2)
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2)
#>  knitr         1.33    2021-04-24 [1] CRAN (R 4.0.2)
#>  lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.0.2)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.2)
#>  pillar        1.6.0   2021-04-13 [1] CRAN (R 4.0.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 4.0.2)
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 4.0.2)
#>  rmarkdown     2.8     2021-05-07 [1] CRAN (R 4.0.2)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.2)
#>  styler        1.4.1   2021-03-30 [1] CRAN (R 4.0.2)
#>  tibble        3.1.1   2021-04-18 [1] CRAN (R 4.0.2)
#>  utf8          1.2.1   2021-03-12 [1] CRAN (R 4.0.2)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.0.2)
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.2)
#>  xfun          0.22    2021-03-11 [1] CRAN (R 4.0.2)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)
#> 
#> [1] /Users/ntierney/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
@dfalbel
Copy link
Member

dfalbel commented May 10, 2021

See also rstudio/keras3#1210 and rstudio/keras3#1165

@juliasilge
Copy link
Member

@njtierney I was having the same problem! 😩

@dfalbel pointed me to this blog post where someone got TensorFlow up and running using pre-release binaries from Apple + the ARM release of R + the new preview release of RStudio. This worked for me!

library(keras)
library(tensorflow)
use_python("~/miniforge3/bin/python")
use_condaenv("tf_env")
reticulate::py_discover_config("tensorflow")
#> python:         /Users/juliasilge/miniforge3/envs/tf_env/bin/python
#> libpython:      /Users/juliasilge/miniforge3/envs/tf_env/lib/libpython3.8.dylib
#> pythonhome:     /Users/juliasilge/miniforge3/envs/tf_env:/Users/juliasilge/miniforge3/envs/tf_env
#> version:        3.8.10 | packaged by conda-forge | (default, May 11 2021, 06:27:18)  [Clang 11.1.0 ]
#> numpy:          /Users/juliasilge/miniforge3/envs/tf_env/lib/python3.8/site-packages/numpy
#> numpy_version:  1.20.3
#> tensorflow:     /Users/juliasilge/miniforge3/envs/tf_env/lib/python3.8/site-packages/tensorflow
#> 
#> python versions found: 
#>  /Users/juliasilge/miniforge3/bin/python
#>  /Users/juliasilge/miniforge3/envs/tf_env/bin/python
#>  /Users/juliasilge/miniforge3/envs/tf_env/bin/python3
#>  /usr/bin/python3
#>  /usr/bin/python

Created on 2021-05-26 by the reprex package (v2.0.0)

Here is some proof:
image

What I have tried so far (mostly models from SMLTAR) has worked, but a few things seem weird. For example, tensorflow::tf$random$set_seed(1234) gives an error.

@njtierney
Copy link
Author

Hi @juliasilge - thanks! I'll try this out and let you know how I go.

@t-kalinowski
Copy link
Member

The development version of tensorflow::install_tensorflow() (and keras::install_keras()) now has support for Arm Macs.
This should setup a working Tensorflow installation:

remotes::install_github("rstudio/tensorflow")
reticulate::install_miniconda()
tensorflow::install_tensorflow()

Please file an issue if you encounter errors!

@njtierney
Copy link
Author

OK! Will let you know how we go :)

@ginxyang
Copy link

Hi there, I am still having issues with having tensorflow working in my R studio.
I did the above

remotes::install_github("rstudio/tensorflow")
reticulate::install_miniconda()
tensorflow::install_tensorflow()

when I run

> library(tensorflow)
> tf$constant("Hellow Tensorflow")

the following is the trace:

 *** caught illegal operation ***
address 0x120170489, cause 'illegal opcode'

Traceback:
 1: py_module_import(module, convert = convert)
 2: import(module)
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch(import(module), error = clear_error_handler())
 7: py_resolve_module_proxy(x)
 8: `$.python.builtin.module`(tf, constant)
 9: tf$constant

@t-kalinowski
Copy link
Member

@ginxyang Can you please file a new issue? The "Installation Issue" template has some instructions for collecting information that is useful for troubleshooting these types of issues.

@ginxyang
Copy link

@ginxyang Can you please file a new issue? The "Installation Issue" template has some instructions for collecting information that is useful for troubleshooting these types of issues.

Thanks, I have opened new issues: #527

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

5 participants