\section{Submission of conference papers to ICLR 2023}
\bibliographystyle{iclr2023_conference}



\section{How to Read This Appendix?}

\section{Convergence Analysis of SGD}\label{appdx:SGD_Convergence}

This section analyzes the convergence of SGD in both supervised learning (SL) and online continual learning (OCL). The purpose of the analysis is to demonstrate the difference between the optimization problem in SL and OCL, and explain intuitively why SGD+RWP works in SL but can fail in OCL. 

\subsection{Convergence analysis in Supervised Learning}\label{appdx:SGD_Convergence_SL}

In supervised learning, we are given a fixed set of training data, and we solve the following stationary optimization problem
\begin{align}\label{eq:SL_OBJ}
\underset{{\bm\theta}\in \mathbb{R}^d}{\text{minimize}} \ \ \ \ l({\bm\theta}).
\end{align}
In each iteration k, SGD updates the model ${\bm\theta}_k$ using the stochastic gradient, from a batch of training data, via,
\begin{align}
{\bm\theta}_k \leftarrow {\bm\theta}_{k-1} - \alpha_{k}g({\bm\theta}_{k-1} | \mathcal{E}_{k}),
\end{align}
where $\mathcal{E}_{k}$ denotes the random variable that determines the noise of the stochastic gradient. 

The standard assumptions~\citep{ghadimi2013stochastic} for analyzing the non-convex case of supervised learning is
\begin{enumerate}[label = \textbf{A\arabic*}]
\setcounter{enumi}{4}	
	\item \label{A5} Lipschitz Smoothness with constant $L \ge 0$ : $\norm{\triangledown l({\bm\theta}) - \triangledown l({\bm\theta}')} \le L\norm{{\bm\theta} - {\bm\theta}'}, \forall {\bm\theta}, {\bm\theta}' \in \mathbb{R}^d$, where $\norm{\cdot}$ is the Euclidean Norm. 
	\item \label{A6} Unbiased gradient estimation: $\mathbb{E}_{\mathcal{E}}[g({\bm\theta} | \mathcal{E})] = \triangledown l({\bm\theta}), \forall {\bm\theta}\in \mathbb{R}^d$.
	\item \label{A7} Bounded gradient noise with constant $\rho \ge 0$: $\norm{\triangledown l({\bm\theta}) - g({\bm\theta} | \mathcal{E})}^2 \le \rho^2, \forall {\bm\theta} \in \mathbb{R}^d$.  
\end{enumerate}
Under these assumptions, we re-produce the standard convergence result of SGD in the non-convex SL case:
\begin{theorem}\label{theory:SGD_SL} 
	Assume~\ref{A5} to~\ref{A7}, and let $\alpha_k < \frac{L}{2} $, 
	\begin{align}\label{theorem_eq:SGD_SL}
	\min_{j\in\{0,...,k\}} \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{j}} [\norm{\triangledown l({\bm\theta}_j)}^2] \le \frac{2 (l({\bm\theta}_0) - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}} [l({\bm\theta}_{k+1})])}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)} + \frac{L\rho^2 \sum_{j=0}^{k} \alpha_{j+1}^2}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)}.
	\end{align}
\end{theorem}
\begin{proof}
	Following the proof of Theorem 2.1 until (2.11) in~\citep{ghadimi2013stochastic}, we have 
	\begin{align}\label{eq:SGD_SL1}
	\sum_{j=0}^k (2\alpha_{j+1} - L\alpha_{j+1}^2) \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{j}} [\norm{\triangledown l({\bm\theta}_{j})}^2] \le 2 (l({\bm\theta}_0) - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}} [l({\bm\theta}_{k+1})]) + L\rho^2 \sum_{j=0}^{k} \alpha_{j+1}^2. 
	\end{align}
	And since 
	\begin{align}\label{eq:SGD_SL2}
	(\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)) \min_{l\in\{0,...,k\}} \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{l}} [\norm{\triangledown l({\bm\theta}_{l})}^2] \le \sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2) \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{j}} [\norm{\triangledown l({\bm\theta}_{j})}^2], 
	\end{align}
	we immediately have~\eqref{theorem_eq:SGD_SL} by combining~\eqref{eq:SGD_SL1} with~\eqref{eq:SGD_SL2} and dividing both sides by $\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)$. 
\end{proof}

Theorem~\ref{theory:SGD_SL} tells us that the convergence of SGD can be guaranteed by properly setting the learning rate $\alpha_k$. Denote $T_4 = \frac{2 (l({\bm\theta}_0) - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}} [l({\bm\theta}_{k+1})])}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)}$ and $T_5 = \frac{L\rho^2 \sum_{j=0}^{k} \alpha_{j+1}^2}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)}$ as the first and the second terms at the right hand side of~\eqref{theorem_eq:SGD_SL}, which are of the same form as $T_1$ and $T_2$ of~\eqref{theorem_eq:SGD_OCL_main}. To ensure that $T_4$ goes to 0, we need to make sure that 
\begin{align}\label{eq:SGD_cond1}
	\lim_{k\rightarrow \infty}\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2) = \infty.
\end{align}
And to ensure that $T_5$ goes to 0, we need to ensure that
\begin{align}\label{eq:SGD_cond2}
\lim_{k\rightarrow \infty}\frac{\sum_{j=0}^{k} \alpha_{j+1}^2}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)} = 0.
\end{align}
For example, one can set $\alpha_{k} = \mathcal{O}(\sqrt{k})$ so that both~\eqref{eq:SGD_cond1} and~\eqref{eq:SGD_cond2} are satisfied.  Theorem~\ref{theory:SGD_SL} also provides insights of why RWP is effective in SL. Given a constant learning rate $\alpha_k = \alpha$, we can see that $T_4 = \mathcal{O}(\frac{1}{k})$ after $k$ iterations, i.e., it converges with linear speed. However, the second term $T_5 = \frac{L\rho^2\alpha}{2-L\alpha}$ is a constant over time. Hence, the gradient norm will first decrease and then converge to a constant given a constant learning rate. And the plateau of the gradient norm is a signal that we need to reduce the learning rate to further improve the model. In practice, the validation loss/accuracy is often used as a surrogate of the gradient norm. 

\subsection{Convergence analysis in OCL}\label{appdx:SGD_Convergence_OCL}
We provide a proof of Theorem~\ref{theory:SGD_OCL} in this section. Before the proof, we first re-state the problem, the assumptions and the theory in a more detailed format.


At each iteration $k$, we are given a non-stationary objective 
\begin{align}\label{eq:OCL_OBJ}
\underset{{\bm\theta}}{\text{minimize}} \ \ \ \ l_k({\bm\theta}).
\end{align}
In each iteration $k$, SGD updates the model ${\bm\theta}_{k}$ using the stochastic gradient $g_{k}({\bm\theta}_{k-1} | \mathcal{E}_{k})$ on $l_{k}({\bm\theta}_{k-1})$, from a batch of training data, via,
\begin{align}
{\bm\theta}_k \leftarrow {\bm\theta}_{k-1} - \alpha_{k}g_{k}({\bm\theta}_{k-1} | \mathcal{E}_{k}),
\end{align}
where $\mathcal{E}_k$ denotes the random variable that decides the noise of the stochastic gradient.

It is unsurprising that no algorithm can achieve a reasonable performance if $l_k(\cdot)$ can change arbitrarily between consecutive iterations, since we can change the training data in a completely adversarial fasion. One reasonable assumption is that $l_k(\cdot)$ does not change significantly between consecutive time steps. For example, when we want to optimize information retention, the training data pool $\mathbf{S}_t$ does not change significantly between consecutive iterations. Given this intuition, we formalize our assumptions in the non-stationary case, with the definition of the mean operation $\mathbb{E}$ (which is omitted in the main paper) as follows:
\begin{enumerate}[label = \textbf{A\arabic*}]
	\item \label{A1_ap} Lipschitz Smoothness with constant $L \ge 0$ : $\norm{\triangledown l_k({\bm\theta}) - \triangledown l_k({\bm\theta}')} \le L\norm{{\bm\theta} - {\bm\theta}'}, \forall {\bm\theta}, {\bm\theta}' \in \mathbb{R}^d$ and $k$. 
	\item \label{A2_ap} Unbiased gradient estimation: $\mathbb{E}_{\mathcal{E}}[g_{k}({\bm\theta} | \mathcal{E})] = \triangledown l_{k}({\bm\theta}), \forall {\bm\theta}\in \mathbb{R}^d$ and $k$.
	\item \label{A3_ap} Bounded gradient noise with constant $\rho \ge 0$: $\norm{\triangledown l_{k}({\bm\theta}) - g_{k}({\bm\theta} | \mathcal{E})}^2 \le \rho^2, \forall {\bm\theta} \in \mathbb{R}^d$ and $k$.  
	\item \label{A4_ap} Bounded non-stationarity with constants $\chi_k \ge 0$: $|l_k({\bm\theta}) - l_{k+1}({\bm\theta})| \le \chi_k, \forall {\bm\theta} \in \mathbb{R}^d$ and $k$.
\end{enumerate}
Intuitively, \ref{A1_ap} to~\ref{A3_ap} extend \ref{A5} to~\ref{A7} to non-stationary objectives, and~\ref{A4_ap} constraints the change of the objective function value between consecutive iterations, which is similar to the analysis of SGD in the convex case~\citep{besbes2015non}. Note that $l_k({\bm\theta})$ is computed over the replay data, i.e., not on the discarded historical data when the replay buffer/storage is limited. Hence the analysis in this section naturally includes limited storage as a special case. Under these assumptions, we can prove the following convergence result of SGD in the non-stationary case:
\setcounter{theorem}{0}
\begin{theorem}
	 Assume~\ref{A1_ap} to~\ref{A4_ap}, and let $\alpha_k < \frac{L}{2}$,
	\begin{align}\label{theorem_eq:SGD_OCL}
	\min_{j\in \{0,1,...,k\}} \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{j}} [\norm{\triangledown l_{j+1}({\bm\theta}_j)}^2] \le T_1 + T_2 + T_3
	\end{align}
	where $
		 T_1 = \frac{2 (l_1({\bm\theta}_0) - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}} [l_{k+2}({\bm\theta}_{k+1})])}{\sum_{j=0}^k (2\alpha_{j+1} - L\alpha_{j+1}^2)}$, $T_2 = \frac{L\rho^2 \sum_{j=0}^k \alpha_{j+1}^2}{\sum_{j=0}^k (2\alpha_{j+1} - L\alpha_{j+1}^2)}$, and $T_3 = \frac{2\sum_{j=0}^k \chi_{j+1}^2}{\sum_{j=0}^k (2\alpha_{j+1} - L\alpha_{j+1}^2)}$.
