MALI: A MEMORY EFFICIENT AND REVERSE ACCURATE INTEGRATOR FOR N EURAL ODE S
Anonymous authors
Paper under double-blind review
A BSTRACT
Neural ordinary differential equations (Neural ODEs) are a new family of deeplearning models with continuous depth.
However, the numerical estimation of the gradient in the continuous case is not well solved: existing implementations of the adjoint method suffer from inaccuracy in reverse-time trajectory, while the naive method and the adaptive checkpoint adjoint method (ACA) have a memory cost that grows with integration time.
In this project, based on the asynchronous leapfrog (ALF) solver, we propose the Memory-efﬁcient ALF Integrator (MALI), which has a constant memory cost w.r.t number of solver steps in integration similar to the adjoint method, and guarantees accuracy in reverse-time trajectory (hence accuracy in gradient estimation).
We validate MALI in various tasks: on image recognition tasks, to our knowledge, MALI is the ﬁrst to enable feasible training of a Neural ODE on ImageNet and outperform a well-tuned ResNet, while existing methods fail due to either heavy memory burden or inaccuracy; for time series modeling, MALI signiﬁcantly outperforms the adjoint method; and for continuous generative models, MALI achieves new state-of-the-art performance.
I NTRODUCTION
Recent research builds the connection between continuous models and neural networks.
The theory of dynamical systems has been applied to analyze the properties of neural networks or guide the design of networks (Weinan, 2017; Ruthotto & Haber, 2019; Lu et al., 2018).
In these works, a residual block (He et al., 2016) is typically viewed as a one-step Euler discretization of an ODE; instead of directly analyzing the discretized neural network, it might be easier to analyze the ODE.
Another direction is the neural ordinary differential equation (Neural ODE) (Chen et al., 2018), which takes a continuous depth instead of discretized depth.
The dynamics of a Neural ODE is typically approximated by numerical integration with adaptive ODE solvers.
Neural ODEs have been applied in irregularly sampled time-series (Rubanova et al., 2019), free-form continuous generative models (Grathwohl et al., 2018; Finlay et al., 2020), mean-ﬁeld games (Ruthotto et al., 2020), stochastic differential equations (Li et al., 2020) and physically informed modeling (SanchezGonzalez et al., 2019; Zhong et al., 2019).
Though the Neural ODE has been widely applied in practice, how to train it is not extensively studied.
The naive method directly backpropagates through an ODE solver, but tracking a continuous trajectory requires a huge memory.
Chen et al.
(2018) proposed to use the adjoint method to determine the gradient in continuous cases, which achieves constant memory cost w.r.t integration time; however, as pointed out by Zhuang et al.
(2020), the adjoint method suffers from numerical errors due to the inaccuracy in reverse-time trajectory.
Zhuang et al.
(2020) proposed the adaptive checkpoint adjoint (ACA) method to achieve accuracy in gradient estimation at a much smaller memory cost compared to the naive method, yet the memory consumption of ACA still grows linearly with integration time.
Due to the non-constant memory cost, neither ACA nor naive method are suitable for large scale datasets (e.g. ImageNet) or high-dimensional Neural ODEs (e.g. FFJORD (Grathwohl et al., 2018)).
In this project, we propose the Memory-efﬁcient Asynchronous Leapfrog Integrator (MALI) to achieve advantages of both the adjoint method and ACA: constant memory cost w.r.t integration time and accuracy in reverse-time trajectory.
MALI is based on the asynchronous leapfrog (ALF) integrator (Mutze, 2013).
With the ALF integrator, each numerical step forward in time is reversible.
Therefore, with MALI, we delete the trajectory and only keep the end-time states, hence achieve constant memory cost w.r.t integration time; using the reversibility, we can accurately reconstruct the trajectory from the end-time value, hence achieve accuracy in gradient.
Our contributions are:
We propose a new method (MALI) to solve Neural ODEs, which achieves constant memory cost w.r.t number of solver steps in integration and accuracy in gradient estimation.
We provide theoretical analysis.
We validate our method with extensive experiments: (a) for image classiﬁcation tasks, MALI enables a Neural ODE to achieve better accuracy than a well-tuned ResNet with the same number of parameters; to our knowledge, MALI is the ﬁrst method to enable training of Neural ODEs on a large-scale dataset such as ImageNet, while existing methods fail due to either heavy memory burden or inaccuracy.
(b) In time-series modeling, MALI achieves comparable or better results than other methods.
(c) For generative modeling, a FFJORD model trained with MALI achieves new state-of-the-art results on MNIST and Cifar10.
P RELIMINARIES 2. N UMERICAL I NTEGRATION M ETHODS
An ordinary differential equation (ODE) typically takes the form
[Equation]
where z ( t ) is the hidden state evolving with time, T is the end time, t 0 is the start time (typically 0), x is the initial state.
The derivative of z ( t ) w.r.t t is deﬁned by a function f , and f is deﬁned as a sequence of layers parameterized by θ .
The loss function is L ( z ( T ) , y ) , where y is the target variable.
Eq.
1 is called the initial value problem (IVP) because only z ( t 0 ) is speciﬁed.
[Table]
x , start time t 0 , end time T , error tolerance etol , initial stepsize h .
Initialize z (0) =
x, t = t
While t < T error est = ∞
While error est > etol h ← h × DecayFactor
ˆ z, error est
= ψ h ( t, z )
If error est < etol h ← h × IncreaseFactor t ← t + h, z ← ˆ z
Notations We summarize the notations following
Zhuang et al.
• z i ( t i ) /z
( τ i ) : hidden state in forward/reverse time trajectory at time t
i /τ i .
• ψ h ( t i , z i ) : the numerical solution at time t
i
+ h , starting from ( t i , z i ) with a stepsize h .
• N f , N z : N f is the number of layers in f in Eq.
1, N z is the dimension of z .
• N t /N
r : number of discretized points (outer iterations in Algo. 1) in forward / reverse integration.
• m : average number of inner iterations in Algo.to ﬁnd an acceptable stepsize.
Numerical Integration
The algorithm for general adaptive-stepsize numerical ODE solvers is summarized in Algo.
1 (Wanner & Hairer, 1996).
The solver repeatedly advances in time by a step, which is the outer loop in Algo.
1 (blue curve in Fig. 1).
For each step, the solver decreases the stepsize until the estimate of error is lower than the tolerance, which is the inner loop in Algo.
1 (green curve in
Fig. 1).
For ﬁxed-stepsize solvers, the inner loop is replaced with a single evaluation of ψ h ( t, z ) using predeﬁned stepsize h .
Different methods typically use different ψ , for example different orders of the Runge-Kutta method (Runge, 1895).
2. A NALYTICAL FORM OF GRADIENT IN CONTINUOUS CASE
We ﬁrst brieﬂy introduce the analytical form of the gradient in the continuous case, then we compare different numerical implementations in the literature to estimate the gradient.
The analytical form of the gradient in the continuous case is
[Equation]
[Table]
Adjoint
MALI/ACA
Naive
[Equation]
where a ( t ) is the “adjoint state”.
Detailed proof is given in (Pontryagin, 1962).
In the next section we compare different numerical implementations of this analytical form.
2. N UMERICAL IMPLEMENTATIONS IN THE LITERATURE FOR THE ANALYTICAL FORM
We compare different numerical implementations of the analytical form in this section.
The forwardpass and backward-pass of different methods are demonstrated in Fig.
1 and Fig.
2 respectively.
Forward-pass is similar for different methods.
The comparison of backward-pass among different methods are summarized in Table.
We explain methods in the literature below.
Naive method The naive method saves all of the computation graph (including search for optimal stepsize, green curve in Fig. 2) in memory, and backpropagates through it.
Hence the memory cost is
N z N f × N t × m and depth of computation graph are N f × N t × m , and the computation is doubled considering both forward and backward passes.
Besides the large memory and computation, the deep computation graph might cause vanishing or exploding gradient (Pascanu et al., 2013).
Adjoint method Note that we use “ adjoint state equation ” to refer to the analytical form in Eq.and 3, while we use “ adjoint method ” to refer to the numerical implementation by Chen et al.
As in Fig.
1 and 2, the adjoint method forgets forward-time trajectory (blue curve) to achieve memory cost N z N f which is constant to integration time; it takes the end-time state (derived from forward-time integration) as the initial state, and solves a separate IVP (red curve) in reverse-time.
Theorem 2.1.
(Zhuang et al., 2020)
For an ODE solver of order p , the error of the reconstructed initial value by the adjoint method is (cid:80) N − 1 k =0 (cid:2) h p +1 k
D Φ Tt k ( z k ) l ( t k , z k ) + ( − h k )
p +1 D
Φ t k T ( z k ) l ( t k , z k ) (cid:3) + O ( h p +1 ) , where Φ is the ideal solution, D Φ is the Jacobian of Φ , l ( t, z ) and l ( t, z ) are the local error in forward-time and reverse-time integration respectively.
Theorem 2.1 is stated as Theorem 3.2 in Zhuang et al.
(2020); please see reference paper for detailed proof.
To summarize, due to inevitable errors with numerical ODE solvers, the reverse-time trajectory (red curve, z ( τ ) ) cannot match the forward-time trajectory (blue curve, z ( t ) ) accurately.
The error in z propagates to d L d θ by Eq. 2, hence affects the accuracy in gradient estimation.
Adaptive checkpoint adjoint (ACA) To solve the inaccuracy of adjoint method, Zhuang et al.
(2020) proposed ACA: ACA stores forward-time trajectory in memory for backward-pass, hence guarantees accuracy; ACA deletes the search process (green curve in Fig. 2), and only backpropagates through the accepted step (blue curve in Fig. 2), hence has a shallower computation graph ( N f × N t for ACA vs N f × N t × m for naive method).
ACA only stores { z ( t i ) } N t i =1 , and deletes the computation graph for { f (cid:0) z ( t i ) , t i (cid:1) } N t i =1 , hence the memory cost is N z ( N f + N t ) .
Though the memory cost is much smaller than the naive method, it grows linearly with N t , and can not handle very high dimensional models.
In the following sections, we propose a method to overcome all these disadvantages of existing methods.
M ETHODS 3. A SYNCHRONOUS L EAPFROG I NTEGRATOR
In this section we give a brief introduction to the asynchronous leapfrog (ALF) method (Mutze, 2013), and we provide theoretical analysis which is missing in Mutze (2013).
For general ﬁrstorder ODEs in the form of Eq.
1, the tuple ( z, t ) is sufﬁcient for most ODE solvers to take a step numerically.
For ALF, the required tuple is ( z, v, t ) , where v is the “approximated derivative”.
Most numerical ODE solvers such as the Runge-Kutta method (Runge, 1895) track state z evolving with time, while ALF tracks the “augmented state” ( z, v ) .
We explain the details of ALF as below.
Algorithm 2: Forward
Input ( z in , v in , s in , h ) where s in is current time, z in and v in are correponding values at time s in , h is stepsize.
Forward s
= s in + h
[Equation]
Output
[Equation]
z
[Equation]
h )
Inverse
[Equation]
Output
[Equation]
Procedure of ALF Different ODE solvers have different ψ in Algo.
1, hence we only summarize ψ for
ALF in Algo.
Note that for a complete algorithm of integration for ALF, we need to plug Algo.
2 into
Algo.
The forward-pass is summarized in Algo.
Given stepsize h , with input ( z in , v in , s in ) , a single step of ALF outputs ( z out , v out , s out ) .
As in Fig. 3, given ( z 0 , v 0 , t 0 ) , the numerical forwardtime integration calls Algo.
2 iteratively:
[Equation]
Invertibility of ALF
An interesting property of ALF is that ψ deﬁnes a bijective mapping; therefore, we can reconstruct ( z in , v in , s in , h ) from ( z out , v out , s out , h ) , as demonstrated in Algo.
As in
Fig.
3, we can reconstruct the entire trajectory given the state ( z j , v j ) at time t j , and the discretized time points { t 0 , ...
t N t } .
For example, given ( z N t , v N t ) and { t i } N t i =0 , the trajectory for Eq. 4 is reconstructed:
[Equation]
In the following sections, we will show the invertibility of ALF is the key to maintain accuracy at a constant memory cost to train Neural ODEs.
Note that “inverse” refers to reconstructing the input from the output without computing the gradient, hence is different from “back-propagation”.
Initial value For an initial value problem (IVP) such as Eq. 1, typically z 0 =
z ( t 0 ) is given while v 0 is undetermined.
We can construct v 0 = f
( z ( t 0 ) , t 0 ) , so the initial augmented state is ( z 0 , v 0 ) .
Difference from midpoint integrator The midpoint integrator (S¨uli & Mayers, 2003) is similar to Algo.
2, except that it recomputes v in = f
( z in , s in ) for every step, while ALF directly uses the input v in .
Therefore, the midpoint method does not have an explicit form of inverse.
Local truncation error Theorem 3.1 indicates that the local truncation error of ALF is of order
O ( h 3 ) ; this implies the global error is O ( h 2 ) .
Detailed proof is in Appendix A.3.
Theorem 3.1.
For a single step in ALF with stepsize h , the local truncation error of z is O
( h 3 ) , and the local truncation error of v is O
( h 2 ) .
A-
Stability The ALF solver has a limited stability region, but this can be solved with damping.
The damped ALF replaces the update of v out in Algo.
2 with v out = v in + 2 η ( u 1 − v in ) , where η is the “damping coefﬁcient” between 0 and 1.
We have the following theorem on its numerical stability.
Theorem 3.2.
For the damped ALF integrator with stepsize h , where σ i is the i -th eigenvalue of the
Jacobian ∂f∂z , then the solver is A-stable if (cid:12)(cid:12)(cid:12) 1 + η
( hσ
[Equation]
−
[Equation]
) ± (cid:113) η (cid:2)
[Equation]
+ η ( hσ
[Equation]
−
[Equation]
) 2 (cid:3)(cid:12)(cid:12)(cid:12) < 1 , ∀
i
Proof is in Appendix A.4 and A.5.
Theorem 3.2 implies the following: when η = 1 , the damped
ALF reduces to ALF, and the stability region is empty;
when 0 < η < 1 , the stability region is nonempty.
However, stability describes the behaviour when T goes to inﬁnity; in practice we always use a bounded T and ALF performs well.
Inverse of damped ALF is in Appendix A.5.
[Equation]
An ideal solver for Neural ODEs should achieve two goals: accuracy in gradient estimation and constant memory cost w.r.t integration time.
Yet none of the existing methods can achieve both goals.
We propose a method based on the ALF solver, which to our knowledge is the ﬁrst method to achieve the two goals simultaneously.
Input Initial state z 0 , start time t 0 , end time T
Forward
Apply the numerical integration in Algo. 1, with the ψ function deﬁned by Algo. 2.
Delete computation graph on the ﬂy, only keep end-time state ( z N t , v N t )
Keep accepted discretized time points { t i } N t i =
(ignore process to search for optimal stepsize)
Backward
Initialize a ( T ) =
∂L∂z ( T ) by Eq.
3, initialize d L d θ =
For i in { N t , N t − 1 , ..., 2 , 1 } :
Reconstruct ( z i − 1 , v i − 1 ) from ( z i , v i ) by Algo.
Local forward ( z i , v i , t i , h i ) =
ψ ( z i − 1 , v i − 1 , t i − 1 , h i )
Local backward, get ∂f ( z i − 1 ,t i − 1 ,θ )
∂z i −and ∂f ( z i − 1 ,t i − 1 ,θ )
∂θ
Update a ( t ) and d L d θ by Eq.
2 and Eq.
3 discretized at time points t i − 1 and t
i
Delete local computation graph
Output the adjoint state a ( t 0 )
(gradient w.r.t input z 0 ) and parameter gradient d L d θ
Procedure of MALI Details of MALI are summarized in Algo.
For the forward-pass, we only keep the end-time state ( z N t , v N t ) and the accepted discretized time points (blue curves in Fig.and 2).
We ignore the search process for optimal stepsize (green curve in Fig.
1 and 2), and delete other variables to save memory.
During the backward pass, we can reconstruct the forward-time trajectory as in Eq.
5, then calculate the gradient by numerical discretization of Eq.
2 and Eq.
Constant memory cost w.r.t number of solver steps in integration We delete the computation graph and only keep the end-time state to save memory.
The memory cost is N z ( N f + 1) , where
N z N f is due to evaluating f ( z, t ) and is irreducible for all methods.
Compared with the adjoint method, MALI only requires extra N z memory to record v N t , and also has a constant memory cost w.r.t time step N t .
The memory cost is N z ( N f + 1) .
Accuracy Our method guarantees the accuracy of reverse-time trajectory (e.g. blue curve in Fig.matches the blue curve in Fig. 1), because ALF is explicitly invertible for free-form f (see Algo. 7).
Therefore, the gradient estimation in MALI is more accurate compared to the adjoint method.
Computation cost Recall that on average it takes m steps to ﬁnd an acceptable stepsize, whose error estimate is below tolerance.
Therefore, the forward-pass with search process has computation burden N z
×
N f × N t × m .
Note that we only reconstruct and backprop through the accepted step and ignore the search process, hence it takes another N z × N f × N t × 2 computation.
The overall computation burden is N z N f × N t × ( m + 2) as in Table 1.
Shallow computation graph Similar to ACA, MALI only backpropagates through the accepted step (blue curve in Fig. 2) and ignores the search process (green curve in Fig. 2), hence the depth of computation graph is N f × N t .
The computation graph of MALI is much shallower than the naive method, hence is more robust to vanishing and exploding gradients (Pascanu et al., 2013).
Summary
The adjoint method suffers from inaccuracy in reverse-time trajectory, the naive method suffers from exploding or vanishing gradient caused by deep computation graph, and ACA ﬁnds a balance but the memory grows linearly with integration time.
MALI achieves accuracy in reversetime trajectory, constant memory w.r.t integration time, and a shallow computation graph.
E XPERIMENTS 4. V ALIDATION ON A TOY EXAMPLE
We compare the performance of different methods on a toy example, deﬁned as
[Equation]
The analytical solution is
[Equation]
We plot the amplitude of error between numerical solution and analytical solution varying with T (integrated under the same error tolerance, rtol = 10 − 5 , atol = 10 − 6 ) in Fig 4.
ACA and MALI have similar errors, both outperforming other methods.
We also plot the memory consumption for different methods on a Neural ODE with the same input in Fig.
As the error tolerance decreases, the solver evaluates more steps, hence the naive method and ACA increase memory consumption, while MALI and the adjoint method have a constant memory cost.
These results validate our analysis in Sec. 3.2 and Table 1, and shows MALI achieves accuracy at a constant memory cost.
4. I MAGE RECOGNITION WITH N EURAL ODE
We validate MALI on image recognition tasks using Cifar10 and ImageNet datasets.
Similar to
Zhuang et al.
(2020), we modify a ResNet18 into its corresponding Neural ODE: the forward func-
[Table] [Table]
tion is y = x
+ f θ ( x ) and y
= x + (cid:82) T
f θ ( z )d t for the residual block and Neural ODE respectively, where the same f θ is shared.
We compare MALI with the naive method, adjoint method and ACA.
Results on Cifar10 Results of 5 independent runs on Cifar10 are summarized in Fig.
MALI achieves comparable accuracy to ACA, and both signiﬁcantly outperform the naive and the adjoint method.
Furthermore, the training speed of MALI is similar to ACA, and both are almost two times faster than the adjoint memthod, and three times faster than the naive method.
This validates our analysis on accuracy and computation burden in Table 1.
Accuracy on ImageNet Due to the heavy memory burden caused by large images, the naive method and ACA are unable to train a Neural ODE on ImageNet with 4 GPUs; only MALI and the adjoint method are feasible due to the constant memory.
We also compare the Neural ODE to a standard ResNet.
As shown in Fig.
6, the accuracy of the Neural ODE trained with MALI closely follows ResNet, and signiﬁcantly outperforms the adjoint method (top-1 validation: 70% v.s. 63%).
Invariance to discretization scheme A continuous model should be invariant to discretization schemes (e.g. different types of ODE solvers) as long as the discretization is sufﬁciently accurate.
We test the Neural ODE using different solvers without re-training; since ResNet is often viewed as a one-step Euler discretization of an ODE (Haber & Ruthotto, 2017), we perform similar experiments.
As shown in Table 2, Neural ODE consistently achieves high accuracy ( ∼ 70%), while
ResNet drops to random guessing ( ∼ 0.1%) because ResNet as a one-step Euler discretization fails to be a meaningful dynamical system (Queiruga et al., 2020).
Robustness to adversarial attack Hanshu et al.
(2019) demonstrated that Neural ODE is more robust to adversarial attack than ResNet on small-scale datasets such as Cifar10.
We validate this result on the large-scale ImageNet dataset.
The top-1 accuracy of Neural ODE and ResNet under
FGSM attack (Goodfellow et al., 2014) are summarized in Table 3.
For Neural ODE, due to its invariance to discretization scheme, we derive the gradient for attack using a certain solver (row in
Table 3), and inference on the perturbed images using various solvers.
For different combinations of solvers and perturbation amplitudes, Neural ODE consistently outperforms ResNet.
Summary In image recognition tasks, we demonstrate Neural ODE is accurate, invariant to discretization scheme, and more robust to adversarial attack than ResNet.
Note that detailed explanation on the robustness of Neural ODE is out of the scope for this paper, but to our knowledge, MALI is the ﬁrst method to enable training of Neural ODE on large datasets due to constant memory cost.
4. T IME - SERIES MODELING
We apply MALI to latent-ODE (Rubanova et al., 2019) and Neural Controlled Differential Equation (Neural CDE) (Kidger et al., 2020).
Our experiment is based on the ofﬁcial implementation from
[Table] [Table]
[Table] [Table]
the literature.
We report the mean squared error (MSE) on the Mujoco test set in Table
[Table]
which is generated from the “Hopper” model using DeepMind control suite (Tassa et al., 2018); for all experiments with different ratios of training data, MALI achieves similar MSE to ACA, and both outperform the adjoint and naive method.
We report the test accuracy on the Speech Command dataset for Neural CDE in Table 5; MALI achieves a higher accuracy than competing methods.
4. C ONTINUOUS GENERATIVE MODELS
We apply MALI on FFJORD (Grathwohl et al., 2018), a free-from continuous generative model, and compare with several variants in the literature (Finlay et al., 2020; Kidger et al., 2020).
Our experiment is based on the ofﬁcial implementaion of Finlay et al.
; for a fair comparison, we train with MALI, and test with the same solver as in the literature (Grathwohl et al., 2018; Finlay et al., 2020), the Dopri5 solver with rtol = atol
= 10 − 5 from the torchdiffeq package (Chen et al., 2018).
Bits per dim (BPD, lower is better) on validation set for various datasets are reported in
Table 6.
For continuous models, MALI consistently generates the lowest BPD, and outperforms the
Vanilla FFJORD (trained with adjoint), RNODE (regularized FFJORD) and the SemiNorm Adjoint (Kidger et al., 2020).
Furthermore, FFJORD trained with MALI achieves comparable BPD to stateof-the-art discrete-layer ﬂow models in the literature.
Please see Sec.
B.3 for generated samples.
R ELATED WORKS
Besides ALF, the symplectic integrator (Verlet, 1967; Yoshida, 1990) is also able to reconstruct trajectory accurately, yet it’s typically restricted to second order
Hamiltonian systems (De Almeida, 1990), and are unsuitable for general ODEs.
Besides aforementioned methods, there are other methods for gradient estimation such as interpolated adjoint (Daulbaev et al., 2020) and spectral method (Quaglino et al., 2019), yet the implementations are involved and not publicly available.
Other works focus on the theoretical properties of Neural ODEs (Dupont et al., 2019; Tabuada & Gharesifard, 2020; Massaroli et al., 2020).
Neural ODE is recently applied to stochastic differential equation (Li et al., 2020), jump differential equation (Jia & Benson, 2019) and auto-regressive models (Wehenkel & Louppe, 2019).
C ONCLUSION
Based on the asynchronous leapfrog integrator, we propose MALI to estimate the gradient for Neural
ODEs.
To our knowledge, our method is the ﬁrst to achieve accuracy, fast speed and a constant memory cost.
We provide comprehensive theoretical analysis on its properties.
We validate MALI with extensive experiments, and achieved new state-of-the-art results in various tasks, including image recognition, continuous generative modeling, and time-series modeling.
C ONTENTS (A PPENDIX ) A Theoretical properties of ALF integrator
A.1 Algorithm of ALF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A.2 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A.3 Local truncation error of ALF . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A.4 Stability analysis . .
A.5 Damped ALF . . .
B Experimental Details
B.1 Image Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B.1.
Experiment on Cifar10 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B.1.
Experiments on ImageNet . . . . . . . . . . . . . . . . . . . . . . . . . .
B.2 Time series modeling . . .
B.3 Continuous generative models . .
B.3.
Training details .
B.3.
results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A T HEORETICAL PROPERTIES OF ALF INTEGRATOR A. A LGORITHM OF ALF
For the ease of reading, we write the algorithm for ψ in ALF below, which is the same as Algo. 2 in the main paper, but uses slightly different notations for the ease of analysis.
Input ( (cid:99) z in , (cid:99) v in , s in , h ) =
( (cid:98) z 0 , (cid:98) v 0 , s 0 , h ) where s 0 is current time,
(cid:98) z 0 and (cid:98) v 0 are correponding values at time s 0 ; stepsize h .
Forward
[Equation] [Equation]
[Equation] [Equation]
[Equation] [Equation]
Output
[Equation]
For simplicity, we can re-write the forward of ALF as
[Equation]
Similarly, the inverse of ALF can be written as
[Equation]
A. P RELIMINARIES
For an ODE of the form d
[Equation] [Equation]
We have:
[Equation]
For the ease of notation, we re-write Eq.
10 as
[Equation]
where f t and f z represents the partial derivative of f w.r.t t and z respectively.
A. L OCAL TRUNCATION ERROR OF ALF
Theorem A.1 (Theorem 3.1 in the main paper) .
For a single step in ALF with stepsize h , the local truncation error of z is O
( h 3 ) , and the local truncation errof of v is O
( h 2 ) .
Proof.
Under the same notation as Algo. 1, denote the ground-truth state of z and v starting from ( (cid:98) z 0 , s 0 ) as (cid:101) z
and (cid:101) v respectively.
Then the local truncation error is
[Equation]
Under mild assumptions that f is smooth up to 2nd order almost everywhere (this is typically satisﬁed with neural networks with bounded weights), hence Taylor expansion is meaningful for f .
By
Eq.
11, the Taylor expansion of (cid:101)
z around point ( (cid:98) z 0 , (cid:98) v 0 , s 0 ) is
[Equation]
Next, we analyze accuracy of the numerical approximation.
For simplicity, we directly analyze Eq.by performing Taylor Expansion on f .
[Equation]
Plug Eq.
14, Eq. 15 and E.q. 16 into the deﬁnition of L z , we get
[Equation]
[Equation]
Therefore, if (cid:12)(cid:12)(cid:12) f
( (cid:98) z 0 , s 0 ) − (cid:98) v 0 (cid:12)(cid:12)(cid:12) is of order O (1) , L z is of order
O ( h 2 ) ; if (cid:12)(cid:12)(cid:12) f
( (cid:98) z 0 , s 0 ) − (cid:98) v 0 (cid:12)(cid:12)(cid:12) is of order
O ( h ) or smaller, then L z is of order
O ( h 3 ) .
Speciﬁcally, at the start time of integration, we have (cid:12)(cid:12)(cid:12) f
( (cid:98) z 0 , s 0 ) − (cid:98) v 0 = 0 (cid:12)(cid:12)(cid:12) , by induction, L z at end time is O ( h 3 ) .
Next we analyze the local truncation error in v , denoted as L v .
Denote the ground truth as (cid:101) v ( t 0 + h ) , we have
[Equation]
Next we analyze the error in the numerical approximation.
Plug Eq.
15 into Eq.
[Equation]
From Eq.
14, Eq.
and Eq.
23, we have
[Equation] [Equation]
The last equation is derived by plugging in Eq.
Note that Eq.
26 holds for every single step forward in time, and at the start time of integration, we have (cid:12)(cid:12) f
( (cid:98) z 0 , s 0 ) − (cid:98) v 0 (cid:12)(cid:12) =
due to our initialization as in Sec.
3.1 of the main paper.
Therefore, by induction, L v is of order O
( h 2 ) for consecutive steps.
A. S TABILITY ANALYSIS
Lemma A.1.1.
For a matrix of the form (cid:20) A B
C D (cid:21) , if A, B, C, D are square matrices of the same shape, and CD =
DC , then we have det (cid:20) A B C D (cid:21) = det( AD − BC )
Proof.
See (Silvester, 2000) for a detailed proof.
Theorem A.2.
For ALF integrator with stepsize h , if hσ i is 0 or is imaginary with norm no larger than 1, where σ i is the i -th eigenvalue of the Jacobian ∂f∂z , then the solver is on the critical boundary of A-stability; otherwise, the solver is not A-stable.
Proof.
A solver is A-stable is equivalent to the eigenvalue of the numerical forward has a norm below 1.
We calculate the eigenvalue of ψ below.
For the function deﬁned by Eq.
7, the Jacobian is
[Equation] [Equation]
We determine the eigenvalue of J by solving the equation
[Equation]
[Equation]
It’s trivial to check J satisﬁes conditions for Lemma A.1.1.Therefore, we have
[Equation]
Suppose the eigen-decompostion of ∂f∂z can be written as
[Equation] [Equation]
Note that I = Λ
Iλ − 1 , hence we have
[Equation]
Hence the eigenvalues are
[Equation]
A-stability requires | λ i ± | < 1 , ∀ i , and has no solution.
The critical boundary is | λ i ± | = 1 , the solution is: hσ i is 0 or on the imaginary line with norm no larger than 1.
A. D AMPED ALF
Input ( (cid:99) z in , (cid:99) v in , s in , h ) =
( (cid:98) z 0 , (cid:98) v 0 , s 0 , h ) where s 0 is current time,
(cid:98) z 0 and (cid:98) v 0 are correponding values at time s 0 ; stepsize h .
Forward
[Equation] [Equation]
[Equation] [Equation]
[Equation] [Equation]
Output
[Equation]
( (cid:100) z out , (cid:100) v out , s out , h ) where s out is current time, (cid:100)
z out and (cid:100) v out at s out , h is
Inverse
[Equation] [Equation]
[Equation] [Equation]
Output
[Equation]
The main difference between ALF and Damped ALF is marked in blue in Algo.
In ALF, the update of (cid:98) v 2 is (cid:98) v 2 =
( (cid:98) v 1 − (cid:98) v 0 )
+ (cid:98) v 1 = 2( (cid:98) v 1 − (cid:98) v 0 )
+ (cid:98) v 0 ; while in Damped ALF, the update is scaled by a factor η between 0 and 1, so the update is (cid:98) v 2 = 2 η ( (cid:98) v 1 − (cid:98) v 0 )
+ (cid:98) v 0 .
When η = 1 , Damped ALF reduces to ALF.
Similar to Sec.
A.1, we can write the forward as For simplicity, we can re-write the forward of ALF as
[Equation]
Similarly, the inverse of ALF can be written as
[Equation]
 
