-
Notifications
You must be signed in to change notification settings - Fork 22
/
07-NumDNN-ResNets.tex
378 lines (252 loc) · 8.93 KB
/
07-NumDNN-ResNets.tex
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
\documentclass[12pt,fleqn,beamer]{beamer}
\input{beamerStyle.tex}
\input{abbrv.tex}
\date{}
\title[ResNet]{Residual Neural Networks}
\subtitle{Numerical Methods for Deep Learning}
\begin{document}
\makebeamertitle
\begin{frame}[fragile]\frametitle{Deep Neural Networks in Practice}
\begin{columns}
\column{.75\textwidth}
(Some) challenges with deep networks
\begin{itemize}
\item
Computational costs (architecture have millions or billions of parameters)
\item
difficult to design
\item
difficult to train (exploding/vanishing gradients)
\item
unpredictable performance
\end{itemize}
\bigskip
\invisible<beamer|1>{
In 2015, He et al.~\cite{he2016deep,he2016identity} proposed a new architecture that solves many of the problems}
\column{.25\textwidth}
\invisible<beamer|1>{
\includegraphics[width=30mm]{resnet-wikimedia}}
\end{columns}
\only<beamer|2>{}
\end{frame}
% section motivation (end)
\section{Residual Neural Networks} % (fold)
\label{sec:residual_neural_networks}
\section{Residual Neural Networks} % (fold)
\label{sec:residual_neural_networks}
\begin{frame}[fragile]\frametitle{Simplified Residual Neural Network}
Residual Network
\bigskip
\begin{eqnarray*}
\bfY_1 &=& \bfY_0 + \sigma(\bfK_0\bfY_0 + \bfb_0) \\
\vdots &=& \vdots \\
\bfY_N &=& \bfY_{N-1} + \sigma( \bfK_{N-1}\bfY_{N-1} + \bfb_{N-1})
\end{eqnarray*}
And use $\bfY_N$ to classify. This leads to the optimization problem
$$
\min_{\bfK_{0,\ldots,N-1},\bfb_{0,\ldots,N-1},\bfW} \ \ E\left(\bfW\bfY_N(\bfK_1,\ldots,\bfK_{N-1},\bfb_1,\ldots, \bfb_{N-1}), \bfC^{\rm obs} \right)
$$
\bigskip
\begin{center}
Leads to smoother objective function~\cite{LiEtAl2017}.
\end{center}
\end{frame}
\begin{frame}
\frametitle{Learning Objective: Residual Neural Networks}
In this module we consider residual neural networks
\bigskip
Learning tasks:
\begin{itemize}
\item regression
\item segmentation
\item classification
\end{itemize}
\bigskip
Numerical methods:
\begin{itemize}
\item differential equations
\end{itemize}
\end{frame}
\begin{frame}\frametitle{Stability of Deep Residual Networks}
Why are ResNets more stable?
A small change
\begin{eqnarray*}
\bfY_1 &=& \bfY_0 + h \sigma(\bfK_0 \bfY_0 + \bfb_0) \\
\vdots &=& \vdots \\
\bfY_N &=& \bfY_{N-1} + h\sigma(\bfK_{N-1} \bfY_{N-1} + \bfb_{N-1})
\end{eqnarray*}
\bigskip
\pause
This is nothing but a forward Euler discretization
of the Ordinary Differential Equation (ODE)
$$ \partial_t \bfY(t) = \sigma(\bfK(t) \bfY(t) + \bfb(t)), \quad \quad \bfY(0) = \bfY_0 $$
Get intuition about ResNet behavior by using tools from nonlinear ODEs~\cite{HaberRuthotto2017,E2017}. A word of warning is~\cite{ascher2019discrete}.
\end{frame}
% section residual_neural_networks (end)
\section{Crash Course: ODE} % (fold)
\label{sec:crash_course_ode}
\begin{frame}\frametitle{ODE Crash Course}
Consider the ODE
$$ \partial_t \bfy(t) = f(\bfy(t)), \quad \bfy(0) = \bfy_0$$
with $f$ differentiable and Jacobian
$$ \bfJ(\bfy) = \left({\frac {\partial f}{\partial \bfy}}\right)^\top$$
Then (see also~\cite{AscherPetzold1998,AscherGreif2011,Ascher2010})
\begin{itemize}
\item If $Re({\rm eig}(\bfJ)) > 0\quad \quad \rightarrow$\ Unstable
\item If $Re({\rm eig}(\bfJ)) < 0\quad \quad \rightarrow$\ Stable ($\rightarrow$ to stationary point)
\item If $Re({\rm eig}(\bfJ)) = 0\quad \quad \rightarrow$\ Stable, energy bounded
\end{itemize}
Reality: $f$ time-dependent ($\leadsto$ penalize time derivatives of weights or use heavier tools, e.g., monotone operators, kinematic eigenvalues)
\end{frame}
\begin{frame}
\frametitle{Stability of Residual Network}
Assume forward propagation of single example $\bfy_0$
$$ \partial_t{\bfy}(t) = \sigma(\bfK(t) \bfy(t) + \bfb(t)), \quad \quad \bfy(0) = \bfy_0 $$
\bigskip
\pause
The Jacobian is
$$
\bfJ(t) = {\rm diag}\left(\sigma'(\bfK(t) \bfy(t) + \bfb(t))\right) \bfK(t)
$$
Here, $\sigma'(x) \geq 0$ for $\tanh$, ReLU, \ldots
\bigskip
\pause
Hence, we need to enforce stability. One option:
\begin{enumerate}
\item $\bfJ$ constant in time (or changes slowly)
\item $Re({\rm eig}(\bfK(t)))= 0$ for every $t$
\end{enumerate}
\pause
\begin{center}
Remember that we learn $\bfK$ $\leadsto$ ensure stability by regularization/constraints!
\end{center}
\end{frame}
\begin{frame}\frametitle{Residual Network as a Path Planning Problem}
\begin{center}
\includegraphics[width=\textwidth]{PathPlanning}
\end{center}
\bigskip
\pause
Forward propagation in residual network (continuous)
$$ \partial_t \bfY(t) = \sigma( \bfK(t) \bfY(t) + \bfb(t)), \qquad \bfY(0) = \bfY_0 $$
The goal is to plan a path (via $\bfK$ and $b$) such that the initial data can be linearly separated
\bigskip
\pause
Question: What is a layer, what is depth?
\end{frame}
\begin{frame}\frametitle{Stability: Continuous vs. Discrete}
Assume $\bfK$ is chosen so that the (continuous) forward propagation is stable
$$ \partial_t \bfY(t) = \sigma( \bfK(t) \bfY(t)+ \bfb(t)), \qquad \bfY(0) = \bfY_0 $$
And assume we use the forward Euler method to discretize
$$ \bfY_{l+1} = \bfY_{l} + h \sigma( \bfK_l \bfY_l + \bfb_l) $$
Is the network stable?
\bigskip
\pause
Not always ...
\end{frame}
\begin{frame}\frametitle{Stability: A Simple Example}
Look at the simplest possible forward propagation
$$ \partial_t \bfY(t) = \lambda\bfY(t), \qquad \lambda \in \C$$
And assume we use the forward Euler to discretize
$$ \bfY_{l+1} = \bfY_{l} + h \lambda \bfY_l = (1+h\lambda) \bfY_l$$
Then the method is stable only if
$$ |1+h\lambda| \le 1 $$
\bigskip
Not every network is stable! Time step size depends on $\lambda$ (which depends on $\bfK$ that is trained).
\end{frame}
\newcommand{\image}[1]{\includegraphics[width=35mm,trim=50 0 70 0,clip=true]{images/E10_Stability/#1}}
\newcommand{\rottext}[1]{\rotatebox{90}{\hbox to 40mm{\hss #1\hss}}}
\newcommand{\imageDiff}[1]{\includegraphics[width=35mm,trim=50 0 0 0,clip=true]{images/E10_Stability/#1}}
\begin{frame}
\frametitle{Why you should care about stability - 1}
$$
\min_\theta \hf \|\bfY_N(\theta) - \bfC\|_F^2 \quad \quad \bfY_{j+1}(\theta) = \bfY_j(\theta) + \frac{10}{N} \tanh \left( \bfK \bfY_j(\theta) \right)
$$
where $\bfC = \bfY_{200}(1,1)$, $\bfY_0 \sim \mathcal{N}(0,1)$, and
$$
\bfK(\theta) = \begin{pmatrix} -\theta_1-\theta_2 & \theta_1 & \theta_2 \\
\theta_2 & -\theta_1-\theta_2 & \theta_1 \\
\theta_1 & \theta_2 & -\theta_1-\theta_2 \end{pmatrix}
$$
\begin{center}
\begin{tabular}{cc}
objective, $N=5$ & objective, $N=100$\\
\image{Phic} &
\image{Phif}
\end{tabular}
\pause
\textbf{\tcr{Next: Compare different inputs $\sim$ generalization}}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Why you should care about stability - 2}
\begin{center}
\begin{tabular}{@{}c@{}c@{}c@{}c@{}}
& objective, $\bfY_0^{\rm train}$ & objective, $\bfY_0^{\rm test}$ & abs. diff\\
\rottext{unstable, $N=5$}
& \image{Phic}
& \image{Phict}
& \imageDiff{Phic-Phict}\\[-8mm]
\rottext{stable, $N=100$}
& \image{Phif}
& \image{Phift}
& \imageDiff{Phif-Phift}
\end{tabular}
\end{center}
\end{frame}
\begin{frame}[fragile]\frametitle{Stability: A Non-Trivial Example}
Consider the antisymmetric kernel model
$$
\bfK(t) = \bfK(t) - \bfK(t)^\top.
$$
Here, $Re({\rm eig}(\bfJ(t)))= 0$ for all $\bftheta$.
\bigskip
\pause
Assume we use the forward Euler to discretize
$$ \bfY_{l+1} = \bfY_{l} + h \sigma( (\bfK_l-\bfK_l^\top) \bfY_l + \bfb_l). $$
Tricky question: How to pick $h$ to ensure stability?
\pause
Answer: Impossible since eigenvalues of Jacobian are imaginary. Need other method than forward Euler.
\end{frame}
\begin{frame}
\frametitle{Multistep Methods}
For the antisymmetric kernel model
$$
\bfK(t) = \bfK(t) - \bfK(t)^\top
$$
forward Euler is unconditionally unstable. One way out is using higher-order Runge Kutta methods and small step size.
\bigskip
\begin{align*}
\bfZ_{l+1} & = \bfY_l + h f(\bftheta_l, \bfY_l) \\
\bfY_{l+1} & = \bfY_l + \frac{h}{2} \left( f(\bftheta_l, \bfY_l) + f(\bftheta_{l+1}, \bfZ_{l+1}) \right)
\end{align*}
Better options: RK3, RK4, semi-implicit time stepping.
\end{frame}
\section{Summary} % (fold)
\label{sec:numerical_optimization}
\begin{frame}[fragile]\frametitle{$\Sigma$: Residual Neural Networks}
Idea: Add a skip connection to multilayer perceptrons
Discrete:
\begin{equation*}
\bfY_{l+1} = \red{\bfY_{l}} + \sigma(\bfK_l \bfY_l + \bfb_l)
\end{equation*}
Continuous:
\begin{equation*}
\partial_t \bfY(t) = \sigma(\bfK(t) \bfY(t) + \bfb(t))
\end{equation*}
Discussion:
\begin{itemize}
\item train well with hundreds of layers
\item won many awards and competitions
\item can be analyzed as a differential equation
\item ResNets are generally not stable
\item Change differential equation and(!) discretization to achieve stability
\item next time: ResNet training and optimal control
\end{itemize}
\end{frame}
\begin{frame}[allowframebreaks]
\frametitle{References}
\bibliographystyle{abbrv}
\bibliography{NumDNN}
\end{frame}
\end{document}