\end{theorem}
\begin{proof}
With~\ref{A1_ap} and Lemma 1.2.3 of~\citep{nesterov1998introductory}, we have 
\small{
\begin{align}
& \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[l_{k+1}({\bm\theta}_{k+1})] \\ 
& \le \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[l_{k+1}({\bm\theta}_k) + \triangledown l_{k+1}({\bm\theta}_k)^T ({\bm\theta}_{k+1}-{\bm\theta}_k) + \frac{L\norm{{\bm\theta}_{k+1}-{\bm\theta}_k}^2}{2}] \\	
& = \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_k)] - \alpha_{k+1}\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2] + \frac{L \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[\norm{\alpha_{k+1}g_{k+1}({\bm\theta}_k|\mathcal{E}_{k+1})}^2]}{2} \\
& = \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_{k})] - \alpha_{k+1}\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2] + \frac{L\alpha_{k+1}^2 \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[\norm{(g_{k+1}({\bm\theta}_k|\mathcal{E}_{k+1})-\triangledown l_{k+1}({\bm\theta}_k))+\triangledown l_{k+1}({\bm\theta}_k)}^2]}{2} \\
& = \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_k)] - \alpha_{k+1}\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2] + \\
& \frac{L\alpha_{k+1}^2 \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[\norm{g_{k+1}({\bm\theta}_k|\mathcal{E}_{k+1})-\triangledown l_{k+1}({\bm\theta}_k)}^2+\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2 - 2\triangledown l_{k+1}({\bm\theta}_k)^T(g_{k+1}({\bm\theta}_k|\mathcal{E}_{k+1})-\triangledown l_{k+1}({\bm\theta}_k))]}{2} \\
& \le \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_k)] - \alpha_{k+1}\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2] + \frac{L\alpha_{k+1}^2 \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_k}[\rho^2+\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2]}{2} \label{eq:SGD_OCL1}  \\
& = \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_k)] - (\alpha_{k+1} - \frac{L\alpha_{k+1}^2}{2})\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2] + \frac{L\alpha_{k+1}^2 \rho^2}{2}. \label{eq:SGD_OCL2}
\end{align}
}

\normalsize
where~\eqref{eq:SGD_OCL1} is due to~\ref{A3_ap} ($\norm{g_{k+1}({\bm\theta}_k|\mathcal{E}_{k+1})-\triangledown l_{k+1}({\bm\theta}_k)}^2\le \rho^2$) and~\ref{A2_ap} ($\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[- 2\triangledown l_{k+1}({\bm\theta}_k)^T(g_{k+1}({\bm\theta}_k|\mathcal{E}_{k+1})-\triangledown l_{k+1}({\bm\theta}_k))] = 0 $). Rearranging the terms in~\eqref{eq:SGD_OCL2} and using~\ref{A4_ap}, we have 
\begin{align}
& (\alpha_{k+1} - \frac{L\alpha_{k+1}^2}{2})\mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[\norm{\triangledown l_{k+1}({\bm\theta}_k)}^2] \\ 
& \le \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_k)] - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[l_{k+1}({\bm\theta}_{k+1})] + \frac{L\alpha_{k+1}^2 \rho^2}{2}, \\
& \le \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k}}[l_{k+1}({\bm\theta}_k)] - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}}[l_{k+2}({\bm\theta}_{k+1})] + \chi_{k+1} + \frac{L\alpha_{k+1}^2 \rho^2}{2}.\label{eq:SGD_OCL3}
\end{align}
Summing both sides of~\eqref{eq:SGD_OCL3} from $j = 0$ to $k$, we have 
\begin{align}
\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2) \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{j}} [\norm{\triangledown l_{j+1}({\bm\theta}_{j})}^2] \le 2 (l_1({\bm\theta}_0) - \mathbb{E}_{\mathcal{E}_1, ...,\mathcal{E}_{k+1}} [l_{k+2}({\bm\theta}_{k+1})]) + L\rho^2 \sum_{j=0}^{k} \alpha_{j+1}^2 + \sum_{j=0}^{k} \chi_{j+1}. 
\end{align}
With a similar derivation as in the proof of Theorem~\ref{theory:SGD_SL}, we immediately have~\eqref{theorem_eq:SGD_OCL}. 
\end{proof}
Intuitively, to make $T_3$ converge to $0$, we need to set the learning rate such that 
\begin{align}\label{eq:SGD_Cond3}
	\lim_{k\rightarrow\infty}\frac{\sum_{j=0}^{k} \chi_{j+1}}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)} = 0,
\end{align}
i.e., we need $\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)$ to increase faster than $\sum_{j=0}^{k} \chi_{j+1}$. In practice, the value of $\chi_{k}$ depends on the application. Given a constant learning rate $\alpha_{k} = \alpha$, $T_3$ can increase for an increasing sequence of $\chi_{k}$. This explains why~\ref{P1} can happen in practice. If $\chi_{k}\ge \chi$ for a constant $\chi$, we cannot have a learning rate schedule that makes $T_1$, $T_2$ and $T_3$ converge to 0 at the same time. Moreover, when $\alpha_k < 1$, decreasing $\alpha_k$ will increase of $T_3$. In the extreme case, if $\alpha_k$ is reduced to 0, $T_3$ will increase in linear speed, causing long term failure of SGD+RWP. This explains~\ref{P2}, i.e., why reducing the learning rate to 0 using RWP hurts the performance of OCL. And demonstrates why we need to keep the learning rate sufficiently large, i.e.,~\ref{P3}. Note that currently, there is no lower bound to demonstrate the tightness of~\eqref{theorem_eq:SGD_OCL}. Hence, the analysis in this section can only be viewed as an intuition. 


 \noindent \textbf{Interpreting Theorem~\ref{theory:SGD_OCL} under limited storage} In practice, both supervised learning and continual learning use a limited amount of (though may be in a large scale) training/replay data. In such cases, the loss ($l_k({\bm\theta})$ in~\eqref{eq:OCL_OBJ} and $l({\bm\theta})$~\eqref{eq:SL_OBJ}) is only computed over the stored data. And our assumptions in the theories are only w.r.t. the loss over the training/replay data. For supervised learning, each training data point can be viewed as a random sample from the original data distribution. For continual learning where not all past data can be stored, one can construct a reservoir replay buffer~\citep{chaudhry2019tiny} online, so that at each time step $t$, each data point in the replay buffer is also a random sample from the original data distribution. Hence, the bound in Theorem~\ref{theory:SGD_OCL} is directly comparable to the bound in Theorem~\ref{theory:SGD_SL} when the replay buffer size in OCL is the same as the dataset size of supervised learning. The performance of a (continual) learner over the original data distribution is the problem of generalization, which is out of the scope of convergence analysis. 

\section{Further Details of AMA and Online Validation}~\label{appdx:AMA_complete}

\vspace{-2em}
\begin{algorithm}[!htb]
	\begin{algorithmic}[1]
		\Require Initial model ${\bm\theta}_0$, the initial moving average weight $\gamma_{0}$, MA weight adjustment coefficient $\delta (>0)$, model update interval $K_M$, validation interval $K_V$, MA weight update interval $K_W$, number of training iterations per time step $p$.
		\State  ${\bm\theta}^{MA_1} \leftarrow {\bm\theta}_0, {\bm\theta}^{MA_2} \leftarrow {\bm\theta}_0 , \gamma^{MA_1} \leftarrow \gamma_0, \gamma^{MA_2} \leftarrow \frac{\gamma_0}{\delta}$
		\State $Acc_1 \leftarrow 0, Acc_2 \leftarrow 0, n \leftarrow 0, i_{best} \leftarrow 1$
		\For {$k \in \{1,2,3,...,\infty\}$}
		\State ${\bm\theta}_{k} \leftarrow {\bm\theta}_{k-1} - \alpha_{k}g({\bm\theta}_{k-1})$
		\If {$k \mod K_M = 0$}\label{alg1:UpdateMA1}
		\State ${\bm\theta}^{MA_1} \leftarrow \gamma^{MA_1} {\bm\theta}^{MA_1} + (1-\gamma^{MA_1}) {\bm\theta}_k$
		\State ${\bm\theta}^{MA_2} \leftarrow \gamma^{MA_2} {\bm\theta}^{MA_2} + (1-\gamma^{MA_2}) {\bm\theta}_k$
		\EndIf\label{alg1:UpdateMA2}
		\If {$k \mod K_V = 0$}\label{alg1:ValStart}
		\State \label{alg1:acc1} $Acc_1 \leftarrow \frac{n \cdot Acc_1 + \texttt{acc}(\mathbf{B}_{\lfloor \frac{k}{p} \rfloor}^V,{\bm\theta}^{MA_1})}{n+1}$, $Acc_2 \leftarrow \frac{n \cdot Acc_2 + \texttt{acc}(\mathbf{B}_{\lfloor \frac{k}{p} \rfloor}^V,{\bm\theta}^{MA_2})}{n+1}$, $n \leftarrow n + 1$
		\State \bf{If} $Acc_1 > Acc_2$ then $i_{best} = 1$  \bf{else} $i_{best} = 2$ \normalfont
		\EndIf\label{alg1:ValEnd}
		\If {$k \mod K_W = 0$}\label{alg1:UpdateWStart}
		\State $Acc_1 \leftarrow 0, Acc_2 \leftarrow 0, n \leftarrow 0$ \label{alg1:resetn}
		\If {$i_{best} = 1$} \Comment{Increase both MA weights but limit them to be $\le 1$}
		\State $\gamma^{MA_1} \leftarrow \min(1, \delta \gamma^{MA_1}), \gamma^{MA_2} \leftarrow \frac{\gamma^{MA_1}}{\delta}$ 
		\State ${\bm\theta}^{MA_2} \leftarrow {\bm\theta}^{MA_1}, i_{best} = 2$
		\Else  \Comment{Decrease both MA weights}
		\State $\gamma^{MA_1} \leftarrow \frac{\gamma^{MA_1}}{\delta}, \gamma^{MA_2} \leftarrow \frac{\gamma^{MA_2}}{\delta}$
		\State ${\bm\theta}^{MA_1} \leftarrow {\bm\theta}^{MA_2}, i_{best} = 1$
		\EndIf
		\EndIf\label{alg1:UpdateWEnd}
		\EndFor
	\end{algorithmic}
	\caption{Adaptive Moving Average (AMA)}\label{alg:AMA_complete}
\end{algorithm}

Alg.~\ref{alg:AMA_complete} describes the complete version of Alg.~\ref{alg:AMA}, with overhead reduction strategies added. Each online validation step (Line~\ref{alg1:ValStart} to Line~\ref{alg1:ValEnd}) computes the accuracy on a batch of data $\mathbf{B}_{\lfloor \frac{k}{p} \rfloor}^V$ sampled from the information retention validation set $\mathbf{S}_{\lfloor \frac{k}{p} \rfloor}^V$ of the current training iteration $k$, where $p$ is the number of SGD updates allowed per time step. We average the computed accuracy on the fly between each $K_W$ iterations, and use the averaged accuracy as the online information retention validation accuracy. The benefit of this online validation process is that the validation steps can be parallelized completely with model updates, and we can also select the best MA model for inference anytime during OCL.


