<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://optimization.cbe.cornell.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fall2024+Wiki+Team6</id>
	<title>Cornell University Computational Optimization Open Textbook - Optimization Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://optimization.cbe.cornell.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fall2024+Wiki+Team6"/>
	<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Special:Contributions/Fall2024_Wiki_Team6"/>
	<updated>2026-04-26T06:55:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7705</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7705"/>
		<updated>2024-12-16T02:46:28Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
=== Problem setup ===&lt;br /&gt;
&#039;&#039;&#039;Minimize the loss function:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(X) = \frac{1}{2}\sum_{i,j}(X_{ij}-C_{ij})^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Target matrix (&amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;)：&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C = \begin{bmatrix} 0.4 &amp;amp; -0.3 &amp;amp;0.5 \\ -0.6 &amp;amp; 0.2&amp;amp;-1.5\\1.0&amp;amp;-0.3&amp;amp;0.1 \end{bmatrix}&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Hyperparameters setup ===&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
=== Step 1:  Learning Rate Scaling ===&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.7^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compute the element-wise (Square of Gradient) ===&lt;br /&gt;
&#039;&#039;&#039;Step 2.1: Compute the gradient of the loss function&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t =     {\partial f(X)\over\partial X} = X_{t-1} - C&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Subtract C from &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix} - \begin{bmatrix} 0.4 &amp;amp; -0.3 &amp;amp;0.5 \\ -0.6 &amp;amp; 0.2&amp;amp;-1.5\\1.0&amp;amp;-0.3&amp;amp;0.1 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2.2: Compute the squared value of each element in the gradient matrix &amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Find the moment estimate ===&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Update the vector ===&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Weight Update ===&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software Tools and Platforms ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Future Prospects ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7704</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7704"/>
		<updated>2024-12-16T02:43:31Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Step 2: Compute                                    G                        t                                   2                                     {\displaystyle G_{t}^{2}}    ​ (Element-wise Square of Gradient) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
=== Problem setup ===&lt;br /&gt;
&#039;&#039;&#039;Minimize the loss function:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(X) = \frac{1}{2}\sum_{i,j}(X_{ij}-C_{ij})^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Target matrix (&amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;)：&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C = \begin{bmatrix} 0.4 &amp;amp; -0.3 &amp;amp;0.5 \\ -0.6 &amp;amp; 0.2&amp;amp;-1.5\\1.0&amp;amp;-0.3&amp;amp;0.1 \end{bmatrix}&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Hyperparameters setup ===&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
=== Step 1:  Learning Rate Scaling ===&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.7^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compute the element-wise (Square of Gradient) ===&lt;br /&gt;
&#039;&#039;&#039;Step 2.1: Compute the gradient of the loss function&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t =     {\partial f(X)\over\partial X} = X_{t-1} - C&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Subtract C from &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix} - \begin{bmatrix} 0.4 &amp;amp; -0.3 &amp;amp;0.5 \\ -0.6 &amp;amp; 0.2&amp;amp;-1.5\\1.0&amp;amp;-0.3&amp;amp;0.1 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2.2: Compute the squared value of each element in the gradient matrix &amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Find the moment estimate ===&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Update the vector ===&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Weight Update ===&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7686</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7686"/>
		<updated>2024-12-16T02:02:27Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Problem setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
=== Problem setup ===&lt;br /&gt;
&#039;&#039;&#039;Minimize the loss function:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(X) = \frac{1}{2}\sum_{i,j}(X_{ij}-C_{ij})^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Target matrix (&amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;)：&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C = \begin{bmatrix} 0.4 &amp;amp; -0.3 &amp;amp;0.5 \\ -0.6 &amp;amp; 0.2&amp;amp;-1.5\\1.0&amp;amp;-0.3&amp;amp;0.1 \end{bmatrix}&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Hyperparameters setup ===&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
=== Step 1:  Learning Rate Scaling ===&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.7^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient) ===&lt;br /&gt;
&#039;&#039;&#039;Step 2.1: Compute the gradient of the loss function&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t =     {\partial f(X)\over\partial X} = X_{t-1} - C&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Subtract C from &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix} - \begin{bmatrix} 0.4 &amp;amp; -0.3 &amp;amp;0.5 \\ -0.6 &amp;amp; 0.2&amp;amp;-1.5\\1.0&amp;amp;-0.3&amp;amp;0.1 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2.2: Compute the squared value of each element in the gradient matrix &amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Find the moment estimate ===&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Weight Update (&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7462</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7462"/>
		<updated>2024-12-15T03:12:42Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
