autorope / donkeycar

Open source hardware and software platform to build a small scale self driving car.
http://www.donkeycar.com
MIT License
3.05k stars 1.28k forks source link

Accelerate tensorflow on Mac #1154

Open cfox570 opened 6 months ago

cfox570 commented 6 months ago

The Mac install should include tensorflow-metal to leverage the builtin GPU capability and accelerate training.

Ezward commented 5 months ago

Relevant links

Ezward commented 5 months ago

As of DonkeyCar 5.0, we are on Python 3.9 and Tensorflow 2.9. Tensorflow 2.9 dictates that we install tensorflow-macos 2.9.0. Once we move the Tensorflow >= 2.13 then we would just install vanilla tensorflow, rather than tensorflow-macos.

In both cases we should install the corresponding tensorflow-metal version to enable the use of Apple Silicon.

DocGarbanzo commented 5 months ago

As of DonkeyCar 5.0, we are on Python 3.9 and Tensorflow 2.9. Tensorflow 2.9 dictates that we install tensorflow-macos 2.9.0. Once we move the Tensorflow >= 2.13 then we would just install vanilla tensorflow, rather than tensorflow-macos.

In both cases we should install the corresponding tensorflow-metal version to enable the use of Apple Silicon.

I believe we only need to change the following line in setup.cfg: tensorflow-macos==2.9 to tensorflow-metal==0.5 which should then pull tensorflow-macos through pip dependencies automatically. I've dry-run that on my MacBook Intel which of course does not work but at least I'm getting the pip error messages & I can see what it tries to do.

cfox570 commented 5 months ago

We should install tensorflow-macos and tensorflow-metal on both Intel and Apple Silicon. I submitted a pull request with the change to setup.py. I understand if you don't need to specify tensorflow-macos but make the change to the docs for both Mac architectures.

Ezward commented 1 month ago

We now install tensorflow-mac-os=2.15.*. @DocGarbanzo is in the process of releasing Donkey 5.2, so perhaps this could get into that release;

cfox570 commented 1 month ago

The versions of tensorflow are compiled for all platforms including macOS ARM and macOS Intel. So there is no need for the unique specifier tensorflow-macos though that continues to reference the ARM versions of tensorflow. I have tested both the ARM and INTEL versions of Mac platforms and neither one works properly with tensorflow-metal. If you look at the pypi.org page, you will notice that version tensorflow-metal 1.1.0 is specified for tensorflow 2.14. When I run a training scripts the errors values explodes. I did find a comment on the internet that there is a bug in tensorflow-metal . I am watching tensorflow-metal to see a new version is released that will correct the issue. Note that tensorflow 2.16 installs Keras 3.0 which may requires some changes to Keras training. I welcome your comments. Maybe I have missed something.