# \[ANN\] Announcing Torch.jl

**URL:** <https://discourse.julialang.org/t/ann-announcing-torch-jl/42390>\
**Category:** Machine Learning\
**Tags:** cuda, flux, machine-learning, pytorch\
**Created:** [July 1, 2020, 6:11pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390 "2020-07-01T18:11:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhairyagandhi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dhairyagandhi96/32/7589_2.png) [@dhairyagandhi96](https://discourse.julialang.org/u/dhairyagandhi96)\
**Post date:** [July 1, 2020, 6:11pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/1 "2020-07-01T18:11:31Z")

</div>

I am excited to share some new development in the Julia ML stack. We are announcing [Torch.jl](https://github.com/FluxML/Torch.jl) which wraps the existing PyTorch and its CUDA kernels and makes them available through Julia. Torch.jl also exposes the kernels through integration with Flux.jl and Zygote.jl (for differentiation), so it requires minimum handling on the user side. Most operations can just be handled like we would any other function calls in Julia. It operates similarly to how a model is moved to the GPU with `gpu(model)`, via `torch(model)`.

We have also written a [blog post](https://fluxml.ai/2020/06/29/acclerating-flux-torch.html) about it which goes in more depth and talks about its intended use and development.

We are excited to see folks use it and see more development in the area! Please file issues for cases that may not be covered yet in the issue tracker, and we would love to hear about all the features that would be nice to see in here!

Cheers,  
@dhairyagandhi96, @MikeInnes

---

<div class="post-metadata">

**Author:** ![maxfreu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxfreu/32/17468_2.png) [@maxfreu](https://discourse.julialang.org/u/maxfreu)\
**Post date:** [July 3, 2020, 12:44pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/2 "2020-07-03T12:44:14Z")

</div>

Wow, nice! I have waited for sth like this and will try it out! 😊 But there is an elephant in the room: Have you benchmarked against python-pytorch?

---

<div class="post-metadata">

**Author:** ![andevellicus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andevellicus/32/15097_2.png) [@andevellicus](https://discourse.julialang.org/u/andevellicus)\
**Post date:** [July 8, 2020, 3:34am UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/3 "2020-07-08T03:34:45Z")

</div>

Excited to try this out… just need 3D support (5D tensors 😁 )

---

<div class="post-metadata">

**Author:** ![Freddy\_Chua](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Freddy\_Chua](https://discourse.julialang.org/u/Freddy_Chua)\
**Post date:** [July 9, 2020, 2:42pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/4 "2020-07-09T14:42:54Z")

</div>

Can you please let me use Torch.jl without assuming a CUDA enabled device is present.

---

<div class="post-metadata">

**Author:** ![dhairyagandhi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dhairyagandhi96/32/7589_2.png) [@dhairyagandhi96](https://discourse.julialang.org/u/dhairyagandhi96)\
**Post date:** [July 12, 2020, 9:38am UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/5 "2020-07-12T09:38:31Z")

</div>

That requires building against the cpu binaries lazy loading the artifact, which in itself is pretty simple simple to do, but means that it’s more work to switch out the cuda capable binaries when you need them. It’s basically copying [this](https://github.com/JuliaPackaging/Yggdrasil/blob/master/T/Torch/build_tarballs.jl) build script and including a cpu only target

---

<div class="post-metadata">

**Author:** ![d1cker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/d1cker/32/9816_2.png) [@d1cker](https://discourse.julialang.org/u/d1cker)\
**Post date:** [July 12, 2020, 10:25am UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/6 "2020-07-12T10:25:55Z")

</div>

Are you planning to add it to Torch.jl?

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [July 12, 2020, 10:34am UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/7 "2020-07-12T10:34:34Z")

</div>

So, how does it compares to Knet.jl and Flux.jl in terms of capabilities and speed?

---

<div class="post-metadata">

**Author:** ![dhairyagandhi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dhairyagandhi96/32/7589_2.png) [@dhairyagandhi96](https://discourse.julialang.org/u/dhairyagandhi96)\
**Post date:** [July 12, 2020, 5:32pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/8 "2020-07-12T17:32:04Z")

</div>

It’s a fairly easy change, I’d very much appreciate contributions back to the project, but I am tied up till JuliaCon, post which I can take a look.

---

<div class="post-metadata">

**Author:** ![dhairyagandhi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dhairyagandhi96/32/7589_2.png) [@dhairyagandhi96](https://discourse.julialang.org/u/dhairyagandhi96)\
**Post date:** [July 12, 2020, 5:34pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/9 "2020-07-12T17:34:02Z")

</div>

This doesn’t replace Flux or KNet, but rather in it’s current form make the core kernels available with a tie in to support the NNlib interface.

For a deeper dive in, I recommend checking out the blog post related to the OP where more of the capabilities and performance is compared

---

<div class="post-metadata">

**Author:** ![nurban](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nurban/32/5278_2.png) [@nurban](https://discourse.julialang.org/u/nurban)\
**Post date:** [July 15, 2020, 5:24pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/10 "2020-07-15T17:24:54Z")

</div>

This is exciting. Is anything like it planned for TensorFlow as well?

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [July 15, 2020, 5:36pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/11 "2020-07-15T17:36:43Z")

</div>

It already exists: [https://github.com/malmaud/TensorFlow.jl](https://github.com/malmaud/TensorFlow.jl)  
but it’s not being updated.  
It’s maintainers prefer Flux.jl (or Flax.py).

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [July 15, 2020, 6:06pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/12 "2020-07-15T18:06:10Z")

</div>

This is pretty exciting. Will this be considerably less “experimental” than Flux.jl?  
Not to be critical of Flux, but my experience with it is such that 1/5 times I needed it for a project some essential functionality was broken in a way that made it unusable. When it works its glorious! but having torch around would be pretty nice for those rough spots so we don’t all have to flock to python between releases/fixes/etc.

---

<div class="post-metadata">

**Author:** ![nurban](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nurban/32/5278_2.png) [@nurban](https://discourse.julialang.org/u/nurban)\
**Post date:** [July 15, 2020, 6:46pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/13 "2020-07-15T18:46:24Z")

</div>

TensorFlow.jl wraps TensorFlow, but it doesn’t provide Flux/Zygote integration, does it?

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [July 15, 2020, 7:02pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/14 "2020-07-15T19:02:47Z")

</div>

That is correct (to my knowledge). The closest equivalent would be [https://github.com/FluxML/XLA.jl](https://github.com/FluxML/XLA.jl), which uses the same acceleration backend as TensorFlow and JAX. I imagine (hope) that there will be some more focused design work around normalizing and polishing all of these Flux backends after JuliaCon.

---

<div class="post-metadata">

**Author:** ![jonathan-laurent](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jonathan-laurent](https://discourse.julialang.org/u/jonathan-laurent)\
**Post date:** [July 17, 2020, 6:59pm UTC](https://discourse.julialang.org/t/ann-announcing-torch-jl/42390/15 "2020-07-17T18:59:14Z")

</div>

Very nice work, thanks! I would be interested in trying Torch.jl with my [AlphaZero.jl](https://github.com/jonathan-laurent/AlphaZero.jl) package. 🙂

However, it seems to me that Torch.jl is not compatible with Flux 0.11 yet. I filed an [issue](https://github.com/FluxML/Torch.jl/issues/33) about this.
