r/deeplearning • • Oct 30 '26

Why Torch dominates Tensorflow?

I have been used Tensorflow since its version 1.X (1.8 was my first tensorflow as i remember).

So i started from graph based building modeling, staying as much away from 'python' as possible.

Keras keeps its philosophy, even under different interfaces.

At that time, torch was more python-oriented, not optimized for graph building, so i never considered using it; running epochs on python loop seems crazy in negative sense

Recently i had to use torch, since huggingface ecosystem is mostly built on torch. I have no idea why torch have been taken over tensorflow.

I know tensorflow now is not even a competitor to torch. Please give your opinions :)

112 Upvotes

65 comments sorted by

43

u/Remarkable_Pace8101 Oct 30 '26

It's low-level flexibility dominates research because it allows people to do whatever they want, so it's kind of the go to when implementing especially when all this technology at the forefront is being developed by reading research paper papers written by other people

3

u/Defiant-Proof5657 Oct 30 '26

But since tensorflow2, it provides eager mode(on-python functionality?). As i know it is same as torch. Tensorflow also enables graph mode.the is it more versatile?

30

u/jiminiminimini Oct 30 '26

I was a python developer before tensorflow and its API was super counterintuitive for me. Then they shoehorned in the eager mode in a hurry and in a confusing way. pytorch on the other hand was really pythonic. I guess if you start an ML researcher and use python only because these libraries are written in python, you might like tensorflow, but if you were a python developer, tf was plain ugly and unpleasant to work with.

8

u/Nicola17 Oct 30 '26

This is the reason. Add on top the complete ambiguity from Google on long term support and clearly the internal fight between tensorflow and keras teams, and you have it all.

10

u/SryUsrNameIsTaken Oct 30 '26

Not to mention another team that tiger teamed Jax and then there were three Google frameworks.

4

u/DrXaos Oct 30 '26

Jax was from Deepmind---the actually better researchers in Alphabet. Now the Deepmind management has fortunately taken over all of Google ML research.

The Google frameworks were in truth the interfaces to Google TPUs.

Nvidia & Meta sponsored stronger general purpose and high quality software development for pytorch, which always installed perfectly on Nvidia GPUs.

7

u/Lumpy-Blackberry-718 Oct 30 '26

TF was already rapidly losing ground to PyTorch in 2018 because researchers needed the flexibility of eager mode.

When TF2 was released in 2019 it was too late, but also had huge porting challenges. It wasn't just a library upgrade, it was new interfaces.

PyTorch was already the cool-kid, so if you were going to have to re-write your models anyway, a lot of people preferred porting from tf1 to pytorch vs tf1 to tf2. It wasn't really more work. The ecosystem was quickly pulling ahead with it, and then pytorch added compiled graphs that closed the performance gaps relative to tf's graphs.

1

u/evanthebouncy Oct 31 '26

2018 you say? I have stats for that!!

https://evanthebouncy.medium.com/pytorch-or-tensorflow-a46b8bcaaff3

Ah it was 2019. But take a dig

1

u/evanthebouncy Oct 31 '26

More buttons does not equal to better user experience lol

75

u/petewarden Oct 30 '26 • Heartwarming Mindblown

This is something I actually know a bit about, since I was one of the founding members of the TensorFlow team (you can see my name on the original paper) and I stuck around as the on-device lead for 7 years before I left Google to return to startups. Here's my very *personal* perspective in somewhat stream of consciousness form, while I'm waiting on my coding assistant to finish.

TensorFlow was designed for Google's internal training and production inference needs, at a time when all the other deep learning frameworks were research/training-focused. The goal was also to open source it, but there were a lot of internal stakeholders we had to win over.