\section{Further Experiments}


\subsection{BN vs GN+WS}~\label{appdx:BN}
\begin{figure}[!hbt]
	\center
	\begin{minipage}[t]{.3\textwidth}
		\includegraphics[width=1\columnwidth]{Figure/exp/BN_vs_WS/exp_main_BN.pdf}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{Information retention over time for models with different normalization layers. ($\uparrow$)} GN+WS performed slightly better than BN in terms of information retention, but more efficient in AMA due to the removal of BN statistics. }\label{fig:exp_GN}
\end{figure}

\vspace{-1em}
As mentioned in Sec.~\ref{sec:AMA}, we replace BN with GN+WS to remove the overhead of re-computing BN statistics in AMA. To show the effect of changing the normalization layer, we compare the model trained with BN against the one trained with GN+WS. Due to resource limitations, we only train the BN model for 700 thousand iterations. As shown in Fig.~\ref{fig:exp_GN}, GN+WS performed slightly better than BN. Combined with the efficiency, GN+WS is suitable for information retention in OCL.



\vspace{-0.5em}
\subsection{Small Learning Rates Stymie Adaptation to New Data}~\label{sec:exp_small_LR}
\begin{figure}[t]
	\center
	\begin{minipage}[t]{.48\textwidth}
		\center
		\includegraphics[width=.5\columnwidth]{Figure/exp/mainResult/Effect_LR_reduce/exp_main_EffectLR_EP192.pdf}
		\subcaption{$k = 5.76\mathrm{e}{5}$. $\alpha_{k}$ is $1.25\mathrm{e}{-2}$ for AMA+MALR, $6.25\mathrm{e}{-3}$ for AMA+RWP, and $9.77\mathrm{e}{-5}$ for SGD+RWP. ($\uparrow$)}\label{fig:exp_EffectLR_ep192}
	\end{minipage}
	\begin{minipage}[t]{.48\textwidth}
		\center
		\includegraphics[width=.5\columnwidth]{Figure/exp/mainResult/Effect_LR_reduce/EP2000/exp_main_EffectLR_EP2000.pdf}
		\subcaption{$k = 4.8\mathrm{e}{8}$. $\alpha_{k}$ is $1.56\mathrm{e}{-3}$ for AMA+MALR, $9.54\mathrm{e}{-8}$ for AMA+RWP, and $2.98\mathrm{e}{-9}$ for SGD+RWP. ($\uparrow$)}\label{fig:exp_EffectLR_ep576}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{Accuracy on evaluation data from different time ranges, for models at two different training iterations $k$.}  Comparing to AMA+MALR, AMA+CLR used a larger learning rate $\alpha_k$, causing performance deterioration on all data ranges. SGD+RWP and AMA+RWP dropped the learning rate too quickly, making the model unable to adapt to new data.}\label{fig:exp_EffectLR}
\end{figure}

\vspace{-2em}
To understand the effect of using suboptimal learning rates on data from different ranges, we take the models of different methods at two distinct training iterations ($k = 5.76\mathrm{e}{5}$ and $k = 4.8\mathrm{e}{8}$), and plot their accuracy on evaluation data from different time ranges. As shown in Fig.~\ref{fig:exp_EffectLR}, AMA+CLR performed worse than AMA+MALR on all data ranges due to the use of a large learning rate. The performance gap was larger on historical data than on future data. SGD+RWP and AMA+RWP performed well only on early data and failed to improve the performance for new data when the learning rate was too low.


\subsection{Heavy parallelism Hurt OCL}\label{sec:exp_BS}
\begin{figure}[t]
	\center
	\vspace{-0.5em}
	\begin{minipage}[t]{.32\textwidth}
		\center
		\includegraphics[width=.8\columnwidth]{Figure/exp/BS/LE/exp_BS_LE.pdf}
		\subcaption{Learning efficacy over time. ($\uparrow$)}\label{fig:exp_BS_LE}
	\end{minipage}
	\begin{minipage}[t]{.32\textwidth}
		\center
		\includegraphics[width=.8\columnwidth]{Figure/exp/BS/exp_BS_IR.pdf}
		\subcaption{Information retention over time. ($\uparrow$)}\label{fig:exp_BS_IR}
	\end{minipage}
	\begin{minipage}[t]{.32\textwidth}
		\center
		\includegraphics[width=.8\columnwidth]{Figure/exp/BS/FT/exp_BS_FT.pdf}
		\subcaption{Forward transfer over time. ($\uparrow$)}\label{fig:exp_BS_FT}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{Effect of batch sizes.} Increasing the batch size hurt all OCL performance metrics.}\label{fig:exp_BS}

\end{figure}


\citet{cai2021online} have shown that increasing batch sizes for optimizing learning efficacy hurts all OCL performance metrics. We perform a similar analysis to study whether this phenomenon still happens when optimizing information retention. Specifically, we optimize information retention with batch sizes varying from 64 to 1024. When we increase the batch size, we reduce the number of training iterations per time step and increase the learning rate by the same factor. We allow 1 training iteration per time step for a batch size of 256. As shown in Fig.~\ref{fig:exp_BS}, increasing batch sizes for optimizing information retention also hurt all OCL performance metrics.

\subsection{A Reasonably Large Replay Buffer Is Sufficient}\label{sec:exp_RepBufSize}
\begin{figure}[t]
	\center

	\begin{minipage}[t]{.32\textwidth}
		\center
		\includegraphics[width=.8\columnwidth]{Figure/exp/RepBufSize/LE/exp_RepBufSize_LE.pdf}
		\subcaption{Learning efficacy over time. ($\uparrow$)}\label{fig:exp_RepBufSize_LE}
	\end{minipage}
	\begin{minipage}[t]{.32\textwidth}
		\center
		\includegraphics[width=.8\columnwidth]{Figure/exp/RepBufSize/exp_RepBufSize_IR.pdf}
		\subcaption{Information retention over time. ($\uparrow$)}\label{fig:exp_RepBufSize_IR}
	\end{minipage}
	\begin{minipage}[t]{.32\textwidth}
		\center
		\includegraphics[width=.8\columnwidth]{Figure/exp/RepBufSize/FT/exp_RepBufSize_FT.pdf}
		\subcaption{Forward transfer over time. ($\uparrow$)}\label{fig:exp_RepBufSize_FT}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{Effect of replay buffer sizes.} Though all performance metrics dropped when the replay buffer size was reduced to 400 thousand images, the performance remained similar when the replay buffer size was larger than 4 million images. }\label{fig:exp_RepBufSize}

\end{figure}

We now analyze the effect of replay buffer sizes, by training models with replay buffer sizes of 400 thousand, 4 million, and 40 million images. To optimize information retention, we use a reservoir buffer~\citep{chaudhry2019tiny} in this experiment. We allow 5 training iterations per time step for each replay buffer size.

As shown in Fig.~\ref{fig:exp_RepBufSize}, reducing the replay buffer size from 40 million to 400 thousand images significantly hurt all performance metrics. However, the performance remained similar when the replay buffer size was 4 million or larger. Therefore, given a fixed model and computational budget, OCL only requires a \emph{reasonably large} replay buffer.



\subsection{Apply AMA to Other Base Optimizers}~\label{sec:ADAM}
\vspace{-1em}
\begin{figure}[t]

	\begin{minipage}[t]{1\textwidth}
		\center
		\includegraphics[width=.3\columnwidth]{Figure/exp/ADAM/exp_main_acc_NZ.pdf}
	
		\caption{\textbf{ADAM results}. ($\uparrow$) AMA+MALR applied to ADAM also improved information retention in OCL. However, ADAM-based methods performed worse than SGD counterparts.}\label{fig:ADAM}
	\end{minipage}










\end{figure}

Besides SGD, AMA+MALR can also be combined with other base optimizers. As an example, we apply it to ADAM and test the performance on CLOC. Specifically, we compare (ADAM-based) AMA+MALR with ADAM+MALR and ADAM+RWP, with an initial learning rate tuned to 0.001. Due to resource limitations, we only run all algorithms on partial data. As shown in Fig.~\ref{fig:ADAM}, (ADAM) AMA+MALR outperformed ADAM+RWP. However, ADAM methods performed worse than SGD. We conjecture that the adaptive scaling in ADAM reduced the effective learning rate (similar to the SGD+RWP case), and leave further investigations as future works. Due to the poor performance of ADAM-based methods, we use SGD-based methods in the main experiments. 


\vspace{-0.5em}
\subsection{Impact of Optimization Objectives to OCL}\label{sec:exp_obj}

\begin{figure}[t]
	\center
	\begin{minipage}{1\textwidth}
		\begin{minipage}[t]{.32\textwidth}
			\center
			\includegraphics[width=.8\columnwidth]{Figure/exp/LE_vs_IR/LE/exp_LE_vs_IR_LE.pdf}
			\subcaption{Learning efficacy over time. ($\uparrow$)}\label{fig:exp_LE_vs_IR_LE}
		\end{minipage}
		\begin{minipage}[t]{.32\textwidth}
			\center
			\includegraphics[width=.8\columnwidth]{Figure/exp/LE_vs_IR/IR/exp_LE_vs_IR_IR.pdf}
			\subcaption{Information retention over time. ($\uparrow$)}\label{fig:exp_LE_vs_IR_IR}
		\end{minipage}
		\begin{minipage}[t]{.32\textwidth}
			\center
			\includegraphics[width=.8\columnwidth]{Figure/exp/LE_vs_IR/FT/exp_LE_vs_IR_FT.pdf}
			\subcaption{Forward transfer over time. ($\uparrow$)}\label{fig:exp_LE_vs_IR_FT}
		\end{minipage}
		\vspace{-0.5em}
		\caption{\textbf{Optimizing learning efficacy (LE Model) vs optimizing information retention (IR Model).} Optimizing information retention hurt learning efficacy (a), but improved information retention (b) and forward transfer (c). More importantly, increasing the budget for optimizing learning efficacy hurt both information retention and forward transfer. In contrast, increasing the budget for optimizing information retention improved all OCL metrics.}\label{fig:exp_LE_vs_IR}
	\end{minipage}
\end{figure}

An ideal OCL algorithm should perform well for all three metrics, i.e., learning efficacy (eq.~\eqref{eq:metric_LE}), information retention (eq.~\eqref{eq:metric_IR}), and forward transfer (eq.~\eqref{eq:metric_FT}). However, optimizing one objective can hurt others. To demonstrate this point, we compare the model trained to optimize information retention (with AMA+MALR), and the model trained to optimize learning efficacy (with the method of \cite{cai2021online}). Following \cite{cai2021online}, we allow different computation budgets (1 and 5 training iterations) per time step. To fairly compare pure replay and mixed replay, we double the batch size for AMA+MALR, so that the average number of gradient descent steps per image is the same for the two models. We set $k_1$ and $k_2$ in the forward transfer metric to $10\%$ and $25\%$ of the dataset size respectively.

