TensorFlow slower using GPU then using CPU with M1 Pro

Hello,

I have recently bought the M1 Pro and installed Tensorflow using the indications of Apple.

I noted that training a simple NN with GPU was really slow (~30 secs per epoch). However, after forcing Tensorflow to use CPU I saw an incredible improvement (~3 secs per epoch).

I cannot believe that the difference is that much. Verified with the System Monitor and I saw Tensorflow using 100% of the GPU.

Could anyone assist me or enlighten me?

Please check below the code used to train this model.

Answered by Frameworks Engineer in 698204022

Hello, At lower batch sizes, Tensorflow on CPU may run faster than GPU. Increasing the batch size will increase performance on the GPU. Please refer to this post for a similar issue.

You do not specify the batch size in your fitting arguments. Try setting this to a high number.

Hello @iDron,

Indeed, that made a huge difference. After setting the batch size to high numbers (250, 500, 1000), I was able to see the real power of the GPU acceleration. I also found a comment from an engineer of Apple where suggest the same thing. Please refer to this post for the answer, where it suggest that on small batches the training on CPU may be faster.

Accepted Answer

Hello, At lower batch sizes, Tensorflow on CPU may run faster than GPU. Increasing the batch size will increase performance on the GPU. Please refer to this post for a similar issue.

TensorFlow slower using GPU then using CPU with M1 Pro
 
 
Q