Skip to content

Commit

Permalink
Deploying to gh-pages from @ f0cb1e8 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
nityajoshi committed Nov 12, 2023
1 parent 7012753 commit 182ff2a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
27 changes: 15 additions & 12 deletions __generated/trainerfunc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ function trainer(m, func, ln::Real=5)
schedule = Interpolator(Step(initial_lr, 0.5, [25, 10]), es)
optim = func(initial_lr)

logger = TensorBoardBackend("tblogs")

logcb = (LogMetrics(logger),)# LogHyperParams(logger))
valcb = Metrics(Metric(accfn; phase = TrainingPhase, name = "train_acc"),
Metric(accfn; phase = ValidationPhase, name = "val_acc"))
learner = Learner(m, lossfn;
data = (trainloader, valloader),
optimizer = optim,
callbacks = [ToGPU(), logcb..., valcb])

FluxTraining.fit!(learner, ln)
close(logger.logger)
logger = TensorBoardBackend("tblog")
try

logcb = (LogMetrics(logger),)# LogHyperParams(logger))
valcb = Metrics(Metric(accfn; phase = TrainingPhase, name = "train_acc"),
Metric(accfn; phase = ValidationPhase, name = "val_acc"))
learner = Learner(m, lossfn;
data = (trainloader, valloader),
optimizer = optim,
callbacks = [ToGPU(), logcb..., valcb])

FluxTraining.fit!(learner, ln)
finally
close(logger.logger)
end

# save model
m = learner.model |> cpu
Expand Down
29 changes: 17 additions & 12 deletions _tutorials/trainerfunc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ function trainer(m, func, ln::Real=5)
schedule = Interpolator(Step(initial_lr, 0.5, [25, 10]), es)
optim = func(initial_lr)
# callbacks
logger = TensorBoardBackend("tblogs")
# schcb = Scheduler(LearningRate => schedule)
logcb = (LogMetrics(logger),)# LogHyperParams(logger))
valcb = Metrics(Metric(accfn; phase = TrainingPhase, name = "train_acc"),
Metric(accfn; phase = ValidationPhase, name = "val_acc"))
learner = Learner(m, lossfn;
data = (trainloader, valloader),
optimizer = optim,
callbacks = [ToGPU(), logcb..., valcb])

FluxTraining.fit!(learner, ln)
close(logger.logger)
logger = TensorBoardBackend("tblog")
try

# schcb = Scheduler(LearningRate => schedule)
logcb = (LogMetrics(logger),)# LogHyperParams(logger))
valcb = Metrics(Metric(accfn; phase = TrainingPhase, name = "train_acc"),
Metric(accfn; phase = ValidationPhase, name = "val_acc"))
learner = Learner(m, lossfn;
data = (trainloader, valloader),
optimizer = optim,
callbacks = [ToGPU(), logcb..., valcb])

FluxTraining.fit!(learner, ln)
finally
close(logger.logger)
end

## save model
m = learner.model |> cpu
Expand All @@ -56,4 +61,4 @@ end
#m = resize_nobn(m)
#m = desaturate(m)
#m = rebn(m)
#m = trainer(m, 1)
#m = trainer(m, 1)
Binary file modified assets/tutorials.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/tutorials/bitstream/code/output/ex10.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0040000000000000036
0.01100000000000001
2 changes: 1 addition & 1 deletion assets/tutorials/bitstream/code/output/ex4.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SBit(pos = true, neg = false)
SBit(pos = false, neg = false)
2 changes: 1 addition & 1 deletion assets/tutorials/pruning/code/output/ex7.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Propagated MobileNet Mults 4992057 Adds 4887057
Propagated MobileNet Mults 4968641 Adds 4866825
2 changes: 1 addition & 1 deletion assets/tutorials/pruning/code/output/ex8.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Resized MobileNet Mults 3671590 Adds 3518013
Resized MobileNet Mults 3638364 Adds 3487521
4 changes: 2 additions & 2 deletions tutorials/bitstream/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
x = SBitstream(<span class=hljs-number >0.3</span>)</code></pre><pre><code class="plaintext hljs">SBitstream{Float64}(value = 0.3)
with 0 bits.</code></pre> <p>Here, we created a <code>SBitstream</code> &#40;the type in BitSAD for stochastic bitstreams&#41; encoding the real value 0.3. <code>SBitstream</code> will keep track of the mean of the Bernoulli distribution, which we can recover with <code>float</code>.</p> <pre><code class="julia hljs">float(x)</code></pre><pre><code class="plaintext hljs">0.3</code></pre>
<p>You&#39;ll also notice that there were &quot;0 bits enqueue&quot; in <code>x</code>. This refers to the fact that the bitstream, <code>x</code>, is a sequence of samples. Currently, we have not drawn any samples from <code>x</code>. We can try that now:</p>
<pre><code class="julia hljs">xt = pop!(x)</code></pre><pre><code class="plaintext hljs">SBit(pos = true, neg = false)</code></pre>
<pre><code class="julia hljs">xt = pop!(x)</code></pre><pre><code class="plaintext hljs">SBit(pos = false, neg = false)</code></pre>
<p>Now, we have a single sample, <code>xt</code>, which is of type <code>SBit</code>. An <code>SBit</code> is a &quot;stochastic bit&quot; which is just a convenient alias for a <a href="https://docs.julialang.org/en/v1.6/manual/functions/#Named-Tuples"><code>NamedTuple</code></a> with two parts –- the positive part &#40;<code>pos</code>&#41; and the negative part &#40;<code>neg</code>&#41;.</p>
<blockquote>
<p>Wait, I thought stochastic bitstreams were a single bit sequence? <br /> –- You &#40;probably&#41;</p>
Expand Down Expand Up @@ -51,7 +51,7 @@ <h2 id=operations_on_sbitstreams ><a href="#operations_on_sbitstreams" class=hea
push!(z, zbit)
<span class=hljs-keyword >end</span>