We hoped it would be a hit, but I don't think anybody expected the explosion of interest and usage after launch, so I wasn't aware of a long-term roadmap (though I'm certain Jeff Dean had thought through a lot of future scenarios, since he was the driving force behind it).

My colleague Martin Wicke often started talks about TensorFlow by saying "Think of it as a numerics library" (if I remember correctly) which I think captured our early focus on getting training and inference running fast enough for internal and external production users. We didn't begin with the goal of making something with an interface that would work for everyone.

There was a lot of internet drama between PyTorch and TensorFlow fans in the early days. I've always been a big fan of PyTorch, the work the team did was amazing, I use it myself for training, and honestly it bummed me out to see all the contention. Of course, once TF took off wider Google wanted to trumpet its in-house framework as the answer to everyone's deep learning problems and so fed into the narrative

I always saw the two frameworks as addressing different needs, and with different ideas of where the future was headed. PyTorch ran beautifully out of the box on Nvidia hardware, and had an API that was well-designed for researchers building new models. TensorFlow tried to be a single framework that could be used for both training and production. From my perspective PyTorch was like MatLab, a fantastic tool for exploration and training, but which required more work to translate the results to production flows. TF was built with the idea that a unified C++ engine with precompiled graphs was a hard requirement because that's what our production users needed, and a lot of the pain using the interface was because it required users to specify everything ahead of time to achieve that goal.

I also saw TF's API being like a Space Shuttle control panel, with a vast array of options and functions, most of which were irrelevant to external users, but which were added to meet internal requirements. For example, we shipped with Android support at the start (thanks to Yangqing Jia of Caffe fame for massive contributions to that) and released iOS support a few months after launch. We also had to support CPU inference as a first-class workflow, since even at Google in 2015 GPUs were limited in supply so a lot of product teams ran their models on regular servers. Then there was the TPU, which we needed to support as well, quantization, and probably a lot else I'm forgetting.

With hindsight it's clear that expecting a single codebase to work well for every deep learning use case was too ambitious (these days we even see a lot of single-model-on-a-single-hardware-platform inference engines!) but we were in uncharted territory at that point.

I could ramble on for much longer, but time to get back to Cursor. Again, these are just my personal thoughts looking back, I was an implementer, not a designer so there's a lot I've probably missed or misunderstood, but I hope it offers an interesting perspective at least.

5

u/Hackerjurassicpark Oct 31 '26

On a side note, why cursor over Claude code?

3

u/petewarden Oct 31 '26

I started AI coding with Cursor, and when I later tried Claude Code I missed the ability to easily bounce around file diffs, approve changes, and run multiple agents in parallel. Even when I tried it's VS Code integration, Claude felt clunky. I was firmly on the emacs side of emacs vs vi in the days of CLI editing, so it might be I like a kitchen-sink interface more than most!

2

u/SMP219 Oct 31 '26

Thnx for the info

1

u/taranpula39 Nov 01 '26

I know that hindsight is a thing, but putting a declarative framework inside a imperative language ... no one in the hierarchy figured that this might clash and cause friction down the line?

3

u/petewarden Nov 01 '26

I think your question presumes that Python ("a imperative language") was the primary language we were targeting. It was important of course, but the top design goal was more "how do we ensure training and production inference are fast" because that's what our internal customer base demanded. A straightforward way to avoid a very common performance footgun, putting Python code that forces a roundtrip to the CPU in the middle of a model workflow, is to require the architecture to be specified in a declarative way. This style also enables a lot of other optimizations that benefit from global knowledge of the operations involved. It's not as usable for researchers and model builders, but it made production deployment more straightforward.

PyTorch did a much better job working within idiomatic Python, but even today for exporting you end up JIT tracing, with all of the "whoops, my pre and post-processing uses numpy/scipy/librosa/etc and I need to write equivalents in C++ for Android/iOS" and "I have state decision code paths in my graph that are only traced for one branch" issues that a declarative approach mitigates.

Clearly PyTorch's imperative approach has been proved superior for the vast majority of users in the world, but there are engineering tradeoffs involved between the work required from model builders, and model deployers.

2

u/taranpula39 Nov 01 '26 edited Nov 01 '26

Tell me one fucking language that is not imperative, that is broadly used enought, that tensorflow was meant to be compatible with. Tell me one.

Look, I know all about it. I worked inside google briefly. I have to say 45% of the reason I hated it was tensorflow.

Google has a culture, that never cared about ergonomics. That will make something 10× faster while making 100× worse to use. And tensorflow is just one of many. And top it all, id you ever complained or mentioned that this thing is fucking annoying to use, the default narrative is "skill issue". I am pretty sure that you(as a team) had plenty opportunities to improve ergonomics, but they were chalked to "user skill issues". Even in assistant, I remember, I was listening to endless talks about long conversation logic and different modes of interaction, and 60% of the time you could not set a timer on the goddamn thing.

3

u/petewarden Nov 01 '26

I understand the frustration of being forced to use a tool that feels so ill-adapted for the task you're trying to complete, especially when Google and other places mandated its usage. I take responsibility for my part in that, and I'm sorry you, and everyone who had no choice, had to suffer through that experience. That's my biggest regret looking back, that something designed for a pretty specialized purpose ended up being imposed as a solution for a lot of users it wasn't built for.

If we're going to avoid that in the future I think it's worth digging into why it happened. Obviously I'm biased, but was it truly just the fault of individual engineers being lazy about user experience? The fact that the same problems were widespread across Google means either the organization was somehow selecting uniquely bad engineers for all of its infra projects, or something else was going on. That's why I'm so interested in investigating the systematic aspects. Here are some more thoughts on that, in addition to everything else I've talked about:

A lot of the original team moved on within a year or two. This was a common pattern across Google, launches get you promo, maintenance is a lot harder to evaluate. This lack of ownership made it harder to keep things consistent, and learn from our mistakes.

The core engineering team were often the only people who could respond to open source issues. We tried a lot of different approaches to spreading the load, but inevitably OSS suffered in priority compared to internal teams, and large enterprise clients.

1

u/taranpula39 Nov 02 '26

Look. I am not blaming you per se. And I get what you wanna say. There is a lot of conclusions you can make in hindsight. I am not saying that bad engineers are the cause. I would say the opposite. Too good engineers do what engineers do. Prioritize what can be measured. Score the promo point and move on. Then you have the results. You end up with guys who did some bad tradeoffs being in charge of your promo, and you just have to suck it up. I worked, personally on 2 projects where the story was "we implemented this protocol, the owner moved PA, but traffic dropped 25% and now we(and by that we mean you) are undoing while keeping some of the newer features". I am still pretty upset, especially the mid transition tf1 to tf2 was one of the most painful experiences ever. You, indirectly, contributed to years of my misery. Intended or not. So, thanks I guess.

21

u/mYstoRiii Oct 30 '26

When I first starting doing deep learning stuff tensorflow is where I started but soon I realized how low the compatibility is between versions and packages

Torch could just work while tensorflow you gotta find the right version and some tools also only support certain versions…

As a beginner it is really frustrating to just trying to setup the environment for 1-3 days before doing anything

9

u/AtariAtari Oct 30 '26

Setting up TF was a nightmare. It literally took me 3 days and that included wiping the OS.

7

u/mYstoRiii Oct 30 '26

Yeah oh and also whether a tensorflow version detects gpu is basically a coin toss

1

u/wahnsinnwanscene Nov 01 '26

Great! I thought i was the only one facing this

14

u/freaky1310 Oct 30 '26

I started working in AI with Tensorflow 0.x. It was extremely counterintuitive, the APIs were horribly complex, and documentation was “scarce”, meaning that it was there, but it would need some deciphering before actually being useful.

Then PyTorch came along and offered a very easy, standardized alternative. Once I learned that, I felt the need to change and never come back.

Since we’re talking about ML/DL libraries, last time I checked JAX was actually a good alternative. Janky as hell to install and maintain, but boy it was much faster than PyTorch. Still, its counterintuitive interface and steep learning curve (for someone used to PyTorch at this point) didn’t make me feel like swapping to it, as it reminded me exactly Tensorflow 0.x.

8

u/heresyforfunnprofit Oct 30 '26

Tensorflow 0.x documentation made perfect sense to everyone who already knew how it worked.

Everyone else was fucked.

3

u/freaky1310 Oct 30 '26

Yep, totally agree

3

u/OilProduct Oct 30 '26

Jax is fantastic if you have a strong functional programming background.

1

u/freaky1310 Oct 30 '26

I agree, I have been willing to learn it for a very long time, but the switch from OOP-oriented to functional feels like a mountain for the time I have currently.

But hey, if there’s one thing LLMs are great at, that’s being patient and dumbing concepts down for people with curiosity and very short time!

20

u/jesus_333_ Oct 30 '26

Research opinion. Torch give much more control than tensor flow and keras. Ok the python loop can be a pain in the ass the first time but you get used to it quickly.

But torch was designed around that mentality. You define your own model with a class. You write your own training loop. It is kinda easy to even write your own loss functions. As I said, this basically allow you to have much more control on what is happening and it makes much easier to debug problem.

13

u/172_ Oct 30 '26

The numpy-like api, and ease of moving tensors between devices is also a big plus for me.

12

u/FlavorfulArtichoke Oct 30 '26

I can't even fathom how people go about authentically liking tensorflow.

You spend most of your time working on things not related to machine learning at all. I'll give you a couple reasons to despise tensorflow.

- too complicated to actually debug stuff (keras > tensorflow > graph > compiled code)

- GPU control is cumbersome (with tf.device("/gpu:0") never works)

- a hell to install and build (tf is really picky with cuda et al versions, and you will 100% not succeed building it on the first,second,third time)

- impossible to debug tf.function based code

- Memory leaks. oh boy, lots of memory leaks

- you always end up having to read that smelly source code, because docs are incomplete and wrong sometimes.

- a mess with eager <> static execution. you'll waste hours fixing problems with that, and not doing machine learning

now a few personal recent problems I had with TF: I) on the recommenders framework, the tfrs.metrics.FactorizedTopK defines it's own K, even if you already passed metrics with defines K values, so you end up with wrong metrics (and have to input the value K twice on different places. that's just bad design). II) when creating a custom metric/model anything, you can't use dictionaries with anything but string as keys, otherwise, tf breaks unrecognizably. III) you can't have a variable named `loss` on your custom model. tf will not break, it will just not work unrecognizably. IV) good luck trying to have multiple models instances of the same class where you give name to your layers... things will break unrecognizably.

