254 lines
7.7 KiB
HTML
254 lines
7.7 KiB
HTML
<!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"/>
|
||
<link href="../assets/documenter.css" rel="stylesheet" type="text/css"/>
|
||
<script>
|
||
documenterBaseURL=".."
|
||
</script>
|
||
<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"/>
|
||
</head>
|
||
<body>
|
||
<nav class="toc">
|
||
<h1>
|
||
Flux
|
||
</h1>
|
||
<form class="search" action="../search.html">
|
||
<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>
|
||
<a class="toctext" href="../index.html">
|
||
Home
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<span class="toctext">
|
||
Building Models
|
||
</span>
|
||
<ul>
|
||
<li>
|
||
<a class="toctext" href="../models/basics.html">
|
||
Model Building Basics
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="../models/templates.html">
|
||
Model Templates
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="../models/recurrent.html">
|
||
Recurrence
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="../models/debugging.html">
|
||
Debugging
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<span class="toctext">
|
||
Other APIs
|
||
</span>
|
||
<ul>
|
||
<li>
|
||
<a class="toctext" href="batching.html">
|
||
Batching
|
||
</a>
|
||
</li>
|
||
<li class="current">
|
||
<a class="toctext" href="backends.html">
|
||
Backends
|
||
</a>
|
||
<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>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="storage.html">
|
||
Storing Models
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<span class="toctext">
|
||
In Action
|
||
</span>
|
||
<ul>
|
||
<li>
|
||
<a class="toctext" href="../examples/logreg.html">
|
||
Simple MNIST
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="../examples/char-rnn.html">
|
||
Char RNN
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="../contributing.html">
|
||
Contributing & Help
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a class="toctext" href="../internals.html">
|
||
Internals
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</nav>
|
||
<article id="docs">
|
||
<header>
|
||
<nav>
|
||
<ul>
|
||
<li>
|
||
Other APIs
|
||
</li>
|
||
<li>
|
||
<a href="backends.html">
|
||
Backends
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
<a class="edit-page" href="https://github.com/MikeInnes/Flux.jl/tree/efcb9650da31c183b94b839f66aa3467d007c33f/docs/src/apis/backends.md">
|
||
<span class="fa">
|
||
|
||
</span>
|
||
Edit on GitHub
|
||
</a>
|
||
</nav>
|
||
<hr/>
|
||
</header>
|
||
<h1>
|
||
<a class="nav-anchor" id="Backends-1" href="#Backends-1">
|
||
Backends
|
||
</a>
|
||
</h1>
|
||
<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>
|
||
<p>
|
||
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>
|
||
directly won't have great performance. In order to run a computationally intensive training process, we rely on a backend like MXNet or TensorFlow.
|
||
</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)
|
||
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>
|
||
.
|
||
</p>
|
||
<footer>
|
||
<hr/>
|
||
<a class="previous" href="batching.html">
|
||
<span class="direction">
|
||
Previous
|
||
</span>
|
||
<span class="title">
|
||
Batching
|
||
</span>
|
||
</a>
|
||
<a class="next" href="storage.html">
|
||
<span class="direction">
|
||
Next
|
||
</span>
|
||
<span class="title">
|
||
Storing Models
|
||
</span>
|
||
</a>
|
||
</footer>
|
||
</article>
|
||
</body>
|
||
</html>
|