As shown in Fig.~\ref{fig:exp_LE_vs_IR_LE}, given the same budget, optimizing learning efficacy (LE Model) performed the best for learning efficacy. Optimizing information retention (IR Model) performed the best for information retention (Fig.~\ref{fig:exp_LE_vs_IR_IR}) and forward transfer (Fig.~\ref{fig:exp_LE_vs_IR_FT}). More importantly, unlike optimizing information retention, where increasing the computation budget improved all OCL metrics, increasing the computation budget for optimizing learning efficacy \emph{hurt} information retention and forward transfer. This phenomenon is consistent with the finding in the language modeling setting~\citep{hu2020drinking}. Hence in terms of improving long term transfer in OCL, information retention is a better objective than learning efficacy.


\subsection{Details on Google Landmarks v2}\label{appdx:GoogleLM}

Similar to CLOC, we construct the OCL version of Google Landmarks v2 using the subset of images from Flickrs, which have time stamps that can be retrieved from flickr API. Similar to the original paper~\citep{weyand2020google}, we address the noisy label and class imbalance issues by using only the data from the cleaned set, and filter out the classes with fewer than 25 images. This results in 645666 images in total. We further divide the dataset into $90\%$ of training data (roughly 580 thousand images) and $10\%$ of evaluation data (roughly 65 thousand images). 

In terms of hyper-parameters, we use the same model as the CLOC dataset. We tune other hyper-parameters on the first $20\%$ of the training data (we still use this part of data during training because otherwise the dataset will be even smaller), resulting in the learning rate of 0.135, the momentum of 0.9 for SGD, the weight decay of 1e-4, and the cross-entropy loss. 

\subsection{Details on ImageNet Continual Learning Experiments}\label{appdx:IN_hyper}

We mostly follow the hyper-parameter settings of supervised learning, i.e., we use ResNet50, with batch size of 256, initial learning rate of 0.1, the momentum of 0.9 for SGD, the weight decay of 1e-4. For ER, GDumb and MIR, we use the same basic hyper-parameter as SGD+Cyclic, including the optimizer, learning rates, the batch size etc. For ER, we mix 128 samples from the current task and 128 samples from replay for each model udpate step. For MIR, we select 128 examples from 256 candidates (using the $s_{MI-1}$ criterion) during the replay data sampling procedure, and mix them with another 128 examples from the current task to update the model. For a fair comparison, we limit the computation of each method to be the same as SGD+Cyclic. Specifically, MIR requires at least two SGD iterations in each model update step, hence, the total number of model update steps is limited to half of the SGD steps in SGD+Cyclic. GDumb trains a model from scratch for each task, hence the number of SGD updates of GDumb and SGD+Cyclic is limit to be the same in each task. To make the final validation accuracy directly comparable to the standard ResNet50 supervised learning result, we use BN as the normalization layer in this experiment (The GN+WS model performed slightly better than the BN model). To update BN statistics on the fly, we do one extra forward pass per 10 training iterations to accumulate the BN statistics for MA models. For both RWP and AMA, we decay the learning rate by half when the corresponding conditions are satisfied. We set $K_R$ in RWP and AMA to 15000, which is smaller than in CLOC, so that the effect of learning rate reduction can be clearly seen. 

We also show in Fig.~\ref{fig:IN_GN_BN} the performance comparison between the BN model and the GN+WS model. Similar as in CLOC, GN+WS also performed slightly better than BN. And its best validation accuracy in the final task ($76.8\%$) is similar as the standard BN model trained with supervised learning. This result confirmed the generalization of our method across problems and datasets.

\begin{figure}[t]
	\center
	\includegraphics[width=.8\columnwidth]{Figure/exp/ImageNetCL/IN_task_avg_GN.pdf}
	\vspace{-.8em}
	\caption{\textbf{BN vs GN+WS in ImageNet continual learning.} ($\uparrow$) Similar as in CLOC, GN+WS also performed slightly better than the BN model on ImageNet continual learning. And its best validation accuracy in the final task  ($76.8\%$) is similar as the standard BN model trained with supervised learning.}\label{fig:IN_GN_BN}

\end{figure}

\subsection{Small replay buffer on ImageNet}\label{appdx:IN_mem}
\begin{figure}[t]
	\center
	\includegraphics[width=.8\columnwidth]{Figure/exp/ImageNetCL/IN_task_limitedMem3.pdf}
	\vspace{-.8em}
	\caption{\textbf{Information retention on ImageNet continual learning with small replay buffer (120K images).} ($\uparrow$) Similar to the results in the main experiment, AMA+MALR out-performed SGD+Cyclic and other OCL methods designed for handling storage limitations. Interestingly, the gap between SGD+Cyclic and ER/MIR became smaller in this case.}\label{fig:IN_mem}

\end{figure}

 In this section, we show the ImageNet continual learning result with limited storage. Specifically, we only allow 120K images to be stored in the replay buffer, and compare AMA+MALR against SGD+Cyclic, ER, MIR and GDumb. For AMA+MALR, SGD+Cyclic and GDumb, the replay buffer is formed using reservoir sampling. For ER and MIR, we assign half of the replay buffer for storing data from previous tasks (using reservoir sampling), and half of the replay buffer for storing data from the current task. As shown in Fig.~\ref{fig:IN_mem}, AMA+MALR still outperformed all competitors in this case. Interestingly, the performance gap between SGD+Cyclic and ER/MIR became smaller compared to the case of large replay buffers.


\subsection{Performance on Supervised Learning}\label{appdx:SL}

\begin{figure}[!hbt]
	\center
	\begin{minipage}[t]{.23\textwidth}
		\includegraphics[width=1\columnwidth]{Figure/exp/ImageNet/exp_IN.pdf}
		\subcaption{Validation accuracy over time. ($\uparrow$)}\label{fig:exp_IN_val}
	\end{minipage}
	\begin{minipage}[t]{.23\textwidth}
		\includegraphics[width=1\columnwidth]{Figure/exp/ImageNet/exp_IN_LR.pdf}
		\subcaption{Learning rate over time.}\label{fig:exp_IN_LR}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{Performance of AMA and MALR on ImageNet for supervised learning. ($\uparrow$)} Similar as in the OCL case, AMA performed much better than SGD when the learning rate was large. MALR adaptively reduced the learning rate, providing similar final performance as the cosine schedule.}\label{fig:exp_ImageNet}
	\vspace{+.5em}
\end{figure}

To understand the performance of AMA + MALR on supervised learning, we apply it to ImageNet, and compare against SGD + cosine schedule (denoted as SGD+Cosine), which is the standard for ImageNet. To understand the effect of each component, we also show the performance of AMA+Cosine and the SGD model in AMA+MALR. To replicate the standard ResNet50 result on ImageNet, we use BN as the normalization layer, and train all models for 120 epochs. Since limiting the minimum learning rate hurts supervised learning, we only use \nameref{C1} and \nameref{C2} in MALR for this experiment. We reduce the learning rate by 10 times once \nameref{C1} and \nameref{C2} are true. 

As shown in Fig.~\ref{fig:exp_ImageNet}, though not better in terms of the final performance, AMA performed much better than SGD at early training stages, where the learning rate was large. MALR adaptively reduced the learning rate over time, providing a similar final performance as the cosine schedule.



\subsection{AMA hyper-parameter tuning and sensitivity}\label{sec:AMA_hyper}

As described in Sec.~\ref{sec:AMA}, we set the MA weight adjustment coefficient $\delta$ to 5 and the interval $K_W$ to adjust MA weights to 10000 iterations. We empirically observed that setting $K_W$ in between 1-10000, and $\delta$ between 2-10 does not have strong effect to the performance (i.e., the classification accuracy). Setting $K_W$ to 10000 and $\delta$ to 5 worked across problems (ImageNet, CLOC, Google Landmarks) and provides AMA a similar speed as SGD in practice. 


For classification tasks, we set $\epsilon$ in \nameref{C3} to $3\%$ accuracy. This value worked for CLOC, ImageNet and CGLM (only tuned on the CLOC preprocessing data). It can be used as a reasonable default for other datasets as well. For tasks other than classification, one can tune $\epsilon$ by:
\begin{enumerate}
	\item Finding the best initial learning rate on preprocessing data.
	\item Using a constant learning rate schedule, with learning rate set to the best initial learning rate. Compute the performance gap between AMA and SGD models on pre-processing data, denoted as g.
	\item Setting $\epsilon$ to roughly 0.3g (this is how we set our $\epsilon$), we observe that the performance difference is small by setting $\epsilon$ in between 0.5-0.2g.
\end{enumerate}




\section{Experiments}\label{sec:exp}

\noindent \textbf{Implementation details.} We mainly use CLOC~\citep{cai2021online} to study OCL at large scale. Similar to the setting of \citet{cai2021online}, the model receives 256 images at each time step. We use the ResNet-50 architecture, a batch size of 256 and tune the initial hyperparameters on the preprocessing data. We set the initial learning rate $\alpha_0$ to $0.025$, the momentum of SGD to $0.9$, the weight decay to $1e-4$, and the loss to cross-entropy. For RWP, we reduce the learning rate by half if the information retention validation loss stops decreasing for $K_R = 60000$ training iterations. For MALR, we set $\sigma_k$ as the difference of the information retention validation accuracy between the MA and the SGD models, and set $\epsilon$ in \nameref{C3} to $3.0\%$. To decouple the effect of the storage limit and better focus on studying the problem of limited computation in large scale OCL, we use a replay buffer size of 40 million images in main experiments. Appx.~\ref{sec:exp_RepBufSize} ablates the effect of replay buffer sizes and shows that large scale OCL only requires a reasonably large replay buffer (4 million images for CLOC). We use the same set of hyperparameters introduced by AMA/MALR in all experiments to verify their robustness. (See Appx.~\ref{sec:AMA_hyper} for further details.) All models are trained with 8 Nvidia Geforce Rtx 2080 Ti GPUs. We refer to the information retention validation loss/accuracy throughout the experiments as the validation loss/accuracy. The arrows ($\uparrow$/$\downarrow$) in the caption of each figure point towards the direction of improvement. 





\subsection{Main Result: Effectiveness of AMA and MALR} \label{sec:exp_main}
\begin{figure}[t]
\vspace{-2em}
	\center
	\begin{minipage}[t]{.19\textwidth}
	\includegraphics[width=1\columnwidth]{Figure/exp/rebuttal/exp_main_acc_reb.pdf}
	\subcaption{Information retention over time. ($\uparrow$)}\label{fig:exp_main_IR}
	\end{minipage}
	\begin{minipage}[t]{.19\textwidth}
	\includegraphics[width=1\columnwidth]{Figure/exp/mainResult/LR/exp_main_LR_logScale.pdf}
	\subcaption{Log-scaled learning rate over time.}\label{fig:exp_main_LR_logScale}