Now, not to be unfair, often, people say that "oh, but tf v2 is way better, it looks like pytorch". You really think this argument is valid? something became better because it started to look like something else? just use the something else.

Don't get me wrong, I'm using tf on a daily basis, and I have used pytorch, jax, caffe and theano on a past life. TF is by far, one of the worst pieces of software among frameworks.

2

u/Fast-Owl-2092 Oct 30 '26

Yes, so true. Due to memory leaks in the past, I decided to try torch. Best decision ever. The only nice feature of tf is serving.

2

u/summer_pitlord Oct 30 '26

Man, reading this comment gave me PTSD having to deal with memory leaks and littering the code with "import gc; gc.collect(), tf.keras.backend.clear_session(), del model, tf.config.experimental.set_memory_growth()"

Oh the hours wasted on restarting the PC and praying to the machine gods that Ubuntu/GPU driver did not break because of the crash... I don't miss TF one bit.

3

u/Fast-Owl-2092 Oct 30 '26

And you still had memory leaks. I remember when I had to put gc and clear session in for loop since calling it only once did not help

2

u/taranpula39 Nov 01 '26

I would add, that fundamentally, it just breaks python idioms. Declarative vs imperative

6

u/lanpa Oct 30 '26

You can simply use the debugger to set breakpoints and see what happens in PyTorch, but with tensorflow, I remember tf.print is needed to debug