=== Problem setup ===&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hyperparameters setup ===&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
=== Step 1:  Learning Rate Scaling ===&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.7^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient) ===&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Find the moment estimate ===&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Weight Update (&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7456</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7456"/>
		<updated>2024-12-15T03:06:59Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
=== Problem setup ===&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hyperparameters setup ===&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
=== Step 1:  Learning Rate Scaling ===&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient) ===&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Find the moment estimate ===&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Weight Update (&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7453</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7453"/>
		<updated>2024-12-15T03:04:30Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
=== Problem setup ===&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hyperparameters setup ===&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
=== Step 1:  Learning Rate Scaling ===&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient) ===&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Find the moment estimate ===&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;) ===&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039; ===&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7442</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7442"/>
		<updated>2024-12-15T02:43:25Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7287</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7287"/>
		<updated>2024-12-13T21:54:00Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Software Tools and Platforms */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ====&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ====&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7286</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7286"/>
		<updated>2024-12-13T21:51:26Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Adafactor addresses the memory consumption challenge of training large-scale deep learning models. By factorizing the second-order moment matrix and dynamically adjusting the learning rate, Adafactor minimizes resource usage without compromising performance. Adafactor can be applied to the training tasks of large language models such as Transformers, T5 models, and Vision Transformers.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
# Shazeer, Noam, and Mitchell Stern. &amp;quot;Adafactor: Adaptive learning rates with sublinear memory cost.&amp;quot; &#039;&#039;International Conference on Machine Learning&#039;&#039;. PMLR, 2018.&lt;br /&gt;
# Raffel, Colin, et al. &amp;quot;Exploring the limits of transfer learning with a unified text-to-text transformer.&amp;quot; &#039;&#039;Journal of machine learning research&#039;&#039; 21.140 (2020): 1-67.&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# Chauhan, Tavishee, and Hemant Palivela. &amp;quot;The Fine tuning of Language models for automation of Humor Detection.&amp;quot; &#039;&#039;INFOCOMP Journal of Computer Science&#039;&#039; 20.2 (2021).&lt;br /&gt;
# Lepikhin, Dmitry, et al. &amp;quot;Gshard: Scaling giant models with conditional computation and automatic sharding.&amp;quot; &#039;&#039;arXiv preprint arXiv:2006.16668&#039;&#039; (2020).&lt;br /&gt;
# DIAGONALIZATION, VIA PRECONDITIONER. &amp;quot;Improving Adaptive Moment Optimization via Preconditioner Diagonalization.&amp;quot;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adafactor&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://pytorch.org/docs/stable/generated/torch.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# &amp;lt;nowiki&amp;gt;https://flax.readthedocs.io/en/v0.5.3/_autosummary/flax.optim.Adafactor.html&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7282</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7282"/>
		<updated>2024-12-13T21:48:11Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Applications */ change tensorflow&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7027</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7027"/>
		<updated>2024-12-12T16:58:34Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Proposed Hyperparameters for Adafactor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
**Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;&lt;br /&gt;
**A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
**The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
**The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
**The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7026</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7026"/>
		<updated>2024-12-12T16:57:48Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* 4. Proposed Hyperparameters for Adafactor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-30}&amp;lt;/math&amp;gt;  &lt;br /&gt;
  Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (&amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;10^{-3}&amp;lt;/math&amp;gt;  &lt;br /&gt;
  Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (&amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt;  &lt;br /&gt;
  A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (&amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;\min(10^{-2}, 1 / \sqrt{t})&amp;lt;/math&amp;gt;  &lt;br /&gt;
  - The &amp;lt;math&amp;gt;\min(10^{-2}, ...)&amp;lt;/math&amp;gt; term caps the learning rate at &amp;lt;math&amp;gt;10^{-2}&amp;lt;/math&amp;gt;, an empirically determined upper bound.  &lt;br /&gt;
  - The &amp;lt;math&amp;gt;1 / \sqrt{t}&amp;lt;/math&amp;gt; term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;):&#039;&#039;&#039; &amp;lt;math&amp;gt;1 - t^{-0.8}&amp;lt;/math&amp;gt;  &lt;br /&gt;
  - The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
  - The &amp;lt;math&amp;gt;t^{-0.8}&amp;lt;/math&amp;gt; power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7025</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7025"/>
		<updated>2024-12-12T16:56:10Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* 4. Proposed Hyperparameters for Adafactor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1 (\(\epsilon_1\)):&#039;&#039;&#039; \(10^{-30}\)  &lt;br /&gt;
  Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates. This value is set extremely low to avoid instability in calculations.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2 (\(\epsilon_2\)):&#039;&#039;&#039; \(10^{-3}\)  &lt;br /&gt;
  Helps stabilize parameter updates by controlling the scaling effect of second-moments in low-magnitude scenarios. This prevents instability caused by noise in small gradients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold (\(d\)):&#039;&#039;&#039; \(1\)  &lt;br /&gt;
  A clipping threshold of 1 ensures stability by limiting large gradient values while maintaining sufficient learning efficiency. This avoids excessive suppression of large gradients, which could hinder learning.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Relative step size (\(\rho_t\)):&#039;&#039;&#039; \(\min(10^{-2}, 1 / \sqrt{t})\)  &lt;br /&gt;
  - The \(\min(10^{-2}, ...)\) term caps the learning rate at \(10^{-2}\), an empirically determined upper bound.  &lt;br /&gt;
  - The \(1 / \sqrt{t}\) term ensures convergence by reducing the step size over time, balancing exploration during early iterations with stability later in training.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay (\(\hat{\beta}_{2t}\)):&#039;&#039;&#039; \(1 - t^{-0.8}\)  &lt;br /&gt;
  - The decay factor remains close to 1 initially to allow rapid adaptation.  &lt;br /&gt;
  - The \(t^{-0.8}\) power balances between rapid learning in early training and stability during later stages, ensuring smoother convergence.&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7024</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7024"/>
		<updated>2024-12-12T16:54:25Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Problem formulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 5. Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7023</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7023"/>
		<updated>2024-12-12T16:53:01Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: Undo revision 6932 by Fall2024 Wiki Team6 (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== Why Clipping ===&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7022</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=7022"/>
		<updated>2024-12-12T16:49:42Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: Undo revision 6933 by Fall2024 Wiki Team6 (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6988</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6988"/>
		<updated>2024-12-12T01:07:02Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Multilingual Model Training&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In training multilingual models, Adafactor improved scalability and efficiency, particularly by significantly reducing memory consumption when handling large-scale parameters.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Pretraining Vision Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When training ResNet50 and ViT on the ImageNet1k dataset, Adafactor successfully optimized these deep networks with its low memory requirements. Additionally, with new algorithms combining preconditioned diagonalization methods (e.g., AdafacDiag and AdafacDiag++), it outperformed the standard Adam optimizer in both convergence speed and final accuracy.&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Software Tools and Platforms&#039;&#039;&#039; ===&lt;br /&gt;
Adafactor has been integrated into the following mainstream deep learning frameworks, making it accessible to developers:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TensorFlow&#039;&#039;&#039;: Provides a built-in implementation of Adafactor, supporting T5 model optimization.&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PyTorch:&#039;&#039;&#039; PyTorch provides the Adafactor optimizer through the torch.optim.AdaFactor class.&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;JAX/Flax:&#039;&#039;&#039; JAX provides an optimizer library called Optax, which includes the Adafactor optimizer.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Future Prospects&#039;&#039;&#039; ===&lt;br /&gt;
As the scale of deep learning models continues to grow, Adafactor’s memory-saving and computational efficiency advantages will become increasingly important. In the training of ultra-large-scale models (e.g., GPT and Vision Transformers), Adafactor is expected to become an indispensable optimization tool. Furthermore, by combining with other optimization strategies, such as mixed precision training, Adafactor may further enhance its applicability in both industrial and research settings.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6987</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6987"/>
		<updated>2024-12-12T01:02:47Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
Adafactor is an efficient adaptive optimizer designed specifically for large-scale deep learning tasks. Its unique memory-saving properties have made it widely used for training large-scale language models, image recognition models, and reinforcement learning policy networks. Compared to other optimizers (e.g., Adam), Adafactor delivers exceptional performance in large-scale computations while significantly reducing memory requirements. Below are several specific application scenarios of Adafactor:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Natural Language Processing (NLP)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In NLP tasks, Adafactor has been successfully applied to training ultra-large-scale language models, such as Google’s Transformer and T5 (Text-To-Text Transfer Transformer). By significantly reducing memory usage during the gradient update process, Adafactor enables efficient model training in resource-constrained environments. For example, the T5 model in Google’s research employed Adafactor to effectively train on large datasets through text-to-text conversion tasks.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Training Large-Scale Language Models&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been used to train large-scale language models like LLaMA, combining it with novel preconditioned diagonalization methods to significantly enhance training efficiency. Experiments showed that Adafactor achieved performance comparable to the Adam optimizer while consuming substantially less memory and computational resources.&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Humor Detection Tasks&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adafactor has been utilized to optimize ALBERT-based models for humor detection tasks. Configured as an adaptive learning rate optimizer and paired with a cross-entropy loss function, Adafactor was used to train models that achieved 99% accuracy and F1 scores. Moreover, training time was faster than with Adam, completing in approximately 43 minutes. Comparisons with Adam and AdaBound optimizers demonstrated that Adafactor excelled in terms of both time efficiency and performance, especially in accuracy, recall, and F1 scores for humor detection tasks .&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6985</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6985"/>
		<updated>2024-12-12T00:51:19Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern from Google Research in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP).&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6984</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6984"/>
		<updated>2024-12-12T00:49:58Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Adafactor is an efficient, adaptive learning rate optimization algorithm proposed by Noam Shazeer and Mitchell Stern from Google Research in 2018. &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike traditional Adam optimizers, Adafactor does not store complete second-order moment matrices. Instead, it employs a factorization approach that only maintains gradient statistics for the rows and columns of parameter matrices, significantly reducing memory usage. Moreover, Adafactor uses an adaptive learning rate, allowing it to dynamically adjust step sizes without the need for manually setting a global learning rate or relying heavily on hyperparameter tuning. Its design also defaults to not performing bias correction, yet it remains stable in scenarios involving large-batch training data.[1] This efficiency makes it an ideal choice for training ultra-large-scale models such as T5.&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adafactor’s efficient memory usage and outstanding performance make it widely applicable in scenarios such as Natural Language Processing (NLP). Compared to the Adam optimizer, Adafactor significantly reduces memory and computational resource requirements while maintaining comparable performance when training large-scale language models and vision models. &amp;lt;sup&amp;gt;3,6&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6974</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6974"/>
		<updated>2024-12-11T22:02:12Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6972</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6972"/>
		<updated>2024-12-11T21:57:54Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient for first iteration (​&amp;lt;math&amp;gt;G_1&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_1 = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\sum_{i=1}^n  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_1 = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_1[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Scale the update vector ( &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ ) to ensure its RMS value does not exceed a predefined clipping threshold (&amp;lt;math&amp;gt;d &amp;lt;/math&amp;gt;), maintaining stability in updates.&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_1} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 5: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Adjust the weights (&amp;lt;math&amp;gt;X_t &amp;lt;/math&amp;gt;) by subtracting the product of the learning rate (&amp;lt;math&amp;gt;\alpha_t &amp;lt;/math&amp;gt;) and the clipped update vector (&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6970</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6970"/>
		<updated>2024-12-11T21:44:05Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial gradient (​&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\textstyle \sum_{i=1}^n\displaystyle  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\sum_{j=1}^m G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\sum_{j=1}^n G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Computed by scaling the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​ element-wise with the inverse square root of the second moment estimate (&amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt;​)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V_t}+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_1)   = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_t} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6969</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6969"/>
		<updated>2024-12-11T21:23:34Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial gradient (​&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\textstyle \sum_{i=1}^n\displaystyle  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the squared value of each element in the gradient matrix &#039;&#039;&#039;&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Compute the exponential moving average of squared gradients to capture the variance or scale of gradients.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we can ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\textstyle \sum_{j=1}^n \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1   = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{V}_1       =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{V_t+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compute RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_t) = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_t} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = X_0 - \alpha \cdot      \hat{U_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result for first iteration&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}  - 0.00806 \cdot      \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_1 =   \begin{bmatrix} 0.692&amp;amp;-0.496&amp;amp;0.887 \\-1.091&amp;amp;0.791&amp;amp;-0.596\\ 1.195&amp;amp;-0.691&amp;amp;0.391\end{bmatrix}       &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6955</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6955"/>
		<updated>2024-12-11T17:10:11Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial gradient (​&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\textstyle \sum_{i=1}^n\displaystyle  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Square the gradient value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_1&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\textstyle \sum_{j=1}^n \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{V_t+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_t) = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_t} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6940</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6940"/>
		<updated>2024-12-11T07:00:35Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial gradient (​&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\textstyle \sum_{i=1}^n\displaystyle  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Square the gradient value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_1&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The process is same as row moments&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\textstyle \sum_{j=1}^n \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column-wise mean:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{V_t+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_t) = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_t} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6939</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6939"/>
		<updated>2024-12-11T06:58:10Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial gradient (​&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Gradient of the loss function with respect to X&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_1 = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\textstyle \sum_{i=1}^n\displaystyle  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.2: Find the Learning Rate Scaling (&#039;&#039;&#039;&amp;lt;math&amp;gt;\alpha_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Learning rate formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(\epsilon_2,RMS(X_0))\cdot p_1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the RMS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_1 = max(0.001,0.806)\cdot 0.01=0.00806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 2: Compute &amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;​ (Element-wise Square of Gradient)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Square the gradient value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.3^2&amp;amp;(-0.2)^2&amp;amp;0.4^2\\ (-0.5)^2&amp;amp;0.6^2&amp;amp;(-0.1)^2\\0.2^2&amp;amp;(-0.4)^2 &amp;amp;0.3^2 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G^{2}_t = \begin{bmatrix} 0.09&amp;amp; 0.04&amp;amp;0.16\\ 0.25&amp;amp;0.36&amp;amp;0.01\\0.04&amp;amp;0.16&amp;amp;0.09\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 3: Find the moment estimate&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.1: Compute row moments (&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This equation computes the row-wise second moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039; ​) as an exponential moving average of past moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_{t-1}&amp;lt;/math&amp;gt;&#039;&#039;&#039;) and the current row-wise mean of squared gradients ( &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;G^{2}_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;​ ), with a balance controlled by (&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G^{2}_t=\mathbb{R}^{m\times n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta_{2t}} \cdot R_{t-1} + (1-\hat{\beta})\cdot (\tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;, for first iteration: &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;. And because &amp;lt;math&amp;gt;\epsilon_1 &amp;lt;/math&amp;gt; is too small, we ignore it. The update of &#039;&#039;&#039;&amp;lt;math&amp;gt;R_1&amp;lt;/math&amp;gt;&#039;&#039;&#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_{1} = \tfrac{1}{m}\textstyle \sum_{j=1}^m \displaystyle G^{2}_t[i,j] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Row-wise mean (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_1 = \begin{bmatrix} \tfrac{0.09+0.04+0.16}{3} \\ \tfrac{0.25+0.36+0.01}{3}\\\tfrac{0.04+0.16+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.0967\\ 0.2067\\0.0967\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.2: Compute column moments (&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The prcoess is same as row moments&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}\cdot C_{{t-1}} + (1-\hat{\beta})\cdot (\tfrac{1}{n}\textstyle \sum_{j=1}^n \displaystyle G^{2}_t[i,j]+\epsilon_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Column Moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;C_1 = \begin{bmatrix} \tfrac{0.09+025+0.04}{3} \\ \tfrac{0.04+0.36+0.16}{3}\\\tfrac{0.16+0.01+0.09}{3} \end{bmatrix} = \begin{bmatrix} 0.1267\\ 0.1867\\0.0867\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3.3: Second Moment Estimate (&#039;&#039;&#039;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;​&#039;&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Second Moment Estimate is calculated as the outer product of the row moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​) and column moments (&#039;&#039;&#039;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&#039;&#039;&#039;​).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t = R_t \otimes C_t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t = \begin{bmatrix} 0.0967\\0.2067\\0.0967 \end{bmatrix} \otimes    \begin{bmatrix} 0.1267&amp;amp;0.1867&amp;amp;0.0867\\ \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;V_t =  \begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\ 0.0122&amp;amp;0.0180&amp;amp;0.0084\end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Update the vector (&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.1: Find the vector value of &amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{V_t+\epsilon_1}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Substitute &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;C_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039; and &amp;lt;small&amp;gt;&amp;lt;math&amp;gt;V_t&amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 =    \frac{\begin{bmatrix}0.3&amp;amp;-0.2&amp;amp;0.4 \\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4&amp;amp;0.3 \end{bmatrix}}{\sqrt{\begin{bmatrix} 0.0122&amp;amp;0.0180&amp;amp;0.0084\\ 0.0262&amp;amp;0.0386&amp;amp;0.0179\\0.0122&amp;amp;0.0180&amp;amp;0.0084 \end{bmatrix}}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;U_1 = \begin{bmatrix} 2.711&amp;amp;-1.489&amp;amp;4.370\\-3.090&amp;amp;3.055&amp;amp;-0.747\\1.807&amp;amp;-2.978&amp;amp;3.278  \end{bmatrix} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;step 4.2: Clipped Update Vector &amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Formula of &#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;\hat{U_t} = \frac{U_t}{max(1,\tfrac{RMS(U_t)}{d})         } &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate RMS of &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;small&amp;gt;&amp;lt;math&amp;gt;RMS(U_t) = \sqrt{\tfrac{1}{9}  \sum_{i=1}^9 U_t[i]^2}  \approx 3.303 &amp;lt;/math&amp;gt;&amp;lt;/small&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Since RMS(&#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​)&amp;gt;d, scale &#039;&#039;&#039;&amp;lt;math&amp;gt;U_t &amp;lt;/math&amp;gt;&#039;&#039;&#039;​ by &amp;lt;math&amp;gt;\tfrac{1}{3.303} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;math&amp;gt;\hat{U_t} =   \begin{bmatrix} 0.965&amp;amp;-0.53&amp;amp;1.556 \\-1.1&amp;amp;1.088&amp;amp;-0.266\\0.664&amp;amp;-1.06&amp;amp;1.167 \end{bmatrix} &amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 4: Weight Update (&amp;lt;/big&amp;gt;&#039;&#039;&#039;&amp;lt;math&amp;gt;X_1 &amp;lt;/math&amp;gt;&#039;&#039;&#039;&amp;lt;big&amp;gt;)&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6937</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6937"/>
		<updated>2024-12-11T04:26:58Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Numerical Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* Regularization constant 1: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constant 2: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step size: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
Step-by-step instructions for determining the result of the first iteration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Problem setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Initial weights (&#039;&#039;&#039;&amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;​&#039;&#039;&#039;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;X_0 = \begin{bmatrix} 0.7 &amp;amp;-0.5&amp;amp; 0.9\\ -1.1 &amp;amp; 0.8&amp;amp; -1.6\\1.2&amp;amp;-0.7&amp;amp; 0.4 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Gradient (​&amp;lt;math&amp;gt;G_t&amp;lt;/math&amp;gt;):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \begin{bmatrix} 0.3&amp;amp;-0.2&amp;amp;0.4\\ -0.5&amp;amp;0.6&amp;amp;-0.1\\0.2&amp;amp;-0.4 &amp;amp;0.3 \end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Hyperparameters setup&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt; (Minimum learning rate scaling factor))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt; (Regularization constant)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt; (Clipping threshold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt; (Relative step size)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt; (Second moment decay)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;big&amp;gt;Step 1:  Learning Rate Scaling&amp;lt;/big&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define the relative step size&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{1})= 10^{-2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1.1: Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Root Mean Square(RMS) calculation for &amp;lt;math&amp;gt;X_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RMS formula&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{n}\textstyle \sum_{i=1}^n\displaystyle  X_0[i]^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute the initial weights&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\tfrac{1}{9}(0.72^2+(-0.5)^2+0.9^2+(-1.1)^2+0.8^2+(-0.6)^2+1.2^2+(-0.7)^2+0.4^2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;RMS(X_0) = \sqrt{\frac{6.85}{9}}\approx 0.806&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the Learning Rate Scaling (αt​):&lt;br /&gt;
&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6936</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6936"/>
		<updated>2024-12-11T04:23:58Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
=== 5.Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6935</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6935"/>
		<updated>2024-12-11T04:23:50Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Clipping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
=== 5.Discussion ===&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6934</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6934"/>
		<updated>2024-12-11T04:23:40Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* 5.Discussion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
=== 5.Discussion ===&lt;br /&gt;
&lt;br /&gt;
=== Why Clipping ===&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6933</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6933"/>
		<updated>2024-12-11T04:23:32Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
=== 5.Discussion ===&lt;br /&gt;
=== Why Clipping ===&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6932</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6932"/>
		<updated>2024-12-11T04:23:15Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Clipping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
=== 5.Discussion ===&lt;br /&gt;
=== Why Clipping ===&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6931</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6931"/>
		<updated>2024-12-11T04:22:49Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Problem formulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== Why Clipping ===&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
=== 5.Discussion ===&lt;br /&gt;
=== Why Clipping ===&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== Why Adafactor is more memory efficient, compared to Adam ===&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6930</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6930"/>
		<updated>2024-12-11T04:21:45Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6929</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6929"/>
		<updated>2024-12-11T04:20:12Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Clipping&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6928</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6928"/>
		<updated>2024-12-11T04:19:39Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&#039;&#039;&#039;Row-wise and Column-wise Second Moment Updates&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Factored Representation of the Second Moment&#039;&#039;&#039;&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&#039;&#039;&#039;Clipping&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6927</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6927"/>
		<updated>2024-12-11T04:18:39Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. &lt;br /&gt;
*However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since&lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
** It also only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6926</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6926"/>
		<updated>2024-12-11T04:17:38Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since &lt;br /&gt;
** The operation is performed element-wise, so it actually never materializes &amp;lt;math&amp;gt;\hat{V_t}&amp;lt;/math&amp;gt; as a &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
&lt;br /&gt;
and only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6925</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6925"/>
		<updated>2024-12-11T04:15:23Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt;, Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
This updates the second momentum based on the outer product &amp;lt;math&amp;gt;R_t C_t&amp;lt;/math&amp;gt;. However, this is not &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; since the operation is performed element-wise, and only storing &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt;and &amp;lt;math&amp;gt; C_t&amp;lt;/math&amp;gt; instead of storage the full second-moment matrix&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6923</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6923"/>
		<updated>2024-12-11T04:08:49Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt; Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6922</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6922"/>
		<updated>2024-12-11T04:07:24Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt; Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6921</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6921"/>
		<updated>2024-12-11T04:06:49Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
Instead of storing the full &amp;lt;math&amp;gt;G_t^2&amp;lt;/math&amp;gt; Adafactor computes the row and column respectively, which reduces the memory requirements from &amp;lt;math&amp;gt;O(n\times m) to O(n + m)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6920</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6920"/>
		<updated>2024-12-11T04:04:58Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
*&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6919</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6919"/>
		<updated>2024-12-11T04:04:43Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6918</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6918"/>
		<updated>2024-12-11T04:03:23Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Adafactor is more memory efficient, compared to Adam */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
* Instead of&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6915</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6915"/>
		<updated>2024-12-11T03:59:52Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Clipping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
==== Why Adafactor is more memory efficient, compared to Adam ====&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6913</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6913"/>
		<updated>2024-12-11T03:54:44Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Clipping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
Therefore, implementing clipping helps ensure stability and efficient training without requiring per-parameter scaling like Adam.&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6912</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6912"/>
		<updated>2024-12-11T03:52:38Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Adafactor for Weighted Matrices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Why Clipping ====&lt;br /&gt;
Adafactor employs clipping to maintain numerical stability, especially since it is designed for use with very large models and often works with unscaled learning rates. &lt;br /&gt;
* Clipping prevents the update step from becoming very large, which would destabilize training&lt;br /&gt;
* Clipping mitigates the effects of very large gradients preventing numerical instability&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
	<entry>
		<id>https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6911</id>
		<title>Adafactor</title>
		<link rel="alternate" type="text/html" href="https://optimization.cbe.cornell.edu/index.php?title=Adafactor&amp;diff=6911"/>
		<updated>2024-12-11T03:52:22Z</updated>

		<summary type="html">&lt;p&gt;Fall2024 Wiki Team6: /* Why Clipping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Aolei Cao (ac3237), Ziyang Li (zl986), Junjia Liang (jl4439) (ChemE 6800 Fall 2024)&lt;br /&gt;
&lt;br /&gt;
Stewards: Nathan Preuss, Wei-Han Chen, Tianqi Xiao, Guoqing Hu&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
== Problem formulation ==&lt;br /&gt;
=== 1. Objective ===&lt;br /&gt;
Minimize the loss function &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x \in R^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the weight vector to be optimized.&lt;br /&gt;
&lt;br /&gt;
=== 2. Parameters ===&lt;br /&gt;
*&#039;&#039;&#039; Gradient:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;math&amp;gt;G_t = \nabla f(x_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Second moment estimate:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Where:&#039;&#039;&#039;&lt;br /&gt;
** &amp;lt;math&amp;gt;\hat{V}_t&amp;lt;/math&amp;gt; is the running average of the squared gradient.&lt;br /&gt;
**&amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; is the corrected decay parameter.&lt;br /&gt;
**&amp;lt;math&amp;gt;\epsilon_1&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Step size:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(x_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Where&#039;&#039;&#039;:&lt;br /&gt;
** &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; is the relative step size.&lt;br /&gt;
** &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt; is a regularization constant.&lt;br /&gt;
** &amp;lt;math&amp;gt;\text{RMS}&amp;lt;/math&amp;gt; is the root mean square, defined as:&lt;br /&gt;
*** &amp;lt;math&amp;gt;u_{xt} = \frac{-g_{xt}}{\sqrt{\hat{v}_{xt}}}&amp;lt;/math&amp;gt;&lt;br /&gt;
*** &amp;lt;math&amp;gt;\text{RMS}(U_t) = \text{RMS}_{x \in X}(u_{xt}) = \sqrt{\text{Mean}_{x \in X}\left(\frac{(g_{xt})^2}{\hat{v}_{xt}}\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
=== 3. Algorithms ===&lt;br /&gt;
==== Adafactor for Weighted Vectors ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^n&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \hat{\beta}_{2t} \hat{V}_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
==== Adafactor for Weighted Matrices ====&lt;br /&gt;
&#039;&#039;&#039;Inputs:&#039;&#039;&#039;&lt;br /&gt;
* Initial point: &amp;lt;math&amp;gt;X_0 \in \mathbb{R}^{n \times m}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Relative step sizes: &amp;lt;math&amp;gt;\rho_t&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;&lt;br /&gt;
* Second moment decay: &amp;lt;math&amp;gt;\hat{\beta}_{2t}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;\hat{\beta}_{21} = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* Regularization constants: &amp;lt;math&amp;gt;\epsilon_1, \epsilon_2&amp;lt;/math&amp;gt;&lt;br /&gt;
* Clipping threshold: &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithm:&#039;&#039;&#039;&lt;br /&gt;
* For &amp;lt;math&amp;gt;t = 1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;:&lt;br /&gt;
** Compute adaptive step size: &amp;lt;math&amp;gt;\alpha_t = \max(\epsilon_2, \text{RMS}(X_{t-1})) \rho_t&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute gradient: &amp;lt;math&amp;gt;G_t = \nabla f_t(X_{t-1})&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update row-wise second moment: &amp;lt;math&amp;gt;R_t = \hat{\beta}_{2t} R_{t-1} + (1 - \hat{\beta}_{2t})(G_t^2 + \epsilon_1 1_n 1_m^T) 1_m&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update column-wise second moment: &amp;lt;math&amp;gt;C_t = \hat{\beta}_{2t} C_{t-1} + (1 - \hat{\beta}_{2t}) 1_n^T (G_t^2 + \epsilon_1 1_n 1_m^T)&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update overall second moment estimate: &amp;lt;math&amp;gt;\hat{V}_t = \frac{R_t C_t}{1_n^T R_t}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Compute normalized gradient: &amp;lt;math&amp;gt;U_t = \frac{G_t}{\sqrt{\hat{V}_t}}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Apply clipping: &amp;lt;math&amp;gt;\hat{U}_t = \frac{U_t}{\max(1, \text{RMS}(U_t) / d)}&amp;lt;/math&amp;gt;&lt;br /&gt;
** Update parameter: &amp;lt;math&amp;gt;X_t = X_{t-1} - \alpha_t \hat{U}_t&amp;lt;/math&amp;gt;&lt;br /&gt;
* End for&lt;br /&gt;
&lt;br /&gt;
=== 4. Proposed Hyperparameters for Adafactor ===&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 1&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_1 = 10^{-30}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Ensures numerical stability by preventing division by zero in the calculation of second-moment estimates, so the numerical value should be very close to zero&lt;br /&gt;
* &#039;&#039;&#039;Regularization constant 2&#039;&#039;&#039;: &amp;lt;math&amp;gt;\epsilon_2 = 10^{-3}&amp;lt;/math&amp;gt;&lt;br /&gt;
* Help to stabilize parameter updates by controlling the effect of second-moment scaling in low-magnitude scenarios. Compared to &amp;lt;math&amp;gt;\epsilon_2&amp;lt;/math&amp;gt;, a relatively larger value ensures the stability of noise and low-magnitude scenarios.&lt;br /&gt;
* &#039;&#039;&#039;Clipping threshold&#039;&#039;&#039;: &amp;lt;math&amp;gt;d = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
* A threshold of 1 balances stability and learning efficiency. It avoids excessive suppression of large gradients, which could hinder learning, while still protecting against extreme updates that could destabilize the model.&lt;br /&gt;
* &#039;&#039;&#039;Relative step size&#039;&#039;&#039;: &amp;lt;math&amp;gt;\rho_t = \min(10^{-2}, 1/\sqrt{t})&amp;lt;/math&amp;gt;&lt;br /&gt;
** &amp;lt;math&amp;gt;min(10^-2, ...)&amp;lt;/math&amp;gt; can caps the learning rate at 10^-2, which is a empirical found for upper bound&lt;br /&gt;
** &amp;lt;math&amp;gt;\frac{1}{\sqrt{t}}&amp;lt;/math&amp;gt; This step size promote convergence of the model. This rate ensures a balance between sufficient exploration in early iteration and stability in later iterations&lt;br /&gt;
* &#039;&#039;&#039;Second moment decay&#039;&#039;&#039;: &amp;lt;math&amp;gt;\hat{\beta}_{2t} = 1 - t^{-0.8}&amp;lt;/math&amp;gt;&lt;br /&gt;
** 1-...: ensures the decay factor remains close to 1&lt;br /&gt;
** &amp;lt;math&amp;gt;t^{-0,8}&amp;lt;/math&amp;gt; the power 0.8 ensures a balance between rapid adaptation in early training and later iterations&lt;br /&gt;
&lt;br /&gt;
== Numerical Examples ==&lt;br /&gt;
== Applications ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Reference ==&lt;/div&gt;</summary>
		<author><name>Fall2024 Wiki Team6</name></author>
	</entry>
</feed>