\end{minipage}
	\begin{minipage}[t]{.19\textwidth}
	\includegraphics[width=1\columnwidth]{Figure/exp/mainResult/valLoss/exp_main_valLoss.pdf}
	\subcaption{Validation loss over time. ($\downarrow$)}\label{fig:exp_main_valLossf}
\end{minipage}
	\begin{minipage}[t]{.19\textwidth}
	\includegraphics[width=1\columnwidth]{Figure/exp/mainResult/valLoss/exp_main_valLoss_250ep.pdf}
	\subcaption{Validation loss (zoomed view). ($\downarrow$)}\label{fig:exp_main_valLoss_250ep}
\end{minipage}
	\begin{minipage}[t]{.19\textwidth}
	\includegraphics[width=1\columnwidth]{Figure/exp/mainResult/AccDiff/exp_main_accDiff.pdf}
	\subcaption{$\sigma_k$ over time.}\label{fig:exp_main_accDiff}
	\end{minipage}
\vspace{-0.5em}
	\caption{\textbf{Results on CLOC}. (a): AMA+MALR outperformed all competitors. Among optimizers, AMA outperformed SGD in both RWP and MALR. (b): MALR effectively annealed the learning rate over time, outperforming RWP and CLR. (c) $\&$ (d): Under distribution shifts, the validation loss increased for constant learning rates in both long and short terms. This made RWP reduce the learning rate too fast. (e): Given a constant learning rate, $\sigma_k$ in MALR first increased and then plateaued. $\sigma_k$ declined with the learning rate reduction. This trend was stable even under distribution shifts.}\label{fig:exp_main}
	\vspace{-0.1em}
\end{figure}


To study the effectiveness of AMA + MALR, we compare it against SGD + RWP (SGD is used as the base optimizer due to high performance, see Appx.~\ref{sec:ADAM} for similar experiments on ADAM). To separate the effects of optimizers and  learning rate schedules, we also compare against AMA + RWP, AMA + constant learning rate (CLR), the SGD model in AMA+MALR, and SGD+CLR (using training + validation data for training since no online hyperparameter adaptation is needed). We allow 80 training iterations per time step, so that the number of training iterations is large enough and learning rate annealing is necessary. 
We evaluate information retention using $P_{IR}(t)$. 

As shown in Fig.~\ref{fig:exp_main_IR}, AMA+MALR outperformed all competitors. The ``jumps" of the performance curves were due to the learning rate change in RWP or MALR. Note that the information retention in Fig.~\ref{fig:exp_main_IR} was not monotonically increasing because of the distribution shifts. In terms of the optimizer, AMA was better than SGD in all learning rate schedules. Moreover, the performance gap was especially large for large learning rates, validating~\ref{P3}. In terms of the learning rate schedule, MALR outperformed both RWP and CLR. Specifically,
the distribution shift made the validation loss increase over time for constant learning rates (Fig.~\ref{fig:exp_main_valLossf} and~\ref{fig:exp_main_valLoss_250ep}). This phenomenon caused RWP to reduce the learning rate too fast (Fig.~\ref{fig:exp_main_LR_logScale}). As a result, AMA+RWP and SGD+RWP performed even worse than SGD+CLR in the long term. In contrast, MALR effectively controlled the learning rate reduction speed and the minimum learning rate with the help of the new signal $\sigma_k$ (Fig.~\ref{fig:exp_main_accDiff}), which was more robust to distribution shifts than the validation loss/accuracy. 

\subsection{Ablations}\label{sec:exp_MALR}

\begin{figure}[t]
	\vspace{-2em}
	\center
	\begin{minipage}[t]{.35\textwidth}
		\center
		\includegraphics[width=0.86\columnwidth]{Figure/exp/MALR_ABL/exp_MALR_ABL.pdf}
		\subcaption{Information retention over time. ($\uparrow$)}\label{fig:exp_MALR_Acc}
	\end{minipage}
	\begin{minipage}[t]{.3\textwidth}
		\center
		\includegraphics[width=\columnwidth]{Figure/exp/MALR_ABL/LR/exp_MALR_LR.pdf}
		\subcaption{Learning rate over time.}\label{fig:exp_MALR_LR}
	\end{minipage}
	\begin{minipage}[t]{.3\textwidth}
		\center
		\includegraphics[width=\columnwidth]{Figure/exp/MALR_ABL/AccDiff/exp_main_accDiff.pdf}
		\subcaption{$\sigma_k$ over time.}\label{fig:exp_MALR_AccDiff}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{Ablation for MALR.} AMA+MALR outperformed all competitors. AMA+MALR+No C2 reduced the learning rate too fast at early stages, causing~\ref{P1}. AMA+MALR+No C3 did not limit the minimum learning rate, causing~\ref{P2}. AMA+RWP performed worst.}\label{fig:exp_MALR}
	\vspace{0.5em}
\end{figure}

 MALR extends RWP by introducing \nameref{C2} and \nameref{C3}. To understand the effect of each condition, we compare AMA+MALR to versions where \nameref{C2} is removed (AMA+MALR+No C2), \nameref{C3} is removed (AMA+MALR+No C3), and both are removed (AMA+RWP).

As shown in Fig.~\ref{fig:exp_MALR_Acc}, AMA+MALR+No C3 failed to limit the minimum learning rate (\ref{P2}), and performed worse than AMA+MALR in the long term. AMA+MALR+No C2 reduced the learning rate too quickly (\ref{P1}) at the early stage compared to AMA+MALR. With both \nameref{C2} and \nameref{C3} removed, AMA+RWP performed the worst in all methods. As shown in Fig.~\ref{fig:exp_MALR_AccDiff}, the performance of all competitors dropped when $\sigma_k$ was too low, which happened when the learning rate was too small (Fig.~\ref{fig:exp_MALR_LR}). Hence, $\sigma_k$ is an effective learning rate annealing signal for OCL. Appx.~\ref{sec:exp_small_LR} further analyzes the effect of using suboptimal learning rates. To summarize, large learning rates led to poor convergence and hurt performance on data \emph{from all time ranges}. On the other hand, small learning rates prevented the model from adapting to new data. 

\begin{figure}[t]
	\vspace{-1.5em}
	\center
	\begin{minipage}[t]{.49\textwidth}
		\center
		\includegraphics[width=.65\columnwidth]{Figure/exp/AMA_vs_EMA/exp_AMA_vs_EMA.pdf}
		\subcaption{Information retention over time. ($\uparrow$)}\label{fig:exp_AMA_vs_EMA_Acc}
	\end{minipage}
	\begin{minipage}[t]{.49\textwidth}
		\center
		\includegraphics[width=.65\columnwidth]{Figure/exp/AMA_vs_EMA/MA_weight/exp_AMA_vs_EMA_weight.pdf}
		\subcaption{MA weight over time.}\label{fig:exp_AMA_vs_EMA_weight}
	\end{minipage}
	\vspace{-0.5em}
	\caption{\textbf{AMA vs EMA}. AMA performed better than EMA by adapting the MA weight over time.}\label{fig:exp_AMA_vs_EMA}
	\vspace{-.8em}
\end{figure}

\noindent \textbf{AMA vs EMA.} We study the effect of population-based MA weight adaptation. We compare AMA with EMA and use the learning rate generated by AMA+MALR on both models to remove the effect of learning rate annealing. Due to resource limitations, we train EMA only for 700 thousand iterations. As shown in Fig.~\ref{fig:exp_AMA_vs_EMA}, AMA outperformed EMA by adapting the MA weight over time.

\noindent \textbf{Further analyses in the appendix.} Due to the space limit, we provide the following analyses in the appendix. \emph{Effect of batch sizes in Appx.~\ref{sec:exp_BS}}: Heavy parallelization by increasing batch sizes and decreasing the number of training iterations has negative impact on all OCL metrics.  \emph{Effect of training objectives, i.e.,~\eqref{eq:pureRep} vs~\eqref{eq:mixRep}, in Appx.~\ref{sec:exp_obj}}: Optimizing information retention (using~\eqref{eq:pureRep}) is more suitable for both information retention and long-term forward transfer, at the cost of sacrificing learning efficacy. More importantly, increasing the computation budget for optimizing information retention improved all OCL metrics, whereas increasing the computation budget for optimizing learning efficacy (using~\eqref{eq:mixRep}) \emph{hurt} information retention and forward transfer.











\subsubsection{Effectiveness of AMA beyond CLOC}\label{sec:OtherData}
\begin{figure}[t]
	\vspace{-0.5em}
	\center
 \begin{small}
 \begin{tabular}{@{\hspace{1mm}}p{31mm}@{\hspace{2mm}}p{31mm}@{\hspace{2mm}}p{36mm}@{\hspace{2mm}}p{35mm}@{}}
 \includegraphics[width=0.23\textwidth]{Figure/exp/GoogleLM/exp_GoogleLM_IR.pdf} &
 \includegraphics[width=0.23\textwidth]{Figure/exp/GoogleLM/LR/exp_GoogleLM_LR.pdf} &
 \includegraphics[ width=0.23\textwidth]{Figure/exp/GoogleLM/CLOC_Zoom/exp_main_acc.pdf} &
 \includegraphics[ width=0.23\textwidth]{Figure/exp/GoogleLM/CLOC_Zoom/exp_main_LR.pdf} \\
    (a) Information retention on CGLM ($\uparrow$).  & 
    (b) Learning rate over time on CGLM. & 
    (c) Information retention on the first 580K CLOC images. & 
    (d) Learning rate for the first 580K images of CLOC.
    \\
 \end{tabular}
 \end{small}
	\vspace{-0.5em}
	\caption{\textbf{Results on the CGLM}. AMA performed better than SGD. Given only 580K images, the difference of learning rate schedules are unclear for CGLM ((a) $\&$ (b)) and CLOC ((c) $\&$ (d)).  }\label{fig:exp_GoogleLM}
	\vspace{-.2em}
 \label{CGLM_results}
\end{figure}


\noindent\textbf{Google Landmarks.} We apply AMA+MALR to \emph{Google Landmarks v2}~\citep{weyand2020google}, which contains images from different landmarks (each representing a class). We construct our continual dataset using a subset of 580 thousand training images with time stamps. We refer to the constructed dataset as \emph{\textbf{C}ontinual \textbf{G}oogle \textbf{L}and\textbf{M}arks (CGLM)}. Similar to CLOC, 256 new images are revealed at each time step, and 80 training iterations are allowed per time step (see Appx.~\ref{appdx:GoogleLM} for more implementation details). As shown in Fig.~\ref{CGLM_results}-a, AMA performed better than SGD in CGLM. Since CGLM is small-scale, the learning rate of both RWP and MALR remained constant throughout most of the training. Hence, we only reported the performance of AMA+MALR and the SGD model. To further check this limitation, we also looked at the first 580K images of CLOC in Figs.~\ref{CGLM_results}-c and~\ref{CGLM_results}-d. Similar to CGLM, the relative merit of different learning rate schedules was unclear. Hence, a large-scale dataset is necessary for analyzing OCL learning rate schedules. 