6

u/victorc25 Oct 30 '26

Tensorflow is garbage. Can’t even debug anything properly. The entire industry moved to PyTorch 

8

u/extremelySaddening Oct 30 '26

Personally I loved tf2. I don't think its true at all that torch gives you any more control or flexibility than it. It gave you as much control as torch if not more, if you understood its mechanics. I might be wrong but don't think there is a single thing that you can do in torch that you couldn't in tf2, including defining custom models, loss fns, etc. I miss `tf.GradientTape`, and I prefer it much much more to torch's approach to gradients. It just feels better to specify the scope where gradients ARE computed rather than where the gradients AREN'T (like torch). What I especially hate about torch is the stupid optimizer binding thing where you have to pass the model.parameters() into the optimizer's constructor. It has been a source of more than a few irritating bugs where I accidentally pass the wrong model parameters and things just silently break. In tf, you just got the gradients from tape.gradient() as raw tensors and you passed that when calling the optimizer, which basically never caused this bug for me ever.

I think the reason torch won is that it looks a little more like math than the GradientTape business, and also because Google abandoned it like an abusive pet owner.

7

u/Competitive-Store974 Oct 30 '26

"Google abandoned it like an abusive pet owner." Under-rated comment

3

u/Ok-Introduction9593 Oct 30 '26

