Effacer les filtres
Effacer les filtres

Why is Matlab deep learning so much slower than Tensorflow in Python

74 vues (au cours des 30 derniers jours)
Steven
Steven le 9 Nov 2023
Commenté : Steven le 21 Nov 2023

Dear all,
I have created an identical neural net in Matlab and in Tensorflow.
I want to use the Matlab implementation as it is needed in a bigger project.
However, the Matlab implementation is 20x slower to converge than the Tensorflow implementation while also having a higher loss.
Can anyone explain me why this could happen?
I am using a fully connected network with 5 layers and relu activations and use Adam to train the network. The parameters and the network are identical for the implementations.

Thank you in advance!

Best, Steven

  3 commentaires
Steven
Steven le 16 Nov 2023
Modifié(e) : Steven le 16 Nov 2023
I will upload the code in the question.
By 20 times slower that I train the model both with the Python code and Matlab code for 50,000 iterations. The Python implementation takes about 1 minute to train whereas the Matlab implementation takes 20+ minutes to train.
So the execution time of a training iteration is significantly slower.
I hope that this clarifies my question.
(P.S. Unfortunately, I cannot upload files for another 24 hours so I will upload the code tomorrow.)
Steven
Steven le 21 Nov 2023
Here is the code that I am using.
Any help is much appreciated!

Connectez-vous pour commenter.

Réponses (1)

atharva
atharva le 13 Nov 2023
Hey Steven,
I understand that you are facing an issue where the Matlab implementation is 20x slower to converge than the Tensorflow implementation.
You can try the GPU Coder which has been tested to run about 2X as fast as Tensorflow on average. If you do not have the toolbox, you can test out a trial version to see how the performance compares. There are instances where GPU Coder code runs multiple times faster than MATLAB code. An example of this is shown in the video from the following documentation page:
For an introduction to using the GPU Coder for deep learning, please see the following documentation pages:
Please note that there are some prerequisites for installing GPU Coder. For a complete list, please see the documentation page below:
Please note that many factors affect the run time, including the GPU, the original MATLAB code, and the optimization settings selected in GPU Coder, so we cannot guarantee a speed up from using GPU Coder instead of the Deep Learning Toolbox.
I hope this helps!
  1 commentaire
Steven
Steven le 16 Nov 2023
Hi atharva,
Thank you for your answer.
Unfortunately, for this project I cannot use a GPU as the project is part of a bigger project which will run on a distributed system using many (10000+) CPU's.
However, thank you for your suggestion!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by