{"id":14626,"date":"2021-01-22T04:25:24","date_gmt":"2021-01-22T12:25:24","guid":{"rendered":"https:\/\/www.springboard.com\/?p=14626"},"modified":"2023-09-28T00:13:25","modified_gmt":"2023-09-28T07:13:25","slug":"pytorch-vs-tensorflow","status":"publish","type":"post","link":"https:\/\/www.springboard.com\/blog\/data-science\/pytorch-vs-tensorflow\/","title":{"rendered":"PyTorch vs. TensorFlow: How Do They Compare?"},"content":{"rendered":"\n<p>You might be a machine learning project first-timer, a hardened AI veteran, or even a tenured professor researching state-of-the-art artificial intelligence\u2014at any skill level, you are likely knowledgeable about PyTorch or TensorFlow.<\/p>\n\n\n\n<p>But beyond what you already know, what are the key comparisons between PyTorch and TensorFlow? Which one is better for your project\u2019s needs? We\u2019ll explain the strengths of each and the best opportunities to apply them.<\/p>\n\n\n\n<p>Learn about the key differences between PyTorch and TensorFlow, and which one best suits your machine learning project.<\/p>\n\n\n\n<p>*Looking for the <strong>Colab Notebook<\/strong> for this post? Find it right here.*<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is TensorFlow? What is PyTorch?<\/h2>\n\n\n\n<p><a href=\"https:\/\/pytorch.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">PyTorch<\/a> and <a href=\"https:\/\/www.tensorflow.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">TensorFlow<\/a> are two of the biggest names in machine learning frameworks. They are tools to help you quickly design, evaluate, and deploy <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/beginners-guide-neural-network-in-python-scikit-learn-0-18\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/www.springboard.com\/blog\/data-science\/beginners-guide-neural-network-in-python-scikit-learn-0-18\/\" rel=\"noreferrer noopener\">neural networks<\/a> at competitive performance levels. PyTorch is primarily developed by <a href=\"https:\/\/ai.facebook.com\/tools\/pytorch\" target=\"_blank\" rel=\"noreferrer noopener\">Facebook\u2019s AI Research<\/a> (FAIR) group, while TensorFlow is overseen by <a href=\"https:\/\/ai.google\/tools\/#developers\" target=\"_blank\" rel=\"noreferrer noopener\">Google AI<\/a>.<\/p>\n\n\n\n<p>It\u2019s not surprising that both PyTorch and TensorFlow are popular, among the <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/what-does-a-data-scientist-do\/\" target=\"_blank\" data-type=\"post\" data-id=\"24427\" rel=\"noreferrer noopener\">Data Scientists<\/a> and ML Engineers, given that they\u2019re both developed by two of the biggest names on the Internet and in machine learning research. But their popularity extends beyond the name of their parent companies. PyTorch and TensorFlow are among the most advanced machine learning tools in the industry and are built off of many of the same ideas.<\/p>\n\n\n\n<p>For long-term support, both PyTorch and TensorFlow are open-source\u2014anyone with a Github account can contribute to the newest versions of both\u2014so the most recent research is often available instantaneously on each platform.<\/p>\n\n\n\n<p>Both PyTorch and TensorFlow have remained the fastest-in-class frameworks by performing as many of their computations as possible onto accelerated hardware such as GPUs (which are processors that can perform many operations in parallel). Both PyTorch and TensorFlow use the same GPU framework <a href=\"https:\/\/developer.nvidia.com\/cudnn\" target=\"_blank\" rel=\"noreferrer noopener\">cuDNN<\/a> by NVIDIA.<\/p>\n\n\n\n<p>Under-the-hood, PyTorch and TensorFlow also use a similar concept, dubbed <a href=\"http:\/\/bears.ece.ucsb.edu\/research-info\/DP\/dfg.html#:~:text=A%20data%2Dflow%20graph%20(DFG,algorithm%20assumes%20real%20roots)%3A\" target=\"_blank\" rel=\"noreferrer noopener\">data flow graphs<\/a>, to translate the code that you write into hardware-accelerated machine code. A data flow graph describes the mathematical operations necessary to compute a neural net\u2019s outputs, and the data flow graph can be inverted (which is a process known as automatic differentiation), to compute the infamous backpropagation of a neural net without requiring the developer to specify how gradients are computed.<\/p>\n\n\n<div class=\"bg-leaf-50 p-4 my-3\"><h4 class=\"fw-bold text-center\">Get To Know Other\tData Science Students<\/h4><div class=\"row row-cols-1 row-cols-lg-3\"><div class=\"col\"><div class=\"card success-story-card h-100 d-flex justify-content-between mb-0\"><div class=\"flex-grow-1 text-center\"><a class=\"d-inline-block rounded-circle\" href=\"\/success\/nick-lenczewski\" style=\"width:125px;height:125px;overflow:hidden\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/res.cloudinary.com\/springboard-images\/image\/upload\/v1667235351\/Student%20Success\/Nick_Lenczewski.jpg\" alt=\"Nick Lenczewski\" style=\"object-fit:contain;max-width:170px;height:125px\" \/><\/a><p class=\"fw-bold mb-0\">Nick Lenczewski<\/p><p class=\"text-muted lh-1\">Data Scientist at Ovative Group<\/p><\/div><div class=\"w-100 d-block d-md-none mt-3\"><\/div><p class=\"mb-0 mx-auto text-center\"><a class=\"btn btn-primary mx-auto\" href=\"\/success\/nick-lenczewski\">Read Story<\/a><\/p><\/div><\/div><div class=\"col d-none d-md-block\"><div class=\"card success-story-card h-100 d-flex justify-content-between mb-0\"><div class=\"flex-grow-1 text-center\"><a class=\"d-inline-block rounded-circle\" href=\"\/success\/leoman-momoh\" style=\"width:125px;height:125px;overflow:hidden\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/res.cloudinary.com\/springboard-images\/image\/upload\/v1629203191\/Student%20Success\/Leoman_Momoh_125x125.png\" alt=\"Leoman Momoh\" style=\"object-fit:contain;max-width:170px;height:125px\" \/><\/a><p class=\"fw-bold mb-0\">Leoman Momoh<\/p><p class=\"text-muted lh-1\">Senior Data Engineer at Enterprise Products<\/p><\/div><p class=\"mb-0 mx-auto text-center\"><a class=\"btn btn-primary mx-auto\" href=\"\/success\/leoman-momoh\">Read Story<\/a><\/p><\/div><\/div><div class=\"col d-none d-md-block\"><div class=\"card success-story-card h-100 d-flex justify-content-between mb-0\"><div class=\"flex-grow-1 text-center\"><a class=\"d-inline-block rounded-circle\" href=\"\/success\/jonathan-orr\" style=\"width:125px;height:125px;overflow:hidden\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/res.cloudinary.com\/springboard-images\/image\/upload\/v1629203194\/Student%20Success\/Jonathan_Orr_125x125.png\" alt=\"Jonathan Orr\" style=\"object-fit:contain;max-width:170px;height:125px\" \/><\/a><p class=\"fw-bold mb-0\">Jonathan Orr<\/p><p class=\"text-muted lh-1\">Data Scientist at Carlisle & Company<\/p><\/div><p class=\"mb-0 mx-auto text-center\"><a class=\"btn btn-primary mx-auto\" href=\"\/success\/jonathan-orr\">Read Story<\/a><\/p><\/div><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">TensorFlow vs. PyTorch: What&#8217;s the difference?<\/h2>\n\n\n\n<p>You\u2019ve seen now that PyTorch and TensorFlow share many of the same elements, but each has unique application opportunities.<\/p>\n\n\n\n<p>For one, TensorFlow has experienced the benefits of open-source contributions somewhat differently\u2014as community members have actively developed TensorFlow APIs in many languages beyond what TensorFlow officially supports\u2014and TensorFlow has been quick to embrace this development.<\/p>\n\n\n\n<p>PyTorch has less official support of its third-party adaptations but devotes its time to providing stability to non-Python languages. The following table summarizes this difference.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.springboard.com\/library\/static\/c1c9e2eed167c992924d16222889f1b6\/8c857\/screen-shot-2020-11-24-at-3.54.53-pm.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.springboard.com\/library\/static\/c1c9e2eed167c992924d16222889f1b6\/8c857\/screen-shot-2020-11-24-at-3.54.53-pm.png\" alt=\"pytorch vs. tensorflow\" title=\"pytorch vs. tensorflow\"\/><\/a><\/figure>\n\n\n\n<p>Historically, the data flow graphs of PyTorch and TensorFlow were generated differently. TensorFlow used to (pre-version 2.0) compile its data flow graphs before running computations on the data flow graph, known as a static graph. On the flip side, PyTorch used to build its data flow graph while it\u2019s executing, known as a dynamic graph. Nowadays, both PyTorch and TensorFlow can compute static or dynamic graphs, but their origins have allowed for slight advantages.<\/p>\n\n\n\n<p>Static graphs allow the framework to perform all the possible hardware optimizations for speed that it can before running code on hardware, but it loses some flexibility. For instance, if you need to alter the neural network architecture at runtime, in the instance of <a href=\"https:\/\/arxiv.org\/pdf\/2003.03033.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">Network Pruning<\/a> to shrink a model\u2019s size, then the framework must recompile the graph whereas a dynamic graph can get ahead\u2014think of it as TensorFlow making a pit stop mid-race. Since TensorFlow started out with static graphs, its static graphs are slightly more optimized than PyTorch.<\/p>\n\n\n\n<p>PyTorch distinguishes its dynamic data flow graphs from TensorFlow by using a technique known as data asynchronization to keep up to speed with static graphs on GPUs. PyTorch keeps track of how much data the GPU can handle at any given moment and adjusts what data is given to the GPU to ensure that it is always running at full power. TensorFlow\u2019s compilation may result in some decreased GPU compute loads during an execution, losing some speed as well.<\/p>\n\n\n\n<p>TensorFlow\u2019s big advantage over PyTorch lies in Google\u2019s very own <a href=\"https:\/\/cloud.google.com\/tpu\/docs\/tpus\" target=\"_blank\" rel=\"noreferrer noopener\">Tensor Processing Units<\/a> (TPUs), a specially designed computer that is far faster than GPUs for most neural network computations. If you can use a TPU, available through Google Cloud, then TensorFlow is sure to outperform the same PyTorch computation, as PyTorch does not natively support TPUs.<\/p>\n\n\n\n<p>Finally, industry insiders use TensorFlow and PyTorch in different ways. Many industry professionals prefer TensorFlow, due to its optimizations with TPUs, wide-variety of supported languages, and battle-tested robustness. Many researchers instead opt for PyTorch as it is easier to develop experimental network architectures.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PyTorch vs. TensorFlow: Which is better?<\/h2>\n\n\n\n<p>To choose between PyTorch and TensorFlow, consider your needs and experience.<\/p>\n\n\n\n<p>If you care only about the speed of the final model and are willing to use TPUs, then TensorFlow will run as fast as you could hope for. If you care about speed but are using a GPU, then TensorFlow and PyTorch have similar enough performance that whichever you have a preference for and develop fast enough in may be the best choice.<\/p>\n\n\n\n<p>If you\u2019re learning either framework for the first time, PyTorch and TensorFlow are both ubiquitous enough that learning a new framework, to contribute in <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/data-science-definition\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/www.springboard.com\/blog\/data-science\/data-science-definition\/\" rel=\"noreferrer noopener\">data science<\/a> or machine learning field, if not both, will be well worth your time. It will take some work, but Springboard can help you become well-versed in either, and both, frameworks.<\/p>\n\n\n\n<p class=\"rm has-background\" style=\"background-color:#efeff6\"><strong>Since you\u2019re here\u2026<\/strong>Are you interested in this career track? Investigate with our free guide to <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/what-does-a-data-scientist-do\/\" data-type=\"post\" data-id=\"24427\">what a data professional <em>actually<\/em> does<\/a>. When you\u2019re ready to build a CV that will make hiring managers melt, join our <a href=\"https:\/\/www.springboard.com\/courses\/data-science-career-track\/\" data-type=\"URL\" data-id=\"https:\/\/www.springboard.com\/courses\/data-science-career-track\/\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Bootcamp<\/a> which will help you land a job or your tuition back!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might be a machine learning project first-timer, a hardened AI veteran, or even a tenured professor researching state-of-the-art artificial intelligence\u2014at any skill level, you are likely knowledgeable about PyTorch or TensorFlow. But beyond what you already know, what are the key comparisons between PyTorch and TensorFlow? Which one is better for your project\u2019s needs? [&hellip;]<\/p>\n","protected":false},"author":100,"featured_media":18996,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_eb_data_table":"","footnotes":""},"categories":[67],"tags":[],"marketing_tags":[1466],"class_list":{"0":"post-14626","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts\/14626"}],"collection":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/comments?post=14626"}],"version-history":[{"count":4,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts\/14626\/revisions"}],"predecessor-version":[{"id":48289,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts\/14626\/revisions\/48289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/media\/18996"}],"wp:attachment":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/media?parent=14626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/categories?post=14626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/tags?post=14626"},{"taxonomy":"marketing_tags","embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/marketing_tags?post=14626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}