\begin{figure}
	\center
 	\vspace{-.5em}
	\includegraphics[width=.85\columnwidth]{Figure/exp/rebuttal/CL_methods/IN_task_avg3.pdf}
	\vspace{-.8em}
	\caption{\textbf{ImageNet results ($\uparrow$).}  AMA+MALR out-performed both SGD+RWP and SGD+Cyclic. The final validation accuracy is close to the supervised learning model. Due to the implicit computation increase in each model update iteration, OCL methods performed worse than simple SGD+Cyclic when the memory is sufficiently large and the computation is explicitly limited.  }\label{fig:IN_task}
    \vspace{-.8em}
\end{figure}


\noindent\textbf{ImageNet.} We test our method on task-based benchmarks synthesized from ImageNet. Specifically, we create a 100-task continual learning problem by randomly dividing ImageNet classes, so that each task contains data from 10 classes. During training, we allow $\frac{120 |\mathbf{X}_t|}{256}$ training iterations per task, where $|\mathbf{X}_t|$ is the number of images of task $t$ and 256 is the training batch size. In this setting, the total number of SGD steps of a continual learner trained on all tasks is the same as the standard supervised learning model trained for 120 epochs. During evaluation, we compute the average accuracy on validation data from all revealed tasks. To demonstrate the online performance, we perform multiple evaluations during each task. Since clear task boundaries are available, we also compare against SGD+Cyclic, where the cosine learning rate schedule is used in each task. We further compare against methods designed for handling storage limitations: GDumb~\citep{prabhu2020gdumb}, ER~\citep{aljundi2018memory}, and MIR~\citep{aljundi2019online}. We explicitly limit the computation budget of ER, GDumb, and MIR to be similar to other methods. See Appx.~\ref{appdx:IN_hyper} for more details about the experimental setup and hyperparameter settings.

As shown in Fig.~\ref{fig:IN_task}, AMA+MALR outperformed both SGD+RWP and SGD+Cyclic. Comparing to SGD+Cyclic, AMA+MALR had better intermediate and final performance during each task, making it more suitable for online applications. Using the same number of SGD steps, the final validation accuracy of AMA+MALR was close to supervised learning. On the other hand, ER, MIR, and GDumb performed worse than SGD+Cyclic since implicit computation increase in each model update step made them require more computation/time to converge. Note that here we allow the replay buffer to store all past data. This result demonstrates that limited computation and limited storage are orthogonal problems in OCL. The are both important and require dedicated treatments. 
See Appx.~\ref{appdx:IN_mem} for similar results with limited storage. 



















\section{Conclusion}\label{sec:conclusion}
We studied the problem of improving information retention in online continual learning (OCL). We proposed to use pure replay as the objective for optimizing information retention. We provided theoretical analysis of the convergence of SGD in OCL. We also proposed an Adaptive Moving Average (AMA) Optimizer and a Moving-Average-based Learning Rate Schedule (MALR) to optimize the pure replay objective online. Experiments on several large-scale continual learning benchmarks demonstrate the effectiveness of AMA+MALR. 
In terms of limitations and future work, we used two MA models to adapt the MA weights, which increases the GPU memory footprint to store the network weights for MA models (but not the gradient information as in the SGD model). Designing more memory-efficient techniques to adapt MA weights is an interesting future research direction. Furthermore, this work mainly focused on studying the problem of limited computation in OCL. Developing effective solutions to address the computation and storage aspects together is an interesting and important future direction.



\section{Introduction}
\label{sec:intro}
Supervised learning commonly assumes that the data is independent and identically distributed (iid.). This assumption is violated in practice when the data comes from a non-stationary distribution that evolves over time. Continual learning aims to solve this problem by designing algorithms that efficiently learn and retain knowledge over time from a data stream. Continual learning can be classified into online and offline. The offline setting~\citep{li2017learning} mainly limits the storage: only a fixed amount of training data can be stored at each time step. The computation is not limited in offline continual learning: the model can be trained from scratch until convergence at each step. In contrast, the online setting only allows a limited amount of storage and computation at each time step.

A number of metrics can be used to evaluate a continual learner. If the model is directly evaluated on the incoming data, the objective is \emph{learning efficacy}; this evaluates the ability to efficiently adapt to new data. If the model is evaluated on historical data, the objective is \emph{information retention}; this evaluates the ability to retain existing knowledge. These two objectives are in conflict, and their trade-off is known as the plasticity-stability dilemma~\citep{mccloskey1989catastrophic}.




Following recent counterintuitive results, we single out information retention in this work. A common assumption in the continual learning literature is that information retention is only a problem due to the storage constraint. Take replay-buffer-based methods as an exemplar. It is tacitly understood that since they cannot store the entire history, they forget past knowledge which is not stored. However, this intuition is challenged by recent empirical results. For example, \citet{cai2021online} show that the information retention problem persists even when past data is stored in its entirety. We argue that, at least in part, the culprit for information loss is optimization. 

Direct application of SGD to a continual data stream is problematic. Informally, consider the learning rate (\emph{i.e.}, step size). It needs to decrease to zero over time to guarantee convergence~\citep{ghadimi2013stochastic}. However, this cannot be applied to a continual and non-iid. stream since infinitesimal learning rates would simply ignore the new information and fail to adapt, resulting in underfitting. This underfitting would worsen over time as the distribution continues to shift. We formalize this problem and further show that there is no straightforward method to control this trade-off, and this issue holds even when common adaptive learning rate heuristics are applied.

Orthogonal to continual learning, one recently proposed remedy to guarantee SGD convergence with high learning rates is using the moving average of SGD iterates~\citep{mandt2016variational, tarvainen2017mean}. Informally, SGD with large learning rates bounces around the optimum. Averaging its trajectory dampens the bouncing and tracks the optimum better~\citep{mandt2016variational}. We apply these ideas to OCL for the first time to improve information retention. 

To summarize, we theoretically analyze the behavior of SGD for OCL. Following this analysis, we propose a moving average strategy to optimize information retention. Our method uses SGD with large learning rates to adapt to non-stationarity, and utilizes the average of SGD iterates for better convergence. We propose an adaptive moving average (AMA) algorithm to control the moving average weight over time. Based on the statistics of the SGD and AMA models, we further propose a moving-average-based learning rate schedule (MALR) to better control the learning rate. Experiments on Continual Localization (CLOC)~\citep{cai2021online}, Google Landmarks~\citep{weyand2020google}, and ImageNet~\citep{deng2009imagenet} demonstrate superior information retention and long-term transfer for large-scale OCL.



\section{Related Work}
\noindent\textbf{Optimization in OCL.}
 OCL methods typically focus on improving learning efficacy. \citet{cai2021online} proposed several strategies, including adaptive learning rates, adaptive replay buffer sizes, and small batch sizes. ~\citet{hu2020drinking} proposed a new optimizer, ConGrad, which, at each time step, adaptively controls the number of online gradient descent steps~\citep{hazan2019introduction} to balance generalization and training loss reduction. Our work instead focuses on information retention and proposes a new optimizer and learning rate schedule that trade off learning efficacy to improve long-term transfer. In terms of replay buffer strategies, mixed replay~\citep{chaudhry2019tiny}, originating from offline continual learning, forms a minibatch by sampling half of the data from the online stream and the other half from the history. It has been applied in OCL to optimize learning efficacy~\citep{cai2021online}. Our work uses pure replay instead to optimize information retention, where a minibatch is formed by sampling uniformly from all history.

\noindent \textbf{Continual learning algorithms.}
We focus on the optimization aspect of OCL. Other aspects, such as the data integration~\citep{aljundi2019gradient} and the sampling procedure of the replay buffer~\citep{aljundi2019online, chrysakis2020online}, are complementary and orthogonal to our study. These aspects are critical for a successful OCL strategy and can potentially be used in conjuction with our optimizers. Offline continual learning~\citep{li2017learning, kirkpatrick2017overcoming} aims to improve information retention with limited storage. Unlike the online setting, SGD works in this case since the model can be retrained until convergence at each time step. We refer the readers to \citet{delange2021continual} for a detailed survey of offline continual learning algorithms.

\noindent \textbf{Moving average in optimization.} We propose a new moving-average-based optimizer for OCL. Although we are the first to apply this idea to OCL, moving average optimizers have been widely utilized for convex~\citep{ruppert1988efficient, polyak1992acceleration} and non-convex optimization~\citep{izmailov2018averaging, maddox2019simple, he2020momentum}. Beyond supervised learning~\citep{izmailov2018averaging, maddox2019simple}, the moving average model has also been used as a teacher of the SGD model in semi-supervised~\citep{tarvainen2017mean} and self-supervised learning~\citep{he2020momentum}. The moving average of stochastic gradients (rather than model weights) has also been widely used in ADAM-based optimizers~\citep{kingma2014adam}. 

\noindent \textbf{Continual learning benchmarks.} We need a large-scale and realistic benchmark to evaluate OCL. For language modeling, \citet{hu2020drinking} created the Firehose benchmark using a large stream of Twitter posts. The task of Firehose is continual per-user tweet prediction, which is self-supervised and multi-task.
For visual recognition, \citet{lin2021clear} created the CLEAR benchmark by manually labeling images on a subset of YFCC100M~\citep{thomee2016yfcc100m}. Though the images are ordered in time, the number of labeled images is small (33K). \citet{cai2021online} proposed the continual localization (CLOC) benchmark using a subset of YFCC100M with time stamps and geographic locations. The task of CLOC is geolocalization, which is formulated as image classification. CLOC has significant scale (39 million images taken over more than 8 years) compared to other benchmarks. Due to the large scale and natural distribution shifts, we use CLOC as the main dataset to study OCL.

\section{Method}\label{sec:method}

We consider replay-based methods, where the common choice for continual learning is mixed replay~\citep{chaudhry2019tiny}. The objective of mixed replay at time step $t$ is
\begin{align}\label{eq:mixRep}
\underset{{\bm\theta} \in \mathbb{R}^d}{\text{minimize}} \ \ \ \  l(\{\mathbf{X}_t, \mathbf{Y}_t\}, {\bm\theta}) + l(\mathbf{S}_{t-1}, {\bm\theta}),
\end{align}
where $\{\mathbf{X}_t, \mathbf{Y}_t\}$ is the data received at time $t$, $\mathbf{S}_{t-1}$ is the historical data accumulated in the replay buffer, and $l(\cdot, {\bm\theta})$ is the loss function. Mixed replay constructs a minibatch of training data by sampling half from the current time step $t$ and another half from the history (from $t-B_t$ to $t-1$ where $B_t$ decides the time range). In offline continual learning~\citep{chaudhry2019tiny}, $B_t$ is set to $t-1$ for full coverage.~\citet{cai2021online} adaptively choose $B_t$ to optimize learning efficacy in OCL.

