Flux is an elegant approach to machine learning. It's a 100% pure-Julia stack, and provides lightweight abstractions on top of Julia's native GPU and AD support. Flux makes the easy things easy while remaining fully hackable.
Flux has powerful high-level features, and common architectures can be defined in a few lines.
model = Chain( Dense(768, 128), LSTM(128, 256) LSTM(256, 128) Dense(128, 10), softmax) loss(x, y) = crossentropy(model(x), y) Flux.train!(loss, data, ADAM(...))
Yet you can easily strip away the layers, and directly write the mathematics for your problem. Flux will seamlessly take gradients of any Julia code, so your model looks just like the paper.
W = param(randn(2, 10)) b = param(randn(2)) y(x) = σ.(W * x .+ b)
If that's still not enough, you can go as deep as you want, even writing your own CUDA kernels! All this can be freely mixed-and-matched in a single model or script, and it all runs interactively via Jupyter or Juno.
function gpu_add(a, b, c) i = (blockIdx().x-1) * blockDim().x + threadIdx().x c[i] = a[i] + b[i] return nothing end
Unusual architectures are no problem in Flux, as you can use all the loops, control flow and even macros that you're used to. Here's a Tree RNN in 4 lines.
tree() = rand() < 0.5 ? rand(10) : (tree(), tree()) # dummy data shrink = Dense(20, 10) combine(a, b) = shrink([a; b]) model(x) = x model(x::Tuple) = combine(model(x), model(x)) model(tree()) # Sample output
Despite this flexibility, Julia's advanced compiler lets us do some powerful optimisations. For example, this definition of
sigmoid automatically gets fused into a single GPU kernel – so it's really fast.
sigmoid(xs) = 1 ./ (1 .+ exp.(.-xs))
For more on our philosophy on machine learning, check out our article On Machine Learning & Programming Languages.
For general questions and help, check out Julia's community forum.
Flux development is carried out via our GitHub issues, so feel free to open feature requests or PRs here.
For more informal discussions we'd love to have you on the Julia slack, where we hang out on the #machine-learning channel.
1 day ago