[Equation] [Equation]
Theorem A.3.
For a single step in Damped ALF with stepsize h , the local truncation error of z is
O ( h 2 ) , and the local truncation errof of v is O ( h ) .
Proof.
The proof is similar to Thm.
A.3.
By similar calculations using the Taylor Expansion in
Eq. 15 and Eq.
14, we have
[Equation]
Using Eq.
21, Eq. 15 and Eq.
[Equation]
we have
[Equation]
Note that when η = 1 , Eq.
51 reduces to Eq.
19, and Eq.
53 reduces to Eq. 26.
By initialization, we have | f ( (cid:98) z 0 , s 0 ) − (cid:98) v 0 | = 0 at initial time, hence by induction, the local truncation error for z is
O ( h 2 ) ; the local truncation error for v is O
( h ) when η < 1 , and is O ( h 2 ) when η = 1 .
Theorem A.4 (Theorem 3.2 in the main paper) .
For Dampled ALF integrator with stepsize h , where σ i is the i -th eigenvalue of the Jacobian ∂f∂z , then the solver is A-stable if (cid:12)(cid:12)(cid:12) 1 + η ( hσ −
[Equation]
Proof.
The Jacobian of the forward-pass of a single step damped ALF is
[Equation]
when η = 1 , J reduces to Eq. 27.
We can determine the eigenvalue of J using similar techniques.
Assume the eigenvalues for ∂f∂z are { σ i } , then we have
[Equation]
when η < 1 , it’s easy to check that (cid:12)(cid:12)(cid:12) 1+ η
[Equation]
hσ
i
[Equation] [Equation]
< 1 has non-empty solutions for hσ .
For a quick validation, we plot the region of A-stability on the imaginary plane for a single eigenvalue in Fig.
As η increases, the area of stability decreases.
When η = 1 , the system is no-where
A-stable, and the boundary for A-stability is on the imaginary axis [ − i, i ] where i is the imaginary unit.
B E XPERIMENTAL D ETAILS B. I MAGE R ECOGNITION B.1. E XPERIMENT ON C IFAR
We directly modify a ResNet18 into a Neural ODE, where the forward of a residual block ( y = x + f ( x ) ) and the forward of an ODE block ( y = x + (cid:82) T 0 f
( z, t ) dt where T = 1 ) share the same parameterization f , hence they have the same number of parameters.
Our experiment is based on the ofﬁcial implementation by Zhuang et al.
(2020) and an open-source repository (Liu, 2017).
All models are trained with SGD optimizer for 90 epochs, with an initial learning rate of 0.01, and decayed by a factor of 10 at 30th epoch and 60th epoch respectively.
Training scheme is the same for all models (ResNet, Neural ODE trained with adjoint, naive, ACA and MALI).
For ACA, we follow the settings in (Zhuang et al., 2020) and use the ofﬁcial implementation torch ACA 1 , and use a Heun-Euler solver with rtol = 10 − 1 , atol = 10 − 2 during training.
For MALI, we use an adaptive version and set rtol = 10 − 1 , atol = 10 − 2 .
For the naive and adjoint method, we use the default
Dopri5 solver from the torchdiffeq 2 package with rtol = atol
= 10 − 5 .
We train all models forindependent runs, and report the mean and standard deviation across runs.
B.1. E XPERIMENTS ON I MAGE N ET
Training scheme We conduct experiments on ImageNet with ResNet18 and Neural-ODE18.
All models are trained on 4 GTX-1080Ti GPUs with a batchsize of 256.
All models are trained for 80 epochs, with an initial learning rate of 0.1, and decayed by a factor of 10 at 30th and 60th epoch.
Note that due to the large size input 256 × 256 , the naive method and ACA requires a huge memory, and is infeasible to train.
MALI and the adjoint method requires a constant memory hence is suitable for large-scale experiments.
For both MALI and the adjoint menthod, we use a ﬁxed stepsize of 0.25, and integrates from 0 to T = 1 .
As shown in Table.
2 in the main paper, a stepsize of 0.25 is sufﬁciently small to train a meaningful continuous model that is robust to discretization scheme.
Invariance to discretization scheme To test the inﬂuence of discretization scheme, we test our
Neural ODE with different solvers without re-training.
For ﬁxed-stepsize solvers, we tested various step sizes including { 0 . 1 , 0 . 15 , 0 . 25 , 0 . 5 , 1 . 0 } ; for adaptive solvers, we set rtol=0.1, atol=0.01 for
MALI and Heun-Euler method, and set rtol = 10 − 2 , atol = 10 − 3 for RK23 solver, and set rtol = 10 − 4 , atol = 10 − 5 for Dopri5 solver.
As shown in Table.
2, Neural ODE trained with MALI is robust to discretization scheme, and MALI signiﬁcantly outperforms the adjoint method in terms of accuracy (70% v.s. 63% top-1 accuracy on the validation dataset).
An interesting ﬁnding is that when trained with MALI which is a second-order solver, and tested with higher-order solver (e.g.
[Figure]
RK4)
, our Neural ODE achieves 70.21% top-1 accuracy, which is higher than both the same solver during training (MALI, 69.59% accuracy) and the ResNet18 (70.09% accuracy).
Furthermore, many papers claim ResNet to be an approximation for an ODE (Lu et al., 2018).
However, Queiruga et al.
(2020) argues that many numerical discretizations fail to be meaningful dynamical systems, while our experiments demonstrate that our model is continuous hence invariant to discretization schemes.
Adversarial robustness Besides the high accuracy and robustness
to discretization scheme, another advantage of Neural ODE is the robustness to adversarial attack.
The adversary robustness of
Neural ODE is extensively studied in (Hanshu et al., 2019), but not only validated on small-scale datasets such as Cifar10.
To our knowledge, our method is the ﬁrst to enable effectuve training of Neural ODE on large-scale datasets such as ImageNet and achieve a high accuracy, and we are the ﬁrst to validate the robustness of Neural ODE on ImageNet.
We use the advertorch 3 toolbox to perform adversarial attack.
We test the performance of ResNet and Neural ODE under FGSM attack.
To be more convincing, we conduct experiment on the pretrained ResNet18 provided by the ofﬁcial PyTorch website 4 .
Since Neural ODE is invariant to discretization scheme, it’s possible to derive the gradient for attack using one ODE solver, and inference on the perturbed image using another solver.
As summarized in Table.
3, Neural ODE consistently achieves a higher accuracy than ResNet under the same attack.
B. T IME SERIES MODELING
We conduct experiments on Latent-ODE models (Rubanova et al., 2019) and Neural CDE (controlled differential equation) (Kidger et al., 2020).
For all experiments, we use the ofﬁcial implementation, and only replace the solver with MALI.
The latent-ODE model is trained on the Mujoco dataset processed with code provided by the ofﬁcial implementation, and we experiment with different ratios (10%,20%,50%) of training data as described in (Rubanova et al., 2019).
All models are trained for 300 epochs with Adamax optimizer, with an initial learning rate of 0.01 and scaled by 0.999 for each epoch.
For the Neural CDE model, for the naive method, ACA and MALI, we perform 5 independent runs and report the mean value and standard deviation; results for the adjoint and seminorm adjoint are from (Kidger et al., 2020).
For Neural CDE, we use MALI with ALF solver with a ﬁxed stepsize of 0.25, and train the model for 100 epochs with an initial learning rate of 0.004.
[Figure]
B. C ONTINUOUS GENERATIVE MODELS B.3. T RAINING DETAILS
Our experiment is based on the ofﬁcial implementation of (Finlay et al., 2020), with the only difference in ODE solver.
For a fair comparison, we only use MALI for training, and use Dopri5 solver from torchdiffeq package (Chen et al., 2018) with rtol = atol = 10 − 5 .
For MALI, we use adaptive
ALF solver with rtol = 10 − 2 , atol = 10 − 3 , and use an initial stepsize of 0.25.
Integration time is from 0 to 1.
On MNIST and CIFAR dataset, we set the regularization coefﬁcients for kinetic energy and Frobenius norm of the derivative function as 0.05.
We train the model for 50 epochs with an initial learning rate of 0.001.
B.3. A DDTIONAL RESULTS
We show generated examples on MNIST dataset in Fig.
3, results for Cifar10 dataset in Fig. 4, and results for ImageNet64 in Fig.
B. E RROR IN GRADIENT ESTIMATION FOR TOY EXAMPLES WHEN t <
We plot the error in gradient estimation for the toy example deﬁned by Eq.6 in the main paper in
Fig.
Note that the integration time T is set as smaller than 1, while the main paper is larger than 20.
We observe the same results, MALI and ACA generate smaller error than the adjoint and the naive method.
B. R ESULTS OF DAMPED MALI
For all experiments in the main paper, we set η = 1 and did not use damping.
For completeness, we experimented with damped MALI using different values of η .
As shown in Table.
7, MALI is robust to different η values.
[Figure] [Figure]
[Table]
[Figure]