In this paper, we focus on information retention, more specifically its optimization. A reasonable objective for pure information retention is \emph{pure replay}, which is defined as follows at each time step $t$:
\begin{align}\label{eq:pureRep}
 \underset{{\bm\theta}\in \mathbb{R}^d}{\text{minimize}} \ \ \ \  l(\mathbf{S}_{t}, {\bm\theta}).
\end{align}
Pure replay constructs a minibatch of training data by sampling uniformly from all historical time steps, i.e., from $1$ to $t$, which encourages remembering  all historical knowledge.
As shown in Appx.~\ref{sec:exp_obj}, optimizing \eqref{eq:pureRep} (as opposed to \eqref{eq:mixRep}) improves both information retention and forward transfer by sacrificing learning efficacy.

\vspace{-0.5em}
\subsection{Optimizing Information Retention}\label{sec:SGD}
\vspace{-0.5em}

When the distribution of $\mathbf{S}_t$ remains unchanged over time (i.e., the loss function is stationary), the standard optimizer for problem~\eqref{eq:pureRep} is Stochastic Gradient Descent (SGD). This choice is typically carried over to continual learning. At each update iteration $k$ ($k\ne t$ if multiple updates are allowed at each time step of continual learning), SGD updates the model via
\begin{align}\label{eq:SGD}
	{\bm\theta}_k \leftarrow {\bm\theta}_{k-1} - \alpha_{k}g_k({\bm\theta}_{k-1}),
\end{align}
where $\alpha_{k}$ is the learning rate and $g_k({\bm\theta}_{k-1})$ is the stochastic gradient of the objective at iteration $k$.

Although the convergence behavior of SGD is well understood for the case of stationary losses, its implications for OCL are not clear. Hence, we extend the analysis of SGD \citep{ghadimi2013stochastic} to the continual learning case. Denote  the loss function at iteration $k$ by $l_k({\bm\theta})$ and assume:
\begin{enumerate}[label = \textbf{A\arabic*},itemsep=1mm]
	\vspace{-0.5em}
	\item \label{A1} $\norm{\triangledown l_{k}({\bm\theta}) - \triangledown l_{k}({\bm\theta}')} \le L\norm{{\bm\theta} - {\bm\theta}'}, \forall {\bm\theta}, {\bm\theta}' \in \mathbb{R}^d$ and $k$ (Lipschitz smoothness).
	\item \label{A2} $\mathbb{E}[g_k({\bm\theta})] = \triangledown l_k({\bm\theta}), \forall {\bm\theta}\in \mathbb{R}^d$ and $k$ (Unbiased gradient estimates).
	\item \label{A3} $\norm{\triangledown l_k({\bm\theta}) - g_k({\bm\theta})}^2 \le \rho^2, \forall {\bm\theta} \in \mathbb{R}^d$ (Bounded gradient noise). 
	\item\label{A4} $|l_{k+1}({\bm\theta}) - l_{k}({\bm\theta})| \le \chi_{k}, \forall {\bm\theta}$ and $k$ (Bounded non-stationarity).
\end{enumerate}

\ref{A1} to~\ref{A3} extend the standard assumptions for SGD analysis~\citep{ghadimi2013stochastic} from the stationary case to the non-stationary case. And \ref{A4} bounds the degree of non-stationarity between consecutive iterations. The expectations are taken over the randomness of the stochastic gradient noise. With these assumptions, we state the following theorem and defer its proof to Appx.~\ref{appdx:SGD_Convergence_OCL} (also see Appx.~\ref{appdx:SGD_Convergence_OCL} for details about how to interpret this result under limited storage):


\begin{theorem}\label{theory:SGD_OCL}
	 Assume~\ref{A1} to~\ref{A4}, and let $\alpha_{k} < \frac{L}{2}$,
	\vspace{-0.5em}
	\begin{align}\label{theorem_eq:SGD_OCL_main}
	\min_{j \in \{0,1,..., k\}} \mathbb{E} [\norm{\triangledown l_{j+1}({\bm\theta}_{j})}^2] \le T_1 + T_2 + T_3,
	\end{align}
	where $T_1 = \frac{2 (l_1({\bm\theta}_0) - \mathbb{E} [l_{k+2}({\bm\theta}_{k+1})])}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)}$, $T_2 = \frac{L\rho^2 \sum_{j=0}^{k} \alpha_{j+1}^2}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)}$, and $T_3 = \frac{2\sum_{j=0}^{k} \chi_{j+1}}{\sum_{j=0}^{k} (2\alpha_{j+1} - L\alpha_{j+1}^2)}.$
	\vspace{-.5em}
\end{theorem}

Therorem~\ref{theory:SGD_OCL} bounds the minimum gradient norm achievable by SGD during OCL. A similar bound in the stationary case (Theorem~\ref{theory:SGD_SL} in Appx.~\ref{appdx:SGD_Convergence_SL}) has only the terms $T_1$ and $T_2$. Hence,  $T_3$ is the cost of the non-stationarity. In the stationary case (when $T_3 = 0$), we can simply find the optimal learning rate by trading off between $T_1$ and $T_2$. Specifically, for a constant learning rate, $T_1$ converges to $0$ at a linear rate, but $T_2$ is constant. Hence, the strategy for convergence is reducing learning rates to control $T_2$ simultaneously with $T_1$. This result supports the effectiveness of the standard ``\emph{reduce-when-plateau}" (RWP) learning rate heuristic in the stationary case. Since the access to the true gradient norm is not practical, RWP often uses the validation accuracy/loss as a surrogate to control the learning rate $\alpha_k$, where we reduce $\alpha_k$ by a certain factor $\beta$ once the validation accuracy/loss plateaus~\citep{goodfellow2016deep, he2016deep}.

In the continual learning setting (when $T_3 \neq 0$), RWP can be less effective. For example, if $\chi_k \ge \chi > 0$ for a constant $\chi$, i.e., the loss function $l_{k}(\cdot)$ changes at least at a linear rate, then $T_3$ can grow linearly when the learning rate is reduced to 0. Hence in OCL, there can be cases where simultaneous convergence of $T_1,T_2,$ and $T_3$ are not possible. Controlling $T_3$ requires a reasonably large learning rate, whereas using a large learning rate increases $T_2$. Finally, the $\chi_k$ term can cause the learning rate annealing signal in RWP, i.e., the gradient norm or the validation loss/accuracy, to be unstable in OCL. We argue that these are the core obstacles in application of SGD to OCL. 

In summary, the major issues hindering the performance of OCL when optimized with SGD are:

\begin{enumerate}[label = \textbf{P\arabic*}, itemsep=1mm]
\vspace{-0.5em}
	\item\label{P3} OCL needs large learning rates due to non-stationarity. However, convergence requires smaller learning rates.
	\item \label{P2} RWP allows the learning rate to be infinitesimal, which prevents                   the model from adapting to new data.
	\item \label{P1} The validation performance is not always indicative of learning. E.g., due to the distribution shift of OCL, the validation accuracy can decrease, even when the model is still improving.
 \vspace{-0.5em}
\end{enumerate}

To address~\ref{P3}, we propose an Adaptive Moving Average (AMA) optimizer in Sec.~\ref{sec:AMA}. Then, to address~\ref{P2} and~\ref{P1}, we introduce a moving-average-based learning rate (MALR) schedule in Sec.~\ref{sec:MALR}.













\subsection{Adaptive Moving Average}\label{sec:AMA}

Our Adaptive Moving Average (AMA) optimizer extends Exponential Moving Average (EMA)~\citep{tarvainen2017mean}. Moving average optimizers maintain two models: the SGD model ${\bm\theta}_k$ and the MA model ${\bm\theta}^{MA}_k$. At each iteration $k$, ${\bm\theta}_k$ is first updated with \eqref{eq:SGD}. Then, ${\bm\theta}^{MA}_k$ is updated via

\vspace{-1.5em}
	\begin{align}\label{eq:MA}
	{\bm\theta}^{MA}_k \leftarrow \gamma_k {\bm\theta}^{MA}_{k-1} + (1-\gamma_k) {\bm\theta}_k,
\end{align}
\vspace{-1.5em}

where the MA weight $\gamma_k \in [0,1]$ is a hyperparameter. In EMA, $\gamma_k$ is a constant. In AMA, we adapt $\gamma_k$ over time using population-based search~\citep{jaderberg2017population} to improve the performance.

\noindent \textbf{Why does AMA help information retention?}\label{sec:AMA_reason}
Given stationary losses, SGD can converge to local optima by reducing the learning rate. In this case, the final solution found by AMA will not be very different from SGD as we validate in Appx.~\ref{appdx:SL}. In the non-stationary case, SGD needs reasonably large learning rates to track the shifting optimum over time. However, the variance ($T_2$ in~\eqref{theorem_eq:SGD_OCL_main}) of SGD increases with large learning rates, hurting convergence.


The advantage of AMA is to reduce the variance of SGD. Given stationary losses, \citet{mandt2016variational} have shown that SGD with a constant learning rate will eventually bounce around a region centered at the optimum. Averaging the SGD trajectory with uniform weights estimates the region center, i.e., the optimal solution. This observation inspires the design of AMA. Informally, SGD with large learning rates would follow and bounce around the \emph{shifting} optimum in OCL. The moving average of these high-variance iterates tracks the shifting optimum better. As a further informal justification, consider the unfolded AMA update rule~\eqref{eq:MA}:

\vspace{-2em}
\begin{align}\label{eq:MA_unfold}
{\bm\theta}^{MA}_k = \left(1-\gamma_k\right) {\bm\theta}_k + \sum_{i=1}^{k-1} \left(1-\gamma_{i}\right) \left(\prod_{j=i+1}^{k}\gamma_{j}\right) {\bm\theta}_{i} + \left(\prod_{j=1}^{k}\gamma_{j}\right) {\bm\theta}_{0},
\end{align}

\vspace{-1em}
where $\theta_0$ is the initial solution of SGD and AMA.~\eqref{eq:MA_unfold} shows that the AMA model ${\bm\theta}^{MA}_{k}$ is a linear combination of the SGD trajectory $\{{\bm\theta}_{0}, ... ,{\bm\theta}_{k}\}$.  Since $\gamma_{k} \in [0,1]$, ${\bm\theta}^{MA}_{k}$ lies inside the convex hull of $\{{\bm\theta}_{0}, ... ,{\bm\theta}_{k}\}$. The population-based search aims to find the best point within the convex hull by adapting $\gamma_k$.

We summarize our method in Alg.~\ref{alg:AMA}. To adapt $\gamma_k$ over time, we maintain two MA models, ${\bm\theta}^{MA_1}$ and ${\bm\theta}^{MA_2}$, and update them using different weights, $\gamma^{MA_1}$ and $\gamma^{MA_2}$ (Line~\ref{alg1:UpdateMA}). To decide the best model and weight, we use the validation accuracy $Acc_1$ and $Acc_2$ (Line~\ref{alg1:Val}), which we define next.
Once every $K_W$ iterations, we copy the parameter of the best MA model to the other one, and adapt the MA weights (Line~\ref{alg1:MainUpdateWStart} to~\ref{alg1:MainUpdateWEnd}). In all our experiments, we set the initial MA weight $\gamma_{0}$ to 0.99, the MA weight adjustment coefficient $\delta$ to 5, and the interval $K_W$ to adjust weights to 10000 iterations. 