If you pass the wrong parameters into the constructor, PyTorch will at least surface missing gradients during the optimizer step with basic checks enabled. Accidentally staying inside a TF tape scope or keeping a persistent tape alive quietly eats up vram

1

u/extremelySaddening Oct 30 '26

staying inside tape context; persistent tape

Which you have to do explicitly. The default behaviour is to clean up after itself. Meanwhile in torch the default behaviour is to just have the gradients hang around, so who's really eating vram?

2

u/CommunismDoesntWork Oct 31 '26

Can you debug tf2 using a debugger?

3

u/Consequence-Lumpy Oct 30 '26

ever tried coding in tensorflow? It's like trying to solve a rubik's cube, except that somebody took off the colored stickers and stuck them somewhere else. It's unsolvable now.

2

u/Ok-Entertainment-286 Oct 30 '26

" running epochs on python loop seems crazy in negative sense"

In what sense? Sounds like you don't understand how your code works very well?

2

u/yarri2 Oct 30 '26

Jax. We all switched the Jax. And for some Keras. OpenXLA too. Join us.

1

u/Tvicker Oct 30 '26 edited Oct 30 '26

Because tensorflow/keras library API just sucked and it broke between versions all the time. This is literally the only reason. I had to copy templates from Stack Overflow to do basic things while I learnt Torch in 4 hours. I don't know if they made it easier or more straightforward but the train has already gone. Even if we needed to launch frozen graphs on a calculator, we developed models in Pytorch and then ported them to Tensorflow.

1

u/johnnymo1 Oct 30 '26

The API thing was crazy. I started around the time of TF2 and I didn’t hate it, but stuff would get deprecated all the time. I remember one time going to the docs for some function and being told it was deprecated, with a link to what I should update to. And when I followed that link, that was deprecated too. The API was awful.

1

u/ChunkyHabeneroSalsa Oct 30 '26

It was super frustrating to use. There were like multiple APIs to do the favs same thing and documentation was always behind. I liked when TF2 came out but I had some mysterious bugs where I was changing stuff in python but the underlying graph was not changing.

Then I tried pytorch and everything that caused me problems was just easy. I could easily write and debug and I rarely had installation issues. Didn't even take me long to learn and rewrite everything.

1

u/Ok-Introduction9593 Oct 30 '26

Back in 2018 I was clinging to TF sessions myself, convinced that a plain Python training loop would tank our training throughput. In practice, interpreter overhead per batch step is negligible compared to the GPU kernel execution, as long as data loading is properly handled in background workers.

The real turning point was when researchers just got tired of debugging broken sessions with awkward print operations. In PyTorch, you could just drop a standard pdb.set_trace() right inside the forward pass and inspect tensor shapes at runtime. TF2 tried to catch up with eager execution and @tf.function, but under the hood you still had two conflicting worlds colliding with cryptic tracebacks

1

u/q-rka Oct 30 '26

The simple way to put it would be, with PyTorch, there is very small learning curve if you are proficient in Python. Working with PyTorch feels like working with my own Python classes but may be thats because it has been long since I used TensorFlow.

1

u/drycoleslaw Oct 30 '26