abs(estimate(z) - float(z))</code></pre><pre><code class="plaintext hljs">0.0040000000000000036</code></pre>
abs(estimate(z) - float(z))</code></pre><pre><code class="plaintext hljs">0.01100000000000001</code></pre>
<p>We used a helper function, <code>multiply_sbit</code> to multiply the positive and negative channel of each <code>SBit</code> separately. This resulted in a new <code>SBit</code>, <code>zbit</code>, which we pushed onto <code>z</code>. When we take the empirical average of all these <code>zbit</code>s, we see that it is close to the true mean of <code>z</code>.</p>
<p>Hopefully, you can now see why stochastic computing can be so resource efficient. Each channel of <code>multiply_sbit</code> only needed to multiply two 1-bit numbers. This can be done with a single AND gate.</p>

Expand Down
4 changes: 2 additions & 2 deletions tutorials/pruning/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ <h3 id=propagating_the_pruning ><a href="#propagating_the_pruning" class=header-
<pre><code class="julia hljs">m_pruned = keepprune(m_ch_pruned)
m_prop = prune_propagate(m_pruned)
mults, adds, output_size = compute_dot_prods(m_prop, (<span class=hljs-number >96</span>, <span class=hljs-number >96</span>, <span class=hljs-number >3</span>, <span class=hljs-number >1</span>))
println(<span class=hljs-string >&quot;Propagated MobileNet Mults &quot;</span>, mults, <span class=hljs-string >&quot; Adds &quot;</span>, adds)</code></pre><pre><code class="plaintext hljs">Propagated MobileNet Mults 4992057 Adds 4887057
println(<span class=hljs-string >&quot;Propagated MobileNet Mults &quot;</span>, mults, <span class=hljs-string >&quot; Adds &quot;</span>, adds)</code></pre><pre><code class="plaintext hljs">Propagated MobileNet Mults 4968641 Adds 4866825
</code></pre>
<h3 id=resizing_the_propagated_model ><a href="#resizing_the_propagated_model" class=header-anchor >Resizing the propagated model</a></h3>
<p>If enough nodes get pruned out, there would be slices in the model which accomplish nothing, computationally. Instead of wasting resources on passing these kernels full of zeros around, they can be eliminated from the structure of our model.</p>
<pre><code class="julia hljs">m_resized = resize(m_prop)
mults, adds, output_size = compute_dot_prods(m_resized, (<span class=hljs-number >96</span>, <span class=hljs-number >96</span>, <span class=hljs-number >3</span>, <span class=hljs-number >1</span>))
println(<span class=hljs-string >&quot;Resized MobileNet Mults &quot;</span>, mults, <span class=hljs-string >&quot; Adds &quot;</span>, adds)</code></pre><pre><code class="plaintext hljs">Resized MobileNet Mults 3671590 Adds 3518013
println(<span class=hljs-string >&quot;Resized MobileNet Mults &quot;</span>, mults, <span class=hljs-string >&quot; Adds &quot;</span>, adds)</code></pre><pre><code class="plaintext hljs">Resized MobileNet Mults 3638364 Adds 3487521
</code></pre>
<h3 id=pruning_and_finetuning_pipeline ><a href="#pruning_and_finetuning_pipeline" class=header-anchor >Pruning and Finetuning pipeline</a></h3>
<p>Now that we seen how to prune our model, let&#39;s try to finetune it to recover some of the accuracy we lost. A basic template setup for training the model is provided by trainer function, and can be used as a starting point for your own training methodology.</p>
Expand Down

0 comments on commit 182ff2a

Please sign in to comment.