We continuously track a validation metric for adaptation. At each time step $t$, a holdout \emph{information retention validation set} $\mathbf{S}_t^V$ is updated,  which has the same distribution as $\mathbf{S}_t$. To maintain $\mathbf{S}_t^V$ online, whenever new data $\{\mathbf{X}_t, \mathbf{Y}_t\}$ is received, we put a random subset ($5\%$ in all experiments) into $\mathbf{S}^V_t$ and put the rest into $\mathbf{S}_t$. We compute the \emph{information retention validation accuracy/loss} on $\mathbf{S}_t^V$ in an online fashion (described in Appx.~\ref{appdx:AMA_complete}). In this way, we can parallelize validation with model updates, and choose the best MA model for inference anytime during OCL. We use the information retention validation accuracy/loss both in Algorithm~\ref{alg:AMA} and later for learning rate control.

\begin{algorithm}[t]
	\begin{algorithmic}[1]
		\Require Initial model ${\bm\theta}_0$, initial moving average weight $\gamma_{0}$, MA weight adjustment coefficient $\delta (>0)$, MA weight update interval $K_W$.
		\State  ${\bm\theta}^{MA_1} \leftarrow {\bm\theta}_0, {\bm\theta}^{MA_2} \leftarrow {\bm\theta}_0 , \gamma^{MA_1} \leftarrow \gamma_0, \gamma^{MA_2} \leftarrow \frac{\gamma_0}{\delta}$, $Acc_1 \leftarrow 0, Acc_2 \leftarrow 0, i_{best} \leftarrow 1$
		\For {$k \in \{1,2,3,...,\infty\}$}
		\State Update the SGD model ${\bm\theta}_{k}$
		\State\label{alg1:UpdateMA}Update ${\bm\theta}^{MA_1}$ using $\gamma^{MA_1}$ and ${\bm\theta}^{MA_2}$ using $\gamma^{MA_2}$
		\State\label{alg1:Val} Update validation accuracy $Acc_1$ and $Acc_2$ online
	
	
	
	
	
	
	
	
	
		\State \bf{If} $Acc_1 > Acc_2$ then $i_{best} = 1$  \bf{else} $i_{best} = 2$
	
		\If {$k \mod K_W = 0$}\label{alg1:MainUpdateWStart}
		\State\label{alg1:resetn} \textnormal{Copy the weights of ${\bm\theta}^{MA_{i_{best}}}$ to the other. $Acc_1 \leftarrow 0, Acc_2 \leftarrow 0$. 
		\State Increase $\gamma^{MA_1} \& \gamma^{MA_2}$ by a factor of $\delta$ if $i_{best}$ = 1, and decrease otherwise.}
		\EndIf\label{alg1:MainUpdateWEnd}
		\EndFor
	\end{algorithmic}
	\caption{Adaptive Moving Average (AMA)}\label{alg:AMA}
\end{algorithm}













We propose several strategies to reduce the overhead of MA and population-based search. The overhead from MA lies in 1) updating the MA model and 2) recomputing the batch normalization (BN) statistics~\citep{ioffe2015batch}. To solve 1, we perform the MA update only every $K_M$ iterations. We set $K_M = 10$ in all experiments and do not observe a performance drop. To solve 2, we replace BN with group normalization (GN) + weight standardization (WS)~\citep{qiao2019micro}, which does not store normalization statistics. We evaluate its impact in Appx.~\ref{appdx:BN}. The overhead from population-based search lies in the online validation operation (Line~\ref{alg1:Val}). Each operation requires one forward pass on a batch of validation data. To reduce the overhead, we execute Line~\ref{alg1:Val} every $K_V = 20$ iterations. See Appx.~\ref{appdx:AMA_complete} for a detailed version of Algorithm~\ref{alg:AMA} with the above strategies.








\subsection{Moving-Average-based Learning Rate Schedule (MALR)}\label{sec:MALR}
As discussed in~(\ref{P1}), monitoring only the validation accuracy is not sufficient for learning rate control as the effects of learning and distribution shifts counteract each other. Interestingly, AMA provides a better signal for learning rate control as a by-product. Specifically, we use the difference between \emph{information retention validation loss/accuracy} of the MA model ${\bm\theta}^{MA_{i_{best}}}$ and the SGD model ${\bm\theta}_k$. We denote this difference at iteration $k$ by $\sigma_k$. Intuitively, since AMA performs better than SGD given non-minimal learning rates, $\sigma_k$ can be used to estimate the performance gain obtainable by learning rate reduction. To control the learning rate reduction speed, we do not reduce learning rates unless $\sigma_k$ plateaus, indicating that we cannot achieve better long-term performance gain. On the other hand, when the learning rate is too small, potentially incapable of adapting to new data, $\sigma_k$ will also be very small. Hence, we do not reduce the learning rate unless $\sigma_k$ exceeds a certain threshold.



In summary, MALR reduces the learning rate when the following conditions are satisfied. \labelText{\textbf{C1}}{C1}: The information retention validation performance (of the MA model) does not improve for $K_R$ iterations. (This is the original RWP condition.) \labelText{\textbf{C2}}{C2}: $\sigma_k$ does not increase for $K_R$ iterations. \labelText{\textbf{C3}}{C3}: $\sigma_k > \epsilon$.

\noindent\textbf{Computational complexity.} The average computational complexity of SGD+RWP per iteration is $c_{\text{SGD}+\text{RWP}} = (\frac{K_V+1}{K_V}) c_F+c_G+c_U$, where $c_F$ is the complexity of one forward pass, $K_V$ is the interval to do one online validation step, $c_G$ and $c_U$ are respectively the complexity for computing the gradient and updating the model. The complexity of AMA+MALR is $c_{\text{AMA}+\text{MALR}} = (\frac{K_V+3}{K_V}) c_F+ c_G+(\frac{K_M+2}{K_M}) c_U$, where $K_M$ is the interval to do one MA update step. When $K_V$ and $K_M$ are large, the overhead of AMA+MALR is small. 



\section{Preliminaries}\label{sec:problem}
In this section, we formalize the online continual learning problem and introduce our notation. We then discuss the dataset and the metrics we use.

\noindent \textbf{Problem definition.} Given the input domain $\mathcal{X}$ and the label space $\mathcal{Y}$, online continual learning learns a parametric function $f(\cdot|{\bm\theta}): \mathcal{X} \rightarrow \mathcal{Y}$ that maps an input $\mathbf{x} \in \mathcal{X}$ to the corresponding label $\mathbf{y} \in \mathcal{Y}$. At each time step $t \in \{1,2, ..., \infty\}$ the learner interacts with the environment as follows:
\begin{enumerate}[itemsep=1mm]
	\vspace{-0.5em}
	\item The environment samples the data $\{\mathbf{X}_t, \mathbf{Y}_t\} \sim \pi_t$ and reveals the inputs $\mathbf{X}_t$ to the learner.
	\item \label{OCLDef:Step2} The learner predicts the label for each datum $\mathbf{x}_t^{i_t} \in \mathbf{X}_t$ via $\hat{\mathbf{y}}_t^{i_t} = f(\mathbf{x}_t^{i_t}|{\bm\theta}_{t-1})$.
	\item The environment reveals the true labels $\mathbf{Y}_t$ and the learner integrates $\{\mathbf{X}_t, \mathbf{Y}_t\}$ into the data pool $\mathbf{S}_t$ via $\mathbf{S}_t = \textup{update}(\mathbf{S}_{t-1}, \{\mathbf{X}_t, \mathbf{Y}_t\})$.
	\item The learner updates the model ${\bm\theta}_t$ using $\mathbf{S}_t$.
	\vspace{-0.5em}
\end{enumerate}


\noindent \textbf{Dataset.} Due to the large scale, the smooth data stream, and natural distribution shifts, we mainly use the Continual Localization (CLOC) benchmark~\citep{cai2021online} to study OCL. CLOC formulates image geolocalization as a classification problem. It contains 39 million labeled images for training, 39 thousand images for performance evaluation, and another 2 million images for initial hyperparameter tuning. The images are ordered according to their time stamps, so that images taken earlier are seen by the model first. Images for training and performance evaluation cover the same time span and are sampled uniformly over time. Images for hyperparameter tuning are from a different time span that does not overlap with the training and evaluation data. We refer to the 39 million training images as the \emph{training data}, the 39 thousand evaluation images as the \emph{evaluation data}, and the 2 million images for initial hyperparameter tuning as the \emph{preprocessing data}.

\noindent \textbf{Evaluation protocol.} We evaluate OCL algorithms using the following metrics.

\emph{Learning Efficacy:} For online learning applications, the model ${\bm\theta}_t$ is deployed for inference on data from the next time step, i.e., $\mathbf{X}_{t+1}$. In this case, we measure the ability to adapt to new data as
{\small
\begin{align}\label{eq:metric_LE}
P_{LE}(t) = \frac{1}{t}\sum_{j=1}^{t}\texttt{acc}(\{\mathbf{X}_{j+1}, \mathbf{Y}_{j+1} \}, {\bm\theta}_j), 
\end{align}
}
where $\texttt{acc}(\mathbf{S}, {\bm\theta})$ is the average accuracy of the model ${\bm\theta}$ on a set of data $\mathbf{S}$.

\emph{Information Retention:} When the data for inference comes from the history, we measure the ability to retain previous knowledge as
{\small
\begin{align}\label{eq:metric_IR}
P_{IR}(t) = \texttt{acc}\Big(\Big\{\bigcup\limits_{j=1}^{t} \mathbf{X}^{E}_{j}, \bigcup\limits_{j=1}^{t} \mathbf{Y}^{E}_j\Big\}, {\bm\theta}_t\Big), 
\end{align}
}
where $\{\mathbf{X}^E_j, \mathbf{Y}^E_j\}$ is the evaluation data from time step $j$, which has the same distribution as $\{\mathbf{X}_j, \mathbf{Y}_j\}$ but unseen by the model. $P_{IR}(t)$ measures the generalization of ${\bm\theta}_t$ to historical data.

\emph{Forward Transfer:} When long-term predictions are required, we measure ability to generalize from current time ($t$) to future time steps ($t+k_1$ to $t+k_2$, $k_2 > k_1 \ge 1$) as
{\small
\begin{align}\label{eq:metric_FT}
P_{FT}(t) = \texttt{acc}\Big(\Big\{\bigcup\limits_{j=t+k_1}^{t+k_2} \mathbf{X}^{E}_{j}, \bigcup\limits_{j=t+k_1}^{t+k_2} \mathbf{Y}^{E}_j\Big\}, {\bm\theta}_t\Big).
\end{align}
}

