The Story

TensorFlow vs PyTorch




TensorFlow and PyTorch are all machine learning frameworks. They are great tools suitable for machine learning engineering, but the comparison between them is a never-ending battle. In this write, you will get a fair and complete side-to-side comparison between them.


Overview:


1. What is each and each?

2. Deep comparison

  • Behind their back

  • Computational Graph Definition

  • Community and Learning Resources

  • Industrial Popularity

  • Deployment

  • Visualization

  • A Lookup into Full Ecosystem

3. Conclusion - which should you choose?


What is Each and Each?

TensorFlow is an open-source framework used to build deep learning models in a variety of fields such as computer vision, natural language processing, time series, generative networks, reinforcement learning, etc.


Same as TensorFlow, PyTorch is also an open-source framework used to build deep learning models in the same fields.


TensorFlow vs PyTorch: Deep comparison


Behind their back

TensorFlow was open-sourced in 2015 by Google Brain. Up to now, it powers most Google applications such as Google Map, Photos, Search, etc... Before TensorFlow, Google was using DistBelief as their main machine learning library and this is what later become TensorFlow.


TensorFlow can run on CPU (Central Processing Unit) and GPU (Graphical) Processing unit. It also supports all standard platforms: Linus, Windows, macOS, and mobile (Android and iOS).


PyTorch was open-sourced by Facebook AI Lab in 2016, one year after TensorFlow. No doubt to say that this is the backbone of Facebook and other social apps like Instagram.


PyTorch can also run on CPU and GPU, and also is available on Windows, macOS, and Linux. At the time of writing this, PyTorch had not stable availability for mobile (iOS and Android) but on its official site, there is a note that PyTorch Mobile is in a beta state and will be available anytime soon.


Computational Graph Comparison

This is the most technical comparison which clearly shows the differences between these two platforms. TensorFlow relies on static graphs whereas PyTorch relies on dynamic graphs.


When creating a model in TensorFlow, before running it, you have to create an empty graph (made of layers and connections) and define the shape of input data. You can't change the graph later. In PyTorch, you can define your graph and change it on go.


I spent a lot of time researching if TensorFlow has supports for dynamics graphs. I found that the recent version of TensorFlow has limited supports for dynamic computation but with Eager execution, you can have some customizations and model debugging options. PyTorch supports debugging fully because of its dynamic computation graph capability.


Community and learning resources

Both of these platforms have a supportive community, it's fair to say that since they are all widely used. In terms of comparisons, TensorFlow has a vibrant community compared to PyTorch, particularly because of being backed by Google. With movements and things like Google IO, TensorFlow Everywhere, it has got a lot of popularity.


The advantages of having a big community are vital when it comes to learning resources and finding solutions or supports to problems. This is why you will find more TensorFlow tutorials and courses than PyTorch.


Since we talked about resources, it would also be nice to add a note about the learning curve for getting started with these two tools. PyTorch being Pythonic, its learning curve may be small for someone who is starting out compared to TensorFlow. TensorFlow's high-level API is not also hard to learn, but the Pythonic purity of PyTorch makes it easy to learn for beginners.


Industrial and Research Popularity

PyTorch is favored in research, whereas TensorFlow gained popularity in industries to its simplicity and production-ready capability.


Nonetheless, things have changed a little bit. Some industries have shifted from TensorFlow to PyTorch in recent time (Example is OpenAI), and the research made with TensorFlow increased. They are both great frameworks.


In terms of big tech adaptions, they are all used. TensorFlow is used by industries like Twitter, LinkedIn, Intel, Nvidia, etc. Companies and organizations like Tesla, OpenAI, Udacity, Stanford University, Salesforce are using PyTorch.


Deployment

The comparison starts to diverge when it comes to deployment and later point. Deploying models in TensorFlow is not a brainer in a whole range of platforms, even in mobile and web. It has TensorFlow Extended (TFX) which is designed to create and manage production Machine Learning pipelines.


PyTorch doesn't have something similar. With its TorchServe (which is still experimental), you still have to use things like Flask or REST API.


Nonetheless, both of these supports distributed training.


Visualization

This is where there is also a clear difference in the comparison of these giants. In Machine Learning experimentation, there is a need to visualize data, model metrics (such as loss and accuracy), the layout of the graph, or even the model parameters (weights and biases). TensorBoard by TensorFlow makes all of that possible, and it is easy to integrate it into the model.


To visualize the above scenarios, either metrics or graph, in PyTorch, you would need to use Python Visualization tools such as Matplotlib or Seaborn. It is also possible to integrate TensorBoard in PyTorch.


A Lookup into Full Ecosystem

Before we wrap up this comparison, it would be good to tap into the one to one ecosystem or tools provided by either TensorFlow and PyTorch.


Both are quite rich and they have an enormous ecosystem, full of tools, libraries, and resources around the model building, privacy and explainability, and various integrations. Learn more about TensorFlow and PyTorch Ecosystem.


Conclusion: Which should you choose?

Both TensorFlow and PyTorch have been improving since the day they were open-sourced. If you have read the whole article, you may have seen that each platform is content enough in what they are built for which is building and shipping machine learning models.


If you are in a battle of choosing which to learn, the advice that most world-class practitioners give is to choose one and stick with it for a while. After all, they both do the same things and they are tools.


Thank you for reading!

9 views0 comments