-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (275 loc) · 9.54 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>PyTorch-reveal.js</title>
<link rel="stylesheet" href="reveal.js/dist/reset.css">
<link rel="stylesheet" href="reveal.js/dist/reveal.css">
<link rel="stylesheet" href="reveal.js/dist/theme/black.css" id="theme">
<link rel="icon" href="assets/images/pytorch_favicon.ico">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="reveal.js/plugin/highlight/zenburn.css" id="highlight-theme">
<!-- For overriding Reveal.js defaults -->
<link rel="stylesheet" href="assets/css/slides.css">
</head>
<body>
<!-- Hierarchy: reveal > slides > section -->
<div class="reveal">
<!-- Beginning Presentations -->
<div class="slides">
<!-- Intro Page -->
<section>
<h1>PyTorch <span style="color: #ff55ff">|</span> Deep Learning</h1>
</section>
<!-- What is PyToch? -->
<section>
<section>
<h2> What is PyTorch? </h2>
<ul>
<li class="fragment fade-in">Open-source Machine Learning library</li>
<li class="fragment fade-in">Based on the Torch library (Lua)</li>
<li class="fragment fade-in">Employed at:
<ul>
<li>Facebook AI Research</li>
<li>Tesla Autopilot</li>
<li>Uber AI</li>
</ul>
</li>
</ul>
</section>
<section>
<h2> What is PyTorch? </h2>
<ul>
<li class="fragment fade-in">Tape-based Automatic Differentiation</li>
<li class="fragment fade-in">Computations with GPU Acceleration</li>
</ul>
<footer class="fragment fade-in" style="color:#ffff00">and much more...</footer>
</section>
<section>
<h2> PyTorch Tensor </h2>
<img data-src="assets/images/pytorch_tensor.svg">
</section>
<section>
<h2> PyTorch Tensor </h2>
<img data-src="assets/images/pytorch_parameter.svg">
<p>Parameters of interest!</p>
<code>(x.requires_grad=True)</code> $\cap$ <code>(x.is_leaf=True)</code>
</section>
</section>
<!-- AD -->
<section>
<section>
<h2> Automatic Differentiation (<em>AD</em>) </h2>
<ul>
<li class="fragment fade-in">Implementing backprop by hand is cumbersome!</li>
<li class="fragment fade-in">Gradient-based Learning: Derivatives!</li>
<li class="fragment fade-in">A way to compute derivatives automatically?</li>
</ul>
</section>
<section>
<h2> Automatic Differentiation (<em>AD</em>) </h2>
<ul>
<li><span style="color:#ffff00">It is not</span>: Numerical Differentiation
<ul>
<li>Expensive (forward pass for each derivative)</li>
<li>Numerical error gets propagated!!</li>
</ul>
</li>
<li class="fragment fade-in">In contrast, <em>AD</em> is efficient and numerically stable.</li>
</ul>
</section>
<section>
<h2>Automatic Differentiation (<em>AD</em>)</h2>
<ul>
<li><span style="color:#ffff00">It is not</span>: Symbolic Differentiation
<ul><li>Complicated expressions (redundant)</li></ul>
</li>
<li class="fragment fade-in"><em>AD</em> provides the computed value and not the expression.</li>
</ul>
</section>
<section>
<h2>Example</h2>
<table class="reveal" cellspacing="0" cellpadding="0">
<tr>
<td> <span style="font-weight:bold">Expression</span> </td>
<td> <span style="font-weight:bold">Derivative</span> </td>
</tr>
<tr>
<td>initialize: $w, b$ </td>
<td>$ \frac{\partial\mathcal{L}}{\partial w}=\frac{\partial\mathcal{L}}{\partial z} x, \frac{\partial\mathcal{L}}{\partial b}=\frac{\partial\mathcal{L}}{\partial z} $</td>
</tr>
<tr>
<td>$ z=wx+b $</td>
<td>$ \frac{\partial\mathcal{L}}{\partial z}=\frac{\partial\mathcal{L}}{\partial y}\sigma^{'}(z) $</td>
</tr>
<tr>
<td>$ y=\sigma(z) $</td>
<td>$ \frac{\partial \mathcal{L}}{\partial y}=y-t $</td>
</tr>
<tr>
<td>$ \mathcal{L}=\frac{1}{2}(y-t)^2 $</td>
<td>$ \frac{\partial\mathcal{L}}{\partial\mathcal{L}}=1 $</td>
</tr>
</table>
<footer>Reference: <a href="https://www.cs.toronto.edu/~rgrosse/courses/csc321_2018/slides/lec10.pdf">CSC312@Toronto</a></footer>
</section>
<section>
<h2>Example: <code>torch.autograd</code></h2>
<pre class="python"><code data-trim data-noescape data-line-numbers="3-5|7-9|11-12">
import torch
w = torch.tensor([1.2], requires_grad=True)
b = torch.tensor([-0.4], requires_grad=True)
x, t = torch.tensor([2.0]), torch.tensor([1.0])
z = w*x + b
y = torch.sigmoid(z)
L = 0.5*(y-t)**2
L.backward() # compute dL/dw, dL/db
w.grad, b.grad # (tensor([-0.0250]), tensor([-0.0125]))
</code></pre>
<footer class="fragment fade-in">
<span style="color:#ffff00">backend</span>: convertion to primitive ops...
</footer>
</section>
<section>
<h2>Example: <code>torch.autograd</code></h2>
<pre class="python"><code data-line-numbers data-trim data-noescape>
# higher-order derivatives
import torch
x = torch.tensor([3.], requires_grad=True)
y = x**2
dy_dx = torch.autograd.grad(y, x, create_graph=True) <span class="fragment fade-in"># 6</span>
d2y_dx2 = torch.autograd.grad(dy_dx, x) <span class="fragment fade-in"># 2</span>
</code></pre>
</section>
<section>
<code>torch.autograd</code>: An engine for computing vector-Jacobian products!
<medium>Head over to the <a href="https://pytorch.org/docs/stable/autograd.html"><code>torch.autograd</code> Documentation</a></medium>
</section>
</section/>
<!-- GPU -->
<section>
<section>
<h2>Why GPU?</h2>
<ul>
<li>Data-parallelism!</li>
<li>Neural Networks: Parallel processing systems</li>
</ul>
</section>
<section>
<h2>Shifting to GPU</h2>
<pre><code class="pythonrepl" data-trim data-noescape>
>> import torch
>> x = torch.tensor([2.]) <span class="fragment fade-in"># defined on CPU</span>
>> x.device()
device(type='cpu')
>> x_gpu = x.cuda() <span class="fragment fade-in"># shifted to GPU</span>
>> x_gpu
tensor([2.], device='cuda:0')
</pre></code>
</section>
</section>
<!-- Optimization Loop -->
<section>
<h2>Optimization Loop</h2>
<img data-src="assets/images/optimization_loop.svg">
</section>
<!-- Linear Regression -->
<section>
<h2>Example: Linear Regression</h2>
<img data-src="assets/images/linear_regression.svg">
</section>
<section data-background-iframe="assets/notebooks/linear_regression.slides.html">
</section>
<section>
<h3>Why are we doing Linear Regression?</h3>
</section>
<!-- Going Futher -->
<section>
<section>
<h3>Example: <code>Image Classification Network</code></h3>
<img data-src="assets/images/fashion_mnist.svg">
</section>
<section>
<h3>Example: <code>Image Classification Network</code></h3>
<pre class="python"><code data-line-numbers="4|5-13|15-23" data-trim data-noescape>
import torch.nn as nn
import torch.nn.Functional as F
class NeuralNetwork(torch.nn.Module):
def __init__(self):
self.conv1 = torch.nn.Conv2d(in_channels=3,
out_channels=64, kernel_size=(3,3))
self.conv2 = torch.nn.Conv2d(in_channels=64,
out_channels=128, kernel_size=(3,3))
self.maxpool = torch.nn.MaxPool2D(kernel_size=(3,3))
self.linear1 = torch.nn.Linear(..., 128)
self.linear2 = torch.nn.Linear(128, 64)
self.linear3 = torch.nn.Linear(64, 10)
def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = self.maxpool(x)
x = torch.flatten(x, 1)
x = F.relu(self.linear1(x))
x = F.relu(self.linear2(x))
x = F.softmax(self.linear3(x))
return x
</code></pre>
</section>
<section>
<h2>Built-in Modules</h2>
<ul>
<li><code>torch.nn</code></li>
<li><code>torch.optim</code></li>
<li><code>torch.utils</code></li>
</ul>
</section>
</section>
<!-- Some more interesting things -->
<section>
<h2>Advanced Practices</h2>
<ul>
<li>Data Augmentation</li>
<li>Tensorboard</li>
<li>Multiprocessing</li>
<li>Multi-GPU training</li>
</ul>
</section>
<!-- Questions -->
<section>
<h2>Questions?</h2>
</section>
</div>
</div>
<script src="reveal.js/dist/reveal.js"></script>
<script src="reveal.js/plugin/notes/notes.js"></script>
<script src="reveal.js/plugin/markdown/markdown.js"></script>
<script src="reveal.js/plugin/highlight/highlight.js"></script>
<script src="reveal.js/plugin/math/math.js"></script>
<script src="reveal.js/plugin/zoom/zoom.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
// Parallax background image
parallaxBackgroundImage: "assets/images/pytorch_background.jpg",
// Parallax background size
parallaxBackgroundSize: "2100px 900px",
hash: true,
controls: true,
progress: true,
loop: false,
history: false,
transition: 'fade',
backgroundTransition: 'slide',
width: 1280,
height: 960,
minScale: '0.2',
maxScale: '1.5',
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes, RevealMath, RevealZoom ]
});
</script>
</body>
</html>