Macbook Air M2 cannot use Tensorflow

Hi Guy

I face the problem that Macbook Air M2 cannot use Tensorflow via conda path. I have already followed the instruction on this link: https://developer.apple.com/metal/tensorflow-plugin/ but it still cannot work.

Can someone advise us ?

Replies

I would suggest to use an environment.yml file for your development, as described in: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file

Create a file named environment.yml in a new directory:

name: tensorflow-metal
channels:
  - apple
  - conda-forge
dependencies:
  - nomkl
  - tensorflow==2.9.1
  - tensorflow-deps==2.9
  - pip
  - pip:
    - tensorflow-macos
    - tensorflow-metal

Then run:

CONDA_SUBDIR=osx-arm64 conda env create -f environment.yml
conda activate tensorflow-metal

This will create the environment with ARM64 binaries and activate it.

If you need to add additional dependencies, be sure to specify them in the dependencies section of the file and then run:

conda env update -f environment.yml

Installing packages one-by-one (whether by pip or conda) can lead to the Intel MKL extensions being installed, which won't work on the ARM processor (note that nomkl is included to explicitly prevent this).

I've created a gist showing some Tensorflow debug output on my Macbook Air M2:

https://gist.github.com/corajr/a10af2f893c4b79275281f6b6fd915d3