Device-agnostic code and using Mac M1 and M2 Chips on TensorFlow


Even though I tried to look at documentation and tutorials on the net, I failed to find a good tutorial or documentation on this topic. How can I create a device agnostic code so that I can use Mac M1 GPU easily?

1 Like

The code for TensorFlow is mostly device agnostic. The underline framework of Tensorflow is taking care of the device part for you. Please take this example on M1.

You just need to use tensorflow-macos and tensorflow-metal packages.

The same tensorflow code runs on different devices.

As I stated mostly, because the device or accelerator ID need to be changed in case of distributed training, but most case on a single host no further code modification are necessary.

Hope this can be helpful for you.