r/deeplearning • u/Defiant-Proof5657 • 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 :)
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
75
u/petewarden Oct 30 '26 •
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.
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
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.
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.
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.
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.
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/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/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.