# Flux 3, now with 100% more Julia!

**URL:** https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824
**Category:** Machine Learning
**Tags:** flux
**Created:** [September 11, 2017, 2:12pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824 "2017-09-11T14:12:47Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [September 11, 2017, 2:12pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/1 "2017-09-11T14:12:47Z")

</div>

Flux v0.3 is a big release, with a brand new, pure-Julia backend for machine learning. This lets us immediately support all of Julia’s most powerful features, without having to compile them to a more limited backend like MXNet. It’s also a huge simplification, with a codebase that’s half the lines and much more straightforward.

Going forward, it will be much easier for us to apply our own optimisations and integrate with Julia’s rapidly growing GPU ecosystem. The [housing data example](https://github.com/FluxML/model-zoo/) shows how easy it is to drop [CuArrays](https://github.com/FluxML/CuArrays.jl) (or [GPUArrays.jl](https://github.com/JuliaGPU/GPUArrays.jl/)) into a model for an easy speedup, with more integration coming shortly.

Of course, you don’t need a GPU to get started, and trying it out is as simple as

```julia
Pkg.add("Flux")

```

Check out the [new docs](http://fluxml.github.io/Flux.jl/) and enjoy!

---

<div class="post-metadata">

### Author: ![jianghaizhu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghaizhu/32/1866_2.png) [@jianghaizhu](https://discourse.julialang.org/u/jianghaizhu)
#### Post date: [September 12, 2017, 2:34pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/2 "2017-09-12T14:34:30Z")

</div>

Is there a model for CNN?

---

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [September 12, 2017, 4:29pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/3 "2017-09-12T16:29:37Z")

</div>

Not just yet – CNN support is a work in progress, but should be pretty easy to add. I’ll finish it up in the next couple of weeks if no one beats me to it with a PR 🙂

---

<div class="post-metadata">

### Author: ![Phil\_Tomson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phil_tomson/32/3575_2.png) [@Phil\_Tomson](https://discourse.julialang.org/u/Phil_Tomson)
#### Post date: [September 18, 2017, 11:04pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/4 "2017-09-18T23:04:19Z")

</div>

Compare & contrast Flux with Knet?

---

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [September 22, 2017, 11:19am UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/5 "2017-09-22T11:19:55Z")

</div>

The main difference right now is that I’ve written Flux to avoid [some issues](https://github.com/denizyuret/Knet.jl/issues/144) with Knet’s current interface. This enables it to provide a higher-level Keras like API (stacking of layers, reusing common layers like LSTM etc). Knet is also looking to fix those things too, and me, Deniz and Jarrett have been working together to figure out the One True Interface, so things will converge in future.

Longer term, Flux will focus on traditionally “static” graphs and optimisations – e.g. pre-allocating memory, scheduling, parallelism and smart batching. The eventual hope is that you can mix and match these different approaches without making the traditional tradeoffs.

Knet is of course pretty robust, full-featured and performant, whereas Flux is still in alpha, so that’s another important consideration if you just want to get things done right away.

---

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [September 28, 2017, 10:44am UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/6 "2017-09-28T10:44:07Z")

</div>

I just tagged 0.3.2 with [new GPU support](http://fluxml.github.io/Flux.jl/stable/gpu.html). Enjoy! Just don’t benchmark it just yet 😉

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [September 28, 2017, 1:23pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/7 "2017-09-28T13:23:19Z")

</div>

I didn’t see anything about how to compile Julia such that one can use CuArrays, is there documentation on this somewhere? I’m also a bit confused about the implementation details. For instance, how do I tell it to use MXNet or TensorFlow as a back-end?

---

<div class="post-metadata">

### Author: ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)
#### Post date: [September 28, 2017, 1:49pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/8 "2017-09-28T13:49:59Z")

</div>

For using CuArrays you need a source build of Julia (see [https://github.com/JuliaGPU/CUDAnative.jl#installation](https://github.com/JuliaGPU/CUDAnative.jl#installation))

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [September 28, 2017, 2:00pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/9 "2017-09-28T14:00:54Z")

</div>

Oh, I figured Julia would need some special compile flags or something.

---

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [September 29, 2017, 12:46pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/10 "2017-09-29T12:46:46Z")

</div>

In this version I’ve removed the TF/MXNet backends as I want to focus on making native Julia support really good. I plan to bring them back in some form in future, likely as a separate package.

---

<div class="post-metadata">

### Author: ![jianghaizhu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghaizhu/32/1866_2.png) [@jianghaizhu](https://discourse.julialang.org/u/jianghaizhu)
#### Post date: [September 29, 2017, 5:34pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/11 "2017-09-29T17:34:52Z")

</div>

Thanks! I will be interested in testing your CNN model.

---

<div class="post-metadata">

### Author: ![Phil\_Tomson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phil_tomson/32/3575_2.png) [@Phil\_Tomson](https://discourse.julialang.org/u/Phil_Tomson)
#### Post date: [November 16, 2017, 8:00pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/12 "2017-11-16T20:00:40Z")

</div>

Are convolutional layers still in the works?

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [November 16, 2017, 9:25pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/13 "2017-11-16T21:25:24Z")

</div>

Currently we have implementation of convolutions for both - CPU and GPU, but they are not merged yet.

For CPU, we have an efficient implementation in C++ for Linux, but not for Windows. We are looking for options for compiling it on Windows or implementing them in pure Julia. See [FluxML/NNlib#2](https://github.com/FluxML/NNlib.jl/pull/2) for full discussion.

For GPU, there’s implementation in [CuConv.jl](https://github.com/dfdx/CuConv.jl) which I’m going to merge into [CUDNN.jl](https://github.com/JuliaGPU/CUDNN.jl) after a few more important functions from NVIDIA’s API are implemented.

---

<div class="post-metadata">

### Author: ![Phil\_Tomson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phil_tomson/32/3575_2.png) [@Phil\_Tomson](https://discourse.julialang.org/u/Phil_Tomson)
#### Post date: [November 17, 2017, 2:29am UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/14 "2017-11-17T02:29:58Z")

</div>

@dfdx: From reading those threads it looks like Flux and Knet are sort of converging - is that correct interpretation?

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [November 17, 2017, 8:22am UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/15 "2017-11-17T08:22:25Z")

</div>

Flux and Knet use a lot of common code - something most Python frameworks fail to provide - but their philosophy is still different.

---

<div class="post-metadata">

### Author: ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)
#### Post date: [November 18, 2017, 10:25am UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/16 "2017-11-18T10:25:29Z")

</div>

@dfdx, Could you elaborate on that?

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [November 18, 2017, 11:21am UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/17 "2017-11-18T11:21:17Z")

</div>

Flux is simpler and more layer-oriented. You have a set of predefined layers that you can chain together to obtain architecture you want. Here’s an example of RNN from Flux docs:

```julia
x = rand(10)
h = rand(5)

m = Flux.Recur(rnn, h)

y = m(x)

```

Knet is more low-level, but gives you more control. The analogous example from Knet:

```julia
function predict(w, s, x)
    x = x * w[end-2]
    for i = 1:2:length(s)
        (s[i],s[i+1]) = lstm(w[i],w[i+1],s[i],s[i+1],x)
        x = s[i]
    end
    return x * w[end-1] .+ w[end]
end

```

Of course, you can build more high-level functions in Knet or implement your own layers in Flux, but that’s not your normal workflow - you just choose what fits your mental model better. That’s what I call “different philosophy”.

There’s also some technical differences. For example, Knet doesn’t work on Windows and (presumably) requires CUDA which may not be available on your machine. Also I believe these libraries use somewhat different approaches to automatic differentiation.

Note, that I’m not (much) involved in development of any of these libraries, so it’s better to consult with their authors if you want to get more information. For me, it’s just two different libraries, and two is definitely better than zero 🙂

---

<div class="post-metadata">

### Author: ![dustyirwin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dustyirwin/32/14996_2.png) [@dustyirwin](https://discourse.julialang.org/u/dustyirwin)
#### Post date: [December 8, 2017, 10:19pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/18 "2017-12-08T22:19:59Z")

</div>

Thank you so much! I love Flux’s straight-forward, elegant manner without sacrificing flexibility. Looking forward to v0.3 and CNNs! Cheers 🙂

---

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [December 18, 2017, 9:54pm UTC](https://discourse.julialang.org/t/flux-3-now-with-100-more-julia/5824/19 "2017-12-18T21:54:49Z")

</div>

Just released Flux 0.4 with `Conv2D` support. Working on CPU now and GPU will follow shortly. Enjoy!
