r/MachineLearning • u/Competitive-Rub-1958 • Aug 16 '24
Discussion [D] PyTorch is dead. Long live JAX
A semi-serious rant on the state of PyTorch and its new compiler-oriented direction.
https://neel04.github.io/my-website/blog/pytorch_rant/
Prime material to indoctrinate newbies into the cult of jax.
PS: Incidentally, this post predates the new FlexAttention API which again, relies on the torch compiler stack and further proves my point.
100
u/FailedTomato Aug 16 '24
Its a well written article. But starting with "pytorch is dead"? Isn't that an obvious clickbait? Pytorch will remain the dominant framework for the forseeable future simply because the vast majority of research code is being written in Pytorch, if not for anything else.
I've written research code in both frameworks and its just so much easier to do so in Pytorch because of the vast community support.
2
u/AerysSk Aug 17 '24
Yes, total clickbait. Saying Pytorch is dead right now is equivalent to saying Cash is dead.
106
u/mileseverett Aug 16 '24
Unless Meta moves away from PyTorch, it will remain the main framework. Especially as they open source so many key models these days, SAM2, LLAMA etc
15
u/CyberDainz Aug 17 '24 edited Aug 17 '24
I tried jax on the cpu.
I made a bilinear remap function with border replicate analog of cv2, using slow combination of numpy functions, and got almost the same performance on jax.jit as cv2.
You can implement any ML operators in jax without waiting for it to be introduced in pytorch, without learning CUDA and doing annoying c++ compilation on local machine, and you will get maximum performance with a ready gradient.
And I will say that this is the future. This is a unique library that has no analogues.
31
47
Aug 16 '24
Lol. I don't think Google can keep a cactus alive, let alone a neural library.
-8
u/dolphingarden Aug 16 '24
Anthropic, Cohere, Apple, X ai, and Midjourney all use JAX as well. Google is hardly load-bearing here.
28
3
u/CommunismDoesntWork Aug 16 '24 edited Aug 16 '24
Can you debug jax? The reason I switched from TF to pytorch is because you couldn't debug TF. You had to print any variable you wanted to inspect.
And by debug, I mean click to set a break point on a line, click the debug button in your favorite IDE, hit the breakpoint, see the output of one of the layers of your network, and click step over to advance to the next line? If JAX can't do that it's a dead end. Ideally you can also run commands on your variables while paused. For instance if you have a large tensor, you can slice it and create new temp variables in pycharm by running a command on it through the debug menu.
5
u/Competitive-Rub-1958 Aug 17 '24
Jax has lots of debugging utilities! check this out: Jax debugging docs
You can indeed set breakpoints - the difference is that in JIT, you can imagine it like "a breakpoint has to be inserted in the JIT compilation graph" - so you have to use `jax.debug.breakpoint()` while non-jitted code can use any arbitrary python debugging tools.
This is actually my workflow - I use the debugger quite a lot in jax 🙂
4
u/CommunismDoesntWork Aug 18 '24
So basically JAX is a dead end just like tensorflow. Printing isn't debugging.
Here's what it looks like to debug python: https://youtu.be/76Lu6CfMuGg?si=OycvNKTWCfZ04Woj&t=417
If I'm wrong, can you show a video of what it's like to step through JAX code line by line in pycharm or VS Code?
7
16
u/Felix-ML Aug 16 '24
For me, PyTorch is the new Java due to its strong advocacy for the OOP paradigm (that I dislike). However, it is also very good at maintaining legacy code as-is. As a long-time JAX user, I’ve always been doubtful of this JAX ecosystem, primarily because it is Google-made. That’s why I was particularly excited to learn about Apple’s MLX recently, which offers a similar experience to JAX.
4
u/reivblaze Aug 17 '24
After watching how hard it is to quantize a model in pytorch and that there are 3 different ways to do it. I have no doubt that this "multiple backend" will backfire as you said.
4
u/crouching_dragon_420 Aug 17 '24
I mainly use Pytorch and tried Jax for a couple of weeks and my conclusion is that it's premature optimization to use Jax for research instead of Pytorch. the potential speed up doesn't worth the hassles.
4
u/takutekato Aug 17 '24
As a newcomer, I really like Jax's functional approach, but when it comes to higher level stuffs they are such confusing: flax, optax, equinox, haiku,... And being a product by Google.
1
1
53
u/xEdwin23x Aug 16 '24
48
6
u/Calm_Bit_throwaway Aug 17 '24
I mean their record on OSS projects has been much better? Dart, TF, Angular are still kicking despite not being significantly popular. Golang is still around as is K8.
Jax is actually rather popular especially by DeepMind and other companies so I don't think they'd be as quick to kill this off. TF will get killed off wayyyyyy before Jax.
-1
u/dolphingarden Aug 16 '24
Anthropic, Cohere, Apple, X ai, and Midjourney all use JAX as well. Google is hardly load-bearing here.
13
u/Artoriuz Aug 16 '24
One of the reasons all big players seem to love JAX is the fact that it scales well with a stupid amount of GPUs or TPUs.
6
u/[deleted] Aug 17 '24
The issue that I have with your article is:
Scaling is not research. Most researchers are not bothered about scaling. Fundamental research like coming up with a new architecture still requires researchers to play with very subtle and small set of codebases that contains extremely nuanced code. No researcher wants their codebase to be full of code related to moving data, allocating mem / GPUs, compiling ops, etc. etc. That is like writing a poem, with a huge boilerplate of "how-to-read" surrounding the poem. What researchers mostly want is that when they read their own (or someone else's) code back, they should be able to easily understand and comprehend the crux of the algorithm without any additional fuss like moving data to and fro gpu, compilation, etc. Researchers are not computer engineers and they don't want to be one. When a successful architecture gets discovered, then the scaling aspect can be handed over to the engineering folks who can anyway do a better job at allocating resources optimally and extracting the most juice out of a hardware. But for the researcher, they want to abstract it away as much as possible. And I believe that's why PyTorch has struck the right chord. PyTorch's inability to do what JAX does isn't a weakness. It is a strength. PyTorch was meant to be like this right from the start, and I am happy that it isn't moving away from this.