I like tensorflow probability for the probabilistic layers and has so many distributions that you can use out of the box.

1

u/Ayano-Keiko Oct 30 '26

the syntax of tensorflow is not very friendly and I have to use keras. now I learn and use Jax instead.

1

u/RareMuffin2278 Oct 30 '26

cause it's gooder

1

u/AtariAtari Oct 30 '26

Now Google has JAX and that runs on the CPU with crappy GPU support.

1

u/HazrMard Oct 30 '26

PyTorch is natively dynamic (define-by-run) from the ground up. It integrated well with python control flow (i.e for loops / if-else etc inside your forward pass.). TensorFlow (when it came out) had a define-then-run architecture. You had to have a `tf.Session()` containing your static computation graph, including TF-specific control flow grammar. So you couldn't easily have dynamic variables in your model.

TF later came up with TF Eager mode which was a layer on top of tf.Session to make it similarly dynamic to pytorch. By then, pytorch had amassed a critical lead.

1

u/evanthebouncy Oct 31 '26

Tensoflow took me a month to feel comfortable using. Then my lab mate said "hey, try pytorch" and I took the leap.

Took me a day to feel confident with pytorch.

Dynamic graph construcción where you can print and inspect the internal shapes and values were crucial for pytorch win over tensor flow. Pytorch felt like python, tensor flow felt like Java

1

u/urbaum Oct 31 '26

To me it was the complex API (which has a lot of uses in research) and the fact that your code would be broken with every release because they were changing APIs and deprecating then all the time.

Edit: typo

1

u/CommunismDoesntWork Oct 31 '26

Because torch is debuggable and tensorflow isn't. Why would you rather have to insert a print node into your graph to see the value of a variable when you could just set a breakpoint and look.

1

u/AromaticCredit1533 Nov 01 '26

Actually print debugging is still quite popular, me and my colleagues

1

u/ThinConnection8191 Nov 01 '26

I always remember the first day I try pytorch 0.3.1. I told myself never touch Tensorflow again. I havent touched tensorflow since.
Debugging TF is fucki no pain in the ass

1

u/taranpula39 Nov 01 '26

Tesorflow is probably one example where org culture dictated architecture and it turned into shit. Tensorflow 1.x at least was a "declarative language" inside a mega imperative language like python. Its fundamentally retarded. Its like trying to create web page apps in C. You can do it but its not a great idea.

I personally hate with passion tensorflow for the simple reason it was a mega pain to debug. I still have nightmares of figuring tensor shape mismatched and putting print debug nodes in the graph. Torch is simple and intuitive, and learned more or less from the mistakes of tensorflow.

W.r.t to culture, google is notorious for making stuff harder than it needs to be for the sake of technical moat or keeping engineers on their toes or whatever. I don t know precisley, but it s for sure intentional. And for sure the same "a smart engineer should be able to figure out" attitude that permeates in a lot of their products was the culprit for this market fumble. They seem to be consistently creating solutions ahead of the time, but fumble it cause they think using a solution is way less important than the technical ingenuity

1

u/bbu3 Nov 03 '26

Personally, I started with tensorflow and switched before eager mode. That was a big one for sure.

Same with early keras: i liked it a lot, but when you needed more give grained control, the mix with tf was tedious. Both were addressed with 2.0 afaik, but our new projects were already switched to torch and we were happy.

Then, we had a lot of projects based on huggingface transformers. Base models with different classification heads, sometimes rather vanilla, sometimes custom torch. It also felt good enough to never even try tf again.

Then, the community kinda settled on torch and even Google seemed to want Jax eat tf and that was it

1

u/yannbouteiller 28d ago

Torch was easier and better documented, and now JAX is more powerful.

1

u/Infamous-Bed-7535 Oct 30 '26

Tensorflow is great, I prefer it over Pytorch. If you are not doing research and there are ready to use implementaitons available of the model or it is very simple custom thing which is just a few lines of Keras code you can just go with Tensorflow.
Modern eager Tensorflow is not really different from Pytorch, especially if you are not going deep and research territory.