Skip to content

TensorFlow with GPU acceleration on Mac #474

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
dkgaraujo opened this issue Jun 16, 2021 · 5 comments
Closed

TensorFlow with GPU acceleration on Mac #474

dkgaraujo opened this issue Jun 16, 2021 · 5 comments

Comments

@dkgaraujo
Copy link

Hi all,
This is a feature request. Google recently launched a plugin to TensorFlow that enables Metal-based GPU acceleration on Macs (both the AMD GPU and Apple silicon) (https://developer.apple.com/metal/tensorflow-plugin/). Perhaps it would be possible to implement it on the RStudio TensorFlow package.

Theoretically,

  • it would have to identify if the Mac is Intel-based or Apple silicon (the pip repository has different builds for each)
  • if it's Intel-based, then reticulate would need to create an environment with python 3.8. If it's Apple silicon, then it could be either v3.8 or 3.9

I would be willing to do a PR if someone from the team could give me any pointers/advice.

@t-kalinowski
Copy link
Member

Hi, thanks for filing.

I think it's great that Apple provides a build of Tensorflow optimized for some Mac computers. Users interested in using that build should follow the install instructions at the link and then point reticulate at the intended python, e.g, by starting their R session with

Sys.setenv(RETICULATE_PYTHON="~/tensorflow-metal/bin/python")

However, I don't think it's a good idea for this package to default to using the apple-provided build when installing tensorflow through the R packages install_tensorflow() function. A few thoughts about why:

a) I just tried those install instructions at that link on a x86 Mac (w/o an AMD GPU) and, no surprise to me, it didn't work. I don't have an ARM or AMD-GPU Mac at the moment so my ability to debug/maintain this will be limited.
b) This is pulling a custom binary seemingly built by Apple and distributed through a condo channel they control. Tensorflow is a fast moving train, and I don't have full faith that that conda channel will always match the current official release version of tensorflow.
c) The Apple provided instructions use miniforge, while r-tensorflow/reticulate uses miniconda. I'm not sure how difficult it will be to swap miniconda for miniforge, or point miniconda at a miniforge channel. (probably trivial, but see point (a)). Swapping out miniconda for miniforge I think is probably too disruptive a change for just this.
d) It seems inevitable (to me) that the official tensorflow package will soon support ARM Macs, and this miniforge build is just a temporary solution during the transition until that happens.

related: #465

@dkgaraujo
Copy link
Author

Thanks for the detailed feedback, @t-kalinowski. Makes sense, and I'm thankful for the practical info.

Just as a side info (not to reopen the issue), my understanding is that the binary is built by Google themselves in what seems to be a more permanent opening towards non-CUDA GPUs using their new PluggableDevices feature, which enables them to bypass the issue of supporting more GPUs without re-writing their core compute code.

@t-kalinowski
Copy link
Member

t-kalinowski commented Jun 16, 2021

Interesting, thank you for clarifying. However, after taking a closer look, I'm not sure that's right. Perhaps there is some other information you can share?

I am making inferences based on these clues:
a) the uploader listed here is 'apple': https://anaconda.org/apple/tensorflow-deps/files
b) the install instructions are hosted on an apple domain: https://developer.apple.com/metal/tensorflow-plugin/
c) the tensorflow-macos and tensorflow-metal packages appear to have been uploaded to pypi package by someone who I think is an apple employee.

@dkgaraujo
Copy link
Author

You are right, @t-kalinowski, thanks - my mistake. Google did the PluggableDevices, and individual hardware providers like Apple, Intel would build the respective plugins. Thanks again for correcting & sorry for any additional trouble.

@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!

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

No branches or pull requests

2 participants