2017-02-18 15:11:53 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" / >
< title >
Backends · Flux
< / title >
< script >
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36890222-9', 'auto');
ga('send', 'pageview');
< / script >
< link href = "https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel = "stylesheet" type = "text/css" / >
< link href = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/default.min.css" rel = "stylesheet" type = "text/css" / >
< link href = "https://fonts.googleapis.com/css?family=Lato|Ubuntu+Mono" rel = "stylesheet" type = "text/css" / >
< link href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel = "stylesheet" type = "text/css" / >
2017-02-20 11:05:06 +00:00
< link href = "../assets/documenter.css" rel = "stylesheet" type = "text/css" / >
2017-02-18 15:11:53 +00:00
< script >
2017-02-20 11:05:06 +00:00
documenterBaseURL=".."
2017-02-18 15:11:53 +00:00
< / script >
2017-02-20 11:05:06 +00:00
< script src = "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main = "../assets/documenter.js" > < / script >
< script src = "../../versions.js" > < / script >
< link href = "../../flux.css" rel = "stylesheet" type = "text/css" / >
2017-02-18 15:11:53 +00:00
< / head >
< body >
< nav class = "toc" >
< h1 >
Flux
< / h1 >
2017-02-20 11:05:06 +00:00
< form class = "search" action = "../search.html" >
2017-02-18 15:11:53 +00:00
< select id = "version-selector" onChange = "window.location.href=this.value" >
< option value = "#" selected = "selected" disabled = "disabled" >
Version
< / option >
< / select >
< input id = "search-query" name = "q" type = "text" placeholder = "Search docs" / >
< / form >
< ul >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../index.html" >
2017-02-18 15:11:53 +00:00
Home
< / a >
< / li >
< li >
< span class = "toctext" >
Building Models
< / span >
< ul >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../models/basics.html" >
2017-02-18 15:11:53 +00:00
Model Building Basics
< / a >
< / li >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../models/templates.html" >
2017-02-18 15:11:53 +00:00
Model Templates
< / a >
< / li >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../models/recurrent.html" >
2017-02-18 15:11:53 +00:00
Recurrence
< / a >
< / li >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../models/debugging.html" >
2017-02-18 15:11:53 +00:00
Debugging
< / a >
< / li >
< / ul >
< / li >
< li >
2017-02-20 10:53:09 +00:00
< span class = "toctext" >
Other APIs
< / span >
< ul >
< li >
< a class = "toctext" href = "batching.html" >
2017-02-18 15:11:53 +00:00
Batching
2017-02-20 10:53:09 +00:00
< / a >
< / li >
< li class = "current" >
< a class = "toctext" href = "backends.html" >
2017-02-18 15:11:53 +00:00
Backends
2017-02-20 10:53:09 +00:00
< / a >
2017-02-21 18:33:28 +00:00
< ul class = "internal" >
< li >
< a class = "toctext" href = "#Basic-Usage-1" >
Basic Usage
< / a >
< / li >
< li >
< a class = "toctext" href = "#Native-Integration-1" >
Native Integration
< / a >
< / li >
< / ul >
2017-02-20 10:53:09 +00:00
< / li >
< / ul >
2017-02-18 15:11:53 +00:00
< / li >
< li >
< span class = "toctext" >
In Action
< / span >
< ul >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../examples/logreg.html" >
2017-02-18 15:11:53 +00:00
Logistic Regression
< / a >
< / li >
< / ul >
< / li >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../contributing.html" >
2017-02-18 15:11:53 +00:00
Contributing & Help
< / a >
< / li >
< li >
2017-02-20 11:05:06 +00:00
< a class = "toctext" href = "../internals.html" >
2017-02-18 15:11:53 +00:00
Internals
< / a >
< / li >
< / ul >
< / nav >
< article id = "docs" >
< header >
< nav >
< ul >
< li >
2017-02-20 10:53:09 +00:00
Other APIs
< / li >
< li >
2017-02-18 15:11:53 +00:00
< a href = "backends.html" >
Backends
< / a >
< / li >
< / ul >
2017-02-21 21:43:19 +00:00
< a class = "edit-page" href = "https://github.com/MikeInnes/Flux.jl/tree/c05ef6286aa284f818bb0f3b90d4347efe8c29e6/docs/src/apis/backends.md" >
2017-02-18 15:11:53 +00:00
< span class = "fa" >
< / span >
Edit on GitHub
< / a >
< / nav >
< hr / >
< / header >
< h1 >
2017-02-21 18:33:28 +00:00
< a class = "nav-anchor" id = "Backends-1" href = "#Backends-1" >
Backends
2017-02-18 15:11:53 +00:00
< / a >
< / h1 >
2017-02-21 18:33:28 +00:00
< h2 >
< a class = "nav-anchor" id = "Basic-Usage-1" href = "#Basic-Usage-1" >
Basic Usage
< / a >
< / h2 >
< pre > < code class = "language-julia" > model = Chain(Affine(10, 20), σ , Affine(20, 15), softmax)
xs = rand(10)< / code > < / pre >
2017-02-18 15:11:53 +00:00
< p >
2017-02-21 18:33:28 +00:00
Currently, Flux' s pure-Julia backend has no optimisations. This means that calling
< / p >
< pre > < code class = "language-julia" > model(rand(10)) #> [0.0650, 0.0655, ...]< / code > < / pre >
< p >
2017-02-21 20:16:07 +00:00
directly won' t have great performance. In order to run a computationally intensive training process, we rely on a backend like MXNet or TensorFlow.
2017-02-21 18:33:28 +00:00
< / p >
< p >
This is easy to do. Just call either
< code > mxnet< / code >
or
< code > tf< / code >
on a model to convert it to a model of that kind:
< / p >
< pre > < code class = "language-julia" > mxmodel = mxnet(model, (10, 1))
mxmodel(xs) #> [0.0650, 0.0655, ...]
# or
tfmodel = tf(model)
tfmodel(xs) #> [0.0650, 0.0655, ...]< / code > < / pre >
< p >
These new models look and feel exactly like every other model in Flux, including returning the same result when you call them, and can be trained as usual using
< code > Flux.train!()< / code >
. The difference is that the computation is being carried out by a backend, which will usually give a large speedup.
< / p >
< h2 >
< a class = "nav-anchor" id = "Native-Integration-1" href = "#Native-Integration-1" >
Native Integration
< / a >
< / h2 >
< p >
Flux aims to provide high-level APIs that work well across backends, but in some cases you may want to take advantage of features specific to a given backend. In these cases it' s easy to " drop down" and use the backend' s API directly, where appropriate. For example:
< / p >
< pre > < code class = "language-julia" > using MXNet
Flux.loadmx()
mxmodel = mx.FeedForward(model)< / code > < / pre >
< p >
This returns a standard
< code > mx.FeedForward< / code >
instance, just like you might have created using MXNet' s usual API. You can then use this with MXNet' s data provider implementation, custom optimisers, or distributed training processes.
< / p >
< p >
Same goes for TensorFlow, where it' s easy to create a
< code > Tensor< / code >
object:
< / p >
< pre > < code class = "language-julia" > using TensorFlow
Flux.loadtf()
x = placeholder(Float32)
y = Tensor(model, x)< / code > < / pre >
< p >
This makes makes it easy to take advantage of Flux' s model description and debugging tools while also getting the benefit of the work put into these backends. You can check out how this looks with the integration examples
< a href = "https://github.com/MikeInnes/Flux.jl/tree/master/examples" >
here
< / a >
.
2017-02-18 15:11:53 +00:00
< / p >
< footer >
< hr / >
< a class = "previous" href = "batching.html" >
< span class = "direction" >
Previous
< / span >
< span class = "title" >
Batching
< / span >
< / a >
2017-02-20 11:05:06 +00:00
< a class = "next" href = "../examples/logreg.html" >
2017-02-18 15:11:53 +00:00
< span class = "direction" >
Next
< / span >
< span class = "title" >
Logistic Regression
< / span >
< / a >
< / footer >
< / article >
< / body >
< / html >