# Converting PyTorch to Flux while keeping performance

**URL:** https://discourse.julialang.org/t/converting-pytorch-to-flux-while-keeping-performance/81877
**Category:** Machine Learning
**Tags:** flux, zygote
**Created:** [May 29, 2022, 5:49pm UTC](https://discourse.julialang.org/t/converting-pytorch-to-flux-while-keeping-performance/81877 "2022-05-29T17:49:09Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [May 29, 2022, 8:26pm UTC](https://discourse.julialang.org/t/converting-pytorch-to-flux-while-keeping-performance/81877/4 "2022-05-29T20:26:33Z")

</div>

Yes, but note here how you’re calling `sum(xs)` and not `sum(f, xs)`.

You may need to import LoopVectorization in order for Tullio to generate a fully optimized kernel. More importantly, I would extract `deformation_indexed[:, 1, :]` into its own local variable to potentially save on a lot of compute/memory overhead.

Also, what is `register`? It seems like there is more code here that may have an influence on performance (e.g. if `register` is a mutable struct), so a [MWE](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) would be much appreciated.

---

_[View the full topic](https://discourse.julialang.org/t/converting-pytorch-to-flux-while-keeping-performance/81877)._
