Cannot access GPU with Tensorflow on MacOS

Open
#620 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
macos, python, r, tensorflow

Research direction

Start by reproducing the empty GPU result with tf$config$list_logical_devices('GPU') and review the provided reticulate::py_config(), tensorflow::tf_config(), and sessionInfo() diagnostics. Done means determining whether the reported Apple Silicon and TensorFlow setup can expose a GPU through the R interface, with the expected device listing or a documented limitation.

Written by the indexing model from the issue text.

Description

I would like to run Tensorflow on the GPUs of my Mac through RStudio.

library(tensorflow)
library(keras)
tf$config$list_logical_devices('GPU')

The return value is an empty list.
list()

For the CPU the return value is non-empty.

I have successfully installed tensorflow, and have also tried the development version

# install the development version of packages, in case the
# issue is already fixed but not on CRAN yet.
install.packages("pak")
pak::pak(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
if (is.null(reticulate::virtualenv_starter()))
   reticulate::install_python()
tensorflow::install_tensorflow()

This runs

tensorflow::as_tensor("Hello World")

/Users/cedlich/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/urllib3/init.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
warnings.warn(
tf.Tensor(b'Hello World', shape=(), dtype=string)

Diagnostics

reticulate::py_config()
tensorflow::tf_config()
reticulate::import("tensorflow")
reticulate::py_last_error()
sessionInfo()

python: /Users/cedlich/.virtualenvs/r-tensorflow/bin/python
libpython: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/config-3.9-darwin/libpython3.9.dylib
pythonhome: /Users/cedlich/.virtualenvs/r-tensorflow:/Users/cedlich/.virtualenvs/r-tensorflow
version: 3.9.6 (default, Feb 3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)]
numpy: /Users/cedlich/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/numpy
numpy_version: 2.0.2
tensorflow: /Users/cedlich/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/tensorflow

NOTE: Python version was forced by import("tensorflow")

tensorflow::tf_config()
TensorFlow v2.18.1 (/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/tensorflow)
Python v3.9 (
/.virtualenvs/r-tensorflow/bin/python)
reticulate::import("tensorflow")
Module(tensorflow)
reticulate::py_last_error()
NULL
sessionInfo()
R version 4.4.3 (2025-02-28)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] keras_2.15.0 tensorflow_2.16.0.9000

loaded via a namespace (and not attached):
[1] R6_2.6.1 base64enc_0.1-3 Matrix_1.7-2 lattice_0.22-6 reticulate_1.41.0.9001
[6] magrittr_2.0.3 rappdirs_0.3.3 generics_0.1.3 png_0.1-8 lifecycle_1.0.4
[11] ps_1.9.0 cli_3.6.4 processx_3.8.6 pak_0.8.0.1 grid_4.4.3
[16] zeallot_0.1.0 withr_3.0.2 tfruns_1.5.3 compiler_4.4.3 rprojroot_2.0.4
[21] here_1.0.1 rstudioapi_0.17.1 tools_4.4.3 whisker_0.4.1 Rcpp_1.0.14
[26] rlang_1.1.5 jsonlite_1.9.1

Dominant language
R
Stars
1.3k
Forks
316
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/tensorflow

All issues in rstudio/tensorflow

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.