adv-optm 1.1.0.dev5__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of adv-optm might be problematic. Click here for more details.

Files changed (28) hide show
  1. adv_optm-1.1.2/PKG-INFO +275 -0
  2. adv_optm-1.1.2/README.md +244 -0
  3. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/__init__.py +1 -1
  4. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/AdamW_adv.py +2 -2
  5. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/Adopt_adv.py +2 -2
  6. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/Lion_Prodigy_adv.py +62 -36
  7. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/Prodigy_adv.py +3 -5
  8. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/Simplified_AdEMAMix.py +1 -1
  9. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/Kourkoutas.py +10 -3
  10. adv_optm-1.1.2/adv_optm.egg-info/PKG-INFO +275 -0
  11. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/setup.py +1 -1
  12. adv_optm-1.1.0.dev5/PKG-INFO +0 -174
  13. adv_optm-1.1.0.dev5/README.md +0 -143
  14. adv_optm-1.1.0.dev5/adv_optm.egg-info/PKG-INFO +0 -174
  15. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/LICENSE +0 -0
  16. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/Lion_adv.py +0 -0
  17. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/optim/__init__.py +0 -0
  18. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/BF16_Stochastic_Rounding.py +0 -0
  19. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/Effective_Shape.py +0 -0
  20. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/NNMF.py +0 -0
  21. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/One_Bit_Boolean.py +0 -0
  22. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/OrthoGrad.py +0 -0
  23. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm/util/__init__.py +0 -0
  24. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm.egg-info/SOURCES.txt +0 -0
  25. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm.egg-info/dependency_links.txt +0 -0
  26. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm.egg-info/requires.txt +0 -0
  27. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/adv_optm.egg-info/top_level.txt +0 -0
  28. {adv_optm-1.1.0.dev5 → adv_optm-1.1.2}/setup.cfg +0 -0
@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.4
2
+ Name: adv_optm
3
+ Version: 1.1.2
4
+ Summary: A family of highly efficient, lightweight yet powerful optimizers.
5
+ Home-page: https://github.com/Koratahiu/Advanced_Optimizers
6
+ Author: Koratahiu
7
+ Author-email: hiuhonor@gmail.com
8
+ License: Apache 2.0
9
+ Keywords: llm,fine-tuning,memory-efficient,low-rank,compression,pytorch,optimizer,adam
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: torch>=2.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: keywords
26
+ Dynamic: license
27
+ Dynamic: license-file
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ # Advanced Optimizers (AIO)
33
+
34
+ A comprehensive, all-in-one collection of optimization algorithms for deep learning, designed for **maximum efficiency**, **minimal memory footprint**, and **superior performance** across diverse model architectures and training scenarios.
35
+
36
+ [![PyPI](https://img.shields.io/pypi/v/adv_optm)](https://pypi.org/project/adv_optm/)
37
+
38
+ ---
39
+
40
+ ## 📦 Installation
41
+
42
+ ```bash
43
+ pip install adv_optm
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 🧠 Core Innovations
49
+
50
+ This library integrates multiple state-of-the-art optimization techniques validated through extensive research and practical training, with **1-bit compression for optimizer states**:
51
+
52
+ ### **Memory-Efficient Optimization (SMMF-inspired)**
53
+ - **Paper**: [SMMF: Square-Matricized Momentum Factorization](https://arxiv.org/abs/2412.08894)
54
+ - **Approach**: Uses rank-1 non-negative matrix factorization with reconstruction cycle (factor → reconstruct → update → factor)
55
+ - **Innovation**:
56
+ - First moment split into **1-bit sign + absolute value**
57
+ - Final storage: **four factored vectors + one 1-bit sign state**
58
+ - Preserves Adam-like update quality with drastically reduced memory
59
+
60
+ ---
61
+
62
+ ## ⚡ Performance Characteristics
63
+
64
+ ### Memory Efficiency (SDXL Model – 6.5GB)
65
+ | Optimizer | Memory Usage | Description |
66
+ |-----------|--------------|-------------|
67
+ | `Adopt_Factored` | 328 MB | 4 small vectors + 1-bit state |
68
+ | `Adopt_Factored + AdEMAMix` | 625 MB | 6 small vectors + two 1-bit states |
69
+ | `Simplified_AdEMAMix` | 328 MB | Same as standard factored (no extra state) |
70
+
71
+ ### Speed Comparison (SDXL, Batch Size 4)
72
+ | Optimizer | Speed | Notes |
73
+ |-----------|-------|-------|
74
+ | `Adafactor` | ~8.5s/it | Baseline |
75
+ | `Adopt_Factored` | ~10s/it | +18% overhead from compression |
76
+ | `Adopt_Factored + AdEMAMix` | ~12s/it | +41% overhead (3 factored states) |
77
+
78
+ ---
79
+
80
+ ## 🧪 Available Optimizers
81
+
82
+ ### Standard Optimizers (All support `factored=True/False`)
83
+ | Optimizer | Description | Best For |
84
+ |-----------|-------------|----------|
85
+ | `Adam_Adv` | Advanced Adam implementation | General purpose |
86
+ | `Adopt_Adv` | Adam-variant with independent beta2 | Stable training for small batch size regimes |
87
+ | `Prodigy_Adv` | Prodigy with D-Adaptation | Adam with automatic LR tuning |
88
+ | `Simplified_AdEMAMix` | Adam variant with accumulator momentum | Small/large batch training when tuned correctly |
89
+ | `Lion_Adv` | Advanced Lion implementation | Memory-constrained environments |
90
+ | `Prodigy_Lion_Adv` | Prodigy + Lion combination | Lion with automatic LR tuning |
91
+
92
+ ---
93
+
94
+ ## ⚙️ Feature Matrix
95
+
96
+ | Feature | Adam_Adv | Adopt_Adv | Prodigy_Adv | Simplified_AdEMAMix | Lion_Adv |
97
+ |---------|----------|-----------|-------------|---------------------|----------|
98
+ | Factored | ✓ | ✓ | ✓ | ✓ | ✓ |
99
+ | AdEMAMix | ✓ | ✓ | ✓ | ✗ | ✗ |
100
+ | Simplified_AdEMAMix | ✗ | ✓ | ✓ | ✓ | ✗ |
101
+ | OrthoGrad | ✓ | ✓ | ✓ | ✓ | ✓ |
102
+ | Grams | ✓ | ✓ | ✓ | ✗ | ✗ |
103
+ | Cautious | ✓ | ✓ | ✓ | ✗ | ✓ |
104
+ | atan2 | ✓ | ✓ | ✓ | ✗ | ✗ |
105
+ | Stochastic Rounding | ✓ | ✓ | ✓ | ✓ | ✓ |
106
+ | Fused Backward Pass | ✓ | ✓ | ✓ | ✓ | ✓ |
107
+ | **Kourkoutas-β** | ✓ | ✓ | ✓ | ✓ | ✗ |
108
+
109
+ ---
110
+
111
+ ## 🛠️ Comprehensive Feature Guide
112
+
113
+ ### A. Universal Safe Features
114
+ *These features work with all optimizers and are generally safe to enable.*
115
+
116
+ | Feature | Description | Recommended Usage | Performance Impact | Theoretical Basis | Compatibility |
117
+ |--------|-------------|-------------------|--------------------|-------------------|--------------|
118
+ | **Fused Back Pass** | Fuses backward pass; gradients used immediately and memory freed on-the-fly | Memory-constrained environments | Reduces peak memory | Memory optimization | All optimizers |
119
+ | **Stochastic Rounding** | Replaces nearest rounding with stochastic rounding to preserve small gradient updates in BF16 | BF16 training | Minimal overhead (<5%) | [Revisiting BFloat16 Training](https://arxiv.org/abs/2010.06192) | All optimizers |
120
+ | **OrthoGrad** | Removes gradient component parallel to weights to reduce overfitting | Full fine-tuning without weight decay | +33% time overhead (BS=4); less at larger BS | [Grokking at Edge](https://github.com/LucasPrietoAl/grokking-at-the-edge-of-numerical-stability) | All optimizers |
121
+ | **Factored** | Memory-efficient optimization via rank-1 1-bit factorization of optimizer states | Large models / memory-limited hardware | Adds compression overhead | [SMMF](https://arxiv.org/abs/2412.08894) | All optimizers |
122
+
123
+ ### B. Individual Features
124
+
125
+ | Feature | Description | Recommended Usage | Performance Impact | Theoretical Basis | Compatibility |
126
+ |--------|-------------|-------------------|--------------------|-------------------|--------------|
127
+ | **Cautious** | Only applies update if gradient direction aligns with momentum direction | Accelerating convergence | No overhead | [C-Optim](https://github.com/kyleliang919/C-Optim) | Adam/Adopt/Prodigy/Lion |
128
+ | **Grams** | Update direction derived purely from current gradient | When Cautious is insufficient | No overhead | [Grams](https://github.com/Gunale0926/Grams) | Adam/Adopt/Prodigy |
129
+ | **AdEMAMix** | Dual EMA system that retains relevance of gradients over tens of thousands of steps | Long training runs, especially where model forgetting is a concern | +1 state memory | [AdEMAMix](https://arxiv.org/abs/2409.03137) | Adam/Adopt/Prodigy |
130
+ | **Simplified_AdEMAMix** | Accumulator-based momentum, single EMA variant of AdEMAMix | All scenarios when tuned correctly | No overhead | [Connections](https://arxiv.org/abs/2502.02431) | Adam/Adopt/Prodigy |
131
+ | **atan2** | Robust epsilon replacement with built-in gradient clipping | Use for stable bounded updates (or for Adopt as it needs that) | No overhead | [Adam-atan2](https://github.com/lucidrains/adam-atan2-pytorch) | Adam/Adopt/Prodigy |
132
+ | **Kourkoutas-β** | Layer-wise adaptive β₂ based on gradient “sunspike” ratio | Noisy/small/large-batch/high-LR training | No overhead | [Kourkoutas-β]() | Adam/Adopt/Prodigy/Simplified_AdEMAMix |
133
+
134
+ > **Note**: If both **Cautious** and **Grams** are enabled, **Grams takes precedence** and Cautious is disabled.
135
+
136
+ ---
137
+
138
+ ## 🔍 Feature Deep Dives
139
+
140
+ ### AdEMAMix
141
+
142
+ - Adds a **slow-decaying second EMA** (`beta3`) that retains gradient memory over tens of thousands of steps.
143
+ - Particularly effective for **small batch sizes**, where Adam’s standard first moment is nearly useless.
144
+ - **Reference**: [AdaMeM: Memory Efficient Momentum for Adafactor](https://openreview.net/forum?id=fZqMVTz7K5)
145
+
146
+ #### Tunable Hyperparameters
147
+ | Parameter | Default | Tuning Guide |
148
+ |-----------|---------|--------------|
149
+ | `beta3` | 0.9999 | • Runs >120k steps: **0.9999**<br>• Runs ≤120k steps: **0.999** |
150
+ | `alpha` | 5 | • Reduce to **2–3** if diverging<br>• Increase to strengthen long-term memory |
151
+
152
+ > ✅ **Pro Tip**: Set `beta1=0` in Adam/Adopt/Prodigy to skip standard EMA entirely and rely solely on AdEMAMix’s slow EMA, ideal for small-batch regimes.
153
+
154
+ ---
155
+
156
+ ### Simplified_AdEMAMix
157
+
158
+ - Introduced in [Connections between Schedule-Free Optimizers, AdEMAMix, and Accelerated SGD Variants (arXiv:2502.02431)](https://arxiv.org/abs/2502.02431).
159
+ - Replaces Adam’s first moment with a **gradient accumulator**, combining the stability of long memory with responsiveness to recent gradients.
160
+ - **Key insight**: Classical momentum **does not accelerate** in noisy (small-batch) regimes; this accumulator do.
161
+
162
+ #### Tunable Hyperparameters
163
+ | Parameter | Default | Tuning Guide |
164
+ |----------|---------|--------------|
165
+ | `beta1` | 0.99 | Controls accumulator memory length:<br>• Small BS: **0.99–0.9999**<br>• Large BS: **0.9** |
166
+ | `Grad α` | 100 | Most critical parameter:<br>• Inversely scales with batch size<br>• **100–10** for small BS (≤32)<br>• **1–0.1** for large BS (≥512) |
167
+
168
+ > ⚠️ **Critical**: Requires **~100x smaller learning rate** than AdamW (e.g., 1e-6 vs 1e-4).
169
+ > For `Prodigy_Adv`, set `initial_d` to:
170
+ > - **LoRA**: `1e-8`
171
+ > - **Full FT**: `1e-10`
172
+ > - **Embedding**: `1e-7`
173
+
174
+ > ⚠️ **Incompatible** with: **Cautious**, **Grams**, **atan2**, and standard gradient clipping.
175
+
176
+ #### Performance Validation
177
+
178
+ **Small Batch Training (SDXL, BS=2, 1.8K steps)**
179
+ ![Training Comparison](https://github.com/user-attachments/assets/7eff0671-cc59-47fc-8b63-d5205456d649)
180
+
181
+ - **🟢 Prodigy_Adv** (beta1=0.9, d0=1e-5): Final LR = 2.9e-4
182
+ - **🔵 Prodigy_Adv + Simplified_AdEMAMix** (beta1=0.99, α=100, d0=1e-7): Final LR = 5.8e-6
183
+
184
+ **Results**:
185
+ - Faster convergence and higher final performance with Simplified_AdEMAMix
186
+ - D-Adaptation automatically compensates for aggressive updates
187
+ - Generated samples show **significantly better quality**
188
+
189
+ ---
190
+
191
+ ### atan2
192
+
193
+ - Replaces `eps` in Adam-family optimizers with a **scale-invariant**, bounded update rule.
194
+ - Automatically clips updates to **[-2, 2]**, preventing destabilizing jumps.
195
+ - **Highly recommended** for `Adopt_Adv`, which is prone to instability without clipping.
196
+
197
+ ---
198
+
199
+ ### **Kourkoutas-β**
200
+
201
+ **Kourkoutas-β** introduces a **sunspike-driven, layer-wise adaptive second-moment decay (β₂)** as an optional enhancement for `Adam_Adv`, `Adopt_Adv`, `Prodigy_Adv`, and `Simplified_AdEMAMix`.
202
+
203
+ Instead of using a fixed β₂ (e.g., 0.999 or 0.95), it **dynamically modulates β₂ per layer** based on a bounded *sunspike ratio*:
204
+
205
+ - **During gradient bursts** → β₂ ↓ toward `Lower β₂` → faster reaction
206
+ - **During calm phases** → β₂ ↑ toward `The Selected β₂` → stronger smoothing
207
+
208
+ This is especially effective for **noisy training, small batch sizes, and high learning rates**, where gradient norms shift abruptly due to noise or aggressive LR schedules.
209
+
210
+ #### Pros/Cons
211
+
212
+ | **Category** | **Details** |
213
+ |--------------|-------------|
214
+ | ✅ **Pros** | • **Layer-wise adaptation** blends benefits of high β₂ (strong smoothing) and low β₂ (fast reaction).<br>• **Robust to sudden loss landscape shifts**, reacts quickly during gradient bursts, smooths during calm phases.<br>• **High tolerance to aggressive learning rates**. |
215
+ | ⚠️ **Cons** | • **Potentially unstable at the start of training** due to unreliable early gradient norms; mitigated by using `K-β Warmup Steps`. |
216
+
217
+ > 💡 **Best Practice**: Set `K_warmup_steps` equal to your standard LR warmup steps. During warmup, the optimizer uses the static `beta2`; adaptation begins only after warmup ends.
218
+
219
+ > 🔍 **Debugging Aid**: Enable `K_Logging` to monitor (min, max, mean) of dynamic β₂ values across layers every *N* steps.
220
+
221
+ #### 📊 Performance Validation
222
+
223
+ **ADAMW_ADV - full SDXL finetuning (aggressive LR: 3e-5) (BS=4, 2.5K steps)**
224
+ <img width="1460" height="382" alt="image" src="https://github.com/user-attachments/assets/007f278a-fbac-4f3d-9cc7-274c3b959cdd" />
225
+
226
+ - 🟣 Fixed `beta2=0.999`
227
+ - 🟠 Auto K-beta
228
+
229
+ **Observations:**
230
+ - K-beta is clearly better and more robust/stable for high LRs.
231
+
232
+ > 📚 **Reference**:
233
+ > - Paper: [Kourkoutas-β: A Sunspike-Driven Adam Optimizer with Desert Flair](https://arxiv.org/abs/2508.12996)
234
+ > - Code: [kbeta](https://github.com/sck-at-ucy/kbeta)
235
+
236
+ ---
237
+
238
+ ## Recommended Preset (Tested on LoRA/FT/Embedding)
239
+
240
+ ```yaml
241
+ Learning Rate: 1
242
+ optimizer: PRODIGY_Adv
243
+ settings:
244
+ - beta1: 0.99 # Controls momentum decay, ~100-step effective memory. Adjust to 0.999 (1000 steps) or 0.9999 (10000 steps) based on training length and stability needs.
245
+ - beta2: 0.999
246
+ - kourkoutas_beta: True # For Kourkoutas-β
247
+ - K-β Warmup Steps: 50 # Or 100, 200, depending on your run
248
+ - Simplified_AdEMAMix: True
249
+ - Grad α: 100
250
+ - OrthoGrad: True
251
+ - weight_decay: 0.0
252
+ - initial_d:
253
+ • LoRA: 1e-8
254
+ • Full fine-tune: 1e-10
255
+ • Embedding: 1e-7
256
+ - d_coef: 1
257
+ - d_limiter: True # To stablizie Prodigy with Simplified_AdEMAMix
258
+ - factored: False # Can be true or false, quality should not degrade due to Simplified_AdEMAMix’s high tolerance to 1-bit factorization.
259
+ ```
260
+
261
+ > ✅ **Why it works**:
262
+ > - `Kourkoutas-β` handles beta2 values
263
+ > - `Simplified_AdEMAMix` ensures responsiveness in small-batch noise
264
+ > - `OrthoGrad` prevents overfitting without weight decay
265
+
266
+ ---
267
+
268
+ ## 📚 References
269
+
270
+ 1. [Revisiting BFloat16 Training](https://arxiv.org/abs/2010.06192)
271
+ 2. [SMMF: Square-Matricized Momentum Factorization](https://arxiv.org/abs/2412.08894)
272
+ 3. [The AdEMAMix Optimizer](https://arxiv.org/abs/2409.03137)
273
+ 4. [Connections between Schedule-Free Optimizers, AdEMAMix, and Accelerated SGD](https://arxiv.org/abs/2502.02431)
274
+ 5. [AdaMeM: Memory Efficient Momentum for Adafactor](https://openreview.net/forum?id=fZqMVTz7K5)
275
+ 6. [Kourkoutas-β: A Sunspike-Driven Adam Optimizer with Desert Flair](https://arxiv.org/abs/2508.12996)
@@ -0,0 +1,244 @@
1
+ # Advanced Optimizers (AIO)
2
+
3
+ A comprehensive, all-in-one collection of optimization algorithms for deep learning, designed for **maximum efficiency**, **minimal memory footprint**, and **superior performance** across diverse model architectures and training scenarios.
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/adv_optm)](https://pypi.org/project/adv_optm/)
6
+
7
+ ---
8
+
9
+ ## 📦 Installation
10
+
11
+ ```bash
12
+ pip install adv_optm
13
+ ```
14
+
15
+ ---
16
+
17
+ ## 🧠 Core Innovations
18
+
19
+ This library integrates multiple state-of-the-art optimization techniques validated through extensive research and practical training, with **1-bit compression for optimizer states**:
20
+
21
+ ### **Memory-Efficient Optimization (SMMF-inspired)**
22
+ - **Paper**: [SMMF: Square-Matricized Momentum Factorization](https://arxiv.org/abs/2412.08894)
23
+ - **Approach**: Uses rank-1 non-negative matrix factorization with reconstruction cycle (factor → reconstruct → update → factor)
24
+ - **Innovation**:
25
+ - First moment split into **1-bit sign + absolute value**
26
+ - Final storage: **four factored vectors + one 1-bit sign state**
27
+ - Preserves Adam-like update quality with drastically reduced memory
28
+
29
+ ---
30
+
31
+ ## ⚡ Performance Characteristics
32
+
33
+ ### Memory Efficiency (SDXL Model – 6.5GB)
34
+ | Optimizer | Memory Usage | Description |
35
+ |-----------|--------------|-------------|
36
+ | `Adopt_Factored` | 328 MB | 4 small vectors + 1-bit state |
37
+ | `Adopt_Factored + AdEMAMix` | 625 MB | 6 small vectors + two 1-bit states |
38
+ | `Simplified_AdEMAMix` | 328 MB | Same as standard factored (no extra state) |
39
+
40
+ ### Speed Comparison (SDXL, Batch Size 4)
41
+ | Optimizer | Speed | Notes |
42
+ |-----------|-------|-------|
43
+ | `Adafactor` | ~8.5s/it | Baseline |
44
+ | `Adopt_Factored` | ~10s/it | +18% overhead from compression |
45
+ | `Adopt_Factored + AdEMAMix` | ~12s/it | +41% overhead (3 factored states) |
46
+
47
+ ---
48
+
49
+ ## 🧪 Available Optimizers
50
+
51
+ ### Standard Optimizers (All support `factored=True/False`)
52
+ | Optimizer | Description | Best For |
53
+ |-----------|-------------|----------|
54
+ | `Adam_Adv` | Advanced Adam implementation | General purpose |
55
+ | `Adopt_Adv` | Adam-variant with independent beta2 | Stable training for small batch size regimes |
56
+ | `Prodigy_Adv` | Prodigy with D-Adaptation | Adam with automatic LR tuning |
57
+ | `Simplified_AdEMAMix` | Adam variant with accumulator momentum | Small/large batch training when tuned correctly |
58
+ | `Lion_Adv` | Advanced Lion implementation | Memory-constrained environments |
59
+ | `Prodigy_Lion_Adv` | Prodigy + Lion combination | Lion with automatic LR tuning |
60
+
61
+ ---
62
+
63
+ ## ⚙️ Feature Matrix
64
+
65
+ | Feature | Adam_Adv | Adopt_Adv | Prodigy_Adv | Simplified_AdEMAMix | Lion_Adv |
66
+ |---------|----------|-----------|-------------|---------------------|----------|
67
+ | Factored | ✓ | ✓ | ✓ | ✓ | ✓ |
68
+ | AdEMAMix | ✓ | ✓ | ✓ | ✗ | ✗ |
69
+ | Simplified_AdEMAMix | ✗ | ✓ | ✓ | ✓ | ✗ |
70
+ | OrthoGrad | ✓ | ✓ | ✓ | ✓ | ✓ |
71
+ | Grams | ✓ | ✓ | ✓ | ✗ | ✗ |
72
+ | Cautious | ✓ | ✓ | ✓ | ✗ | ✓ |
73
+ | atan2 | ✓ | ✓ | ✓ | ✗ | ✗ |
74
+ | Stochastic Rounding | ✓ | ✓ | ✓ | ✓ | ✓ |
75
+ | Fused Backward Pass | ✓ | ✓ | ✓ | ✓ | ✓ |
76
+ | **Kourkoutas-β** | ✓ | ✓ | ✓ | ✓ | ✗ |
77
+
78
+ ---
79
+
80
+ ## 🛠️ Comprehensive Feature Guide
81
+
82
+ ### A. Universal Safe Features
83
+ *These features work with all optimizers and are generally safe to enable.*
84
+
85
+ | Feature | Description | Recommended Usage | Performance Impact | Theoretical Basis | Compatibility |
86
+ |--------|-------------|-------------------|--------------------|-------------------|--------------|
87
+ | **Fused Back Pass** | Fuses backward pass; gradients used immediately and memory freed on-the-fly | Memory-constrained environments | Reduces peak memory | Memory optimization | All optimizers |
88
+ | **Stochastic Rounding** | Replaces nearest rounding with stochastic rounding to preserve small gradient updates in BF16 | BF16 training | Minimal overhead (<5%) | [Revisiting BFloat16 Training](https://arxiv.org/abs/2010.06192) | All optimizers |
89
+ | **OrthoGrad** | Removes gradient component parallel to weights to reduce overfitting | Full fine-tuning without weight decay | +33% time overhead (BS=4); less at larger BS | [Grokking at Edge](https://github.com/LucasPrietoAl/grokking-at-the-edge-of-numerical-stability) | All optimizers |
90
+ | **Factored** | Memory-efficient optimization via rank-1 1-bit factorization of optimizer states | Large models / memory-limited hardware | Adds compression overhead | [SMMF](https://arxiv.org/abs/2412.08894) | All optimizers |
91
+
92
+ ### B. Individual Features
93
+
94
+ | Feature | Description | Recommended Usage | Performance Impact | Theoretical Basis | Compatibility |
95
+ |--------|-------------|-------------------|--------------------|-------------------|--------------|
96
+ | **Cautious** | Only applies update if gradient direction aligns with momentum direction | Accelerating convergence | No overhead | [C-Optim](https://github.com/kyleliang919/C-Optim) | Adam/Adopt/Prodigy/Lion |
97
+ | **Grams** | Update direction derived purely from current gradient | When Cautious is insufficient | No overhead | [Grams](https://github.com/Gunale0926/Grams) | Adam/Adopt/Prodigy |
98
+ | **AdEMAMix** | Dual EMA system that retains relevance of gradients over tens of thousands of steps | Long training runs, especially where model forgetting is a concern | +1 state memory | [AdEMAMix](https://arxiv.org/abs/2409.03137) | Adam/Adopt/Prodigy |
99
+ | **Simplified_AdEMAMix** | Accumulator-based momentum, single EMA variant of AdEMAMix | All scenarios when tuned correctly | No overhead | [Connections](https://arxiv.org/abs/2502.02431) | Adam/Adopt/Prodigy |
100
+ | **atan2** | Robust epsilon replacement with built-in gradient clipping | Use for stable bounded updates (or for Adopt as it needs that) | No overhead | [Adam-atan2](https://github.com/lucidrains/adam-atan2-pytorch) | Adam/Adopt/Prodigy |
101
+ | **Kourkoutas-β** | Layer-wise adaptive β₂ based on gradient “sunspike” ratio | Noisy/small/large-batch/high-LR training | No overhead | [Kourkoutas-β]() | Adam/Adopt/Prodigy/Simplified_AdEMAMix |
102
+
103
+ > **Note**: If both **Cautious** and **Grams** are enabled, **Grams takes precedence** and Cautious is disabled.
104
+
105
+ ---
106
+
107
+ ## 🔍 Feature Deep Dives
108
+
109
+ ### AdEMAMix
110
+
111
+ - Adds a **slow-decaying second EMA** (`beta3`) that retains gradient memory over tens of thousands of steps.
112
+ - Particularly effective for **small batch sizes**, where Adam’s standard first moment is nearly useless.
113
+ - **Reference**: [AdaMeM: Memory Efficient Momentum for Adafactor](https://openreview.net/forum?id=fZqMVTz7K5)
114
+
115
+ #### Tunable Hyperparameters
116
+ | Parameter | Default | Tuning Guide |
117
+ |-----------|---------|--------------|
118
+ | `beta3` | 0.9999 | • Runs >120k steps: **0.9999**<br>• Runs ≤120k steps: **0.999** |
119
+ | `alpha` | 5 | • Reduce to **2–3** if diverging<br>• Increase to strengthen long-term memory |
120
+
121
+ > ✅ **Pro Tip**: Set `beta1=0` in Adam/Adopt/Prodigy to skip standard EMA entirely and rely solely on AdEMAMix’s slow EMA, ideal for small-batch regimes.
122
+
123
+ ---
124
+
125
+ ### Simplified_AdEMAMix
126
+
127
+ - Introduced in [Connections between Schedule-Free Optimizers, AdEMAMix, and Accelerated SGD Variants (arXiv:2502.02431)](https://arxiv.org/abs/2502.02431).
128
+ - Replaces Adam’s first moment with a **gradient accumulator**, combining the stability of long memory with responsiveness to recent gradients.
129
+ - **Key insight**: Classical momentum **does not accelerate** in noisy (small-batch) regimes; this accumulator do.
130
+
131
+ #### Tunable Hyperparameters
132
+ | Parameter | Default | Tuning Guide |
133
+ |----------|---------|--------------|
134
+ | `beta1` | 0.99 | Controls accumulator memory length:<br>• Small BS: **0.99–0.9999**<br>• Large BS: **0.9** |
135
+ | `Grad α` | 100 | Most critical parameter:<br>• Inversely scales with batch size<br>• **100–10** for small BS (≤32)<br>• **1–0.1** for large BS (≥512) |
136
+
137
+ > ⚠️ **Critical**: Requires **~100x smaller learning rate** than AdamW (e.g., 1e-6 vs 1e-4).
138
+ > For `Prodigy_Adv`, set `initial_d` to:
139
+ > - **LoRA**: `1e-8`
140
+ > - **Full FT**: `1e-10`
141
+ > - **Embedding**: `1e-7`
142
+
143
+ > ⚠️ **Incompatible** with: **Cautious**, **Grams**, **atan2**, and standard gradient clipping.
144
+
145
+ #### Performance Validation
146
+
147
+ **Small Batch Training (SDXL, BS=2, 1.8K steps)**
148
+ ![Training Comparison](https://github.com/user-attachments/assets/7eff0671-cc59-47fc-8b63-d5205456d649)
149
+
150
+ - **🟢 Prodigy_Adv** (beta1=0.9, d0=1e-5): Final LR = 2.9e-4
151
+ - **🔵 Prodigy_Adv + Simplified_AdEMAMix** (beta1=0.99, α=100, d0=1e-7): Final LR = 5.8e-6
152
+
153
+ **Results**:
154
+ - Faster convergence and higher final performance with Simplified_AdEMAMix
155
+ - D-Adaptation automatically compensates for aggressive updates
156
+ - Generated samples show **significantly better quality**
157
+
158
+ ---
159
+
160
+ ### atan2
161
+
162
+ - Replaces `eps` in Adam-family optimizers with a **scale-invariant**, bounded update rule.
163
+ - Automatically clips updates to **[-2, 2]**, preventing destabilizing jumps.
164
+ - **Highly recommended** for `Adopt_Adv`, which is prone to instability without clipping.
165
+
166
+ ---
167
+
168
+ ### **Kourkoutas-β**
169
+
170
+ **Kourkoutas-β** introduces a **sunspike-driven, layer-wise adaptive second-moment decay (β₂)** as an optional enhancement for `Adam_Adv`, `Adopt_Adv`, `Prodigy_Adv`, and `Simplified_AdEMAMix`.
171
+
172
+ Instead of using a fixed β₂ (e.g., 0.999 or 0.95), it **dynamically modulates β₂ per layer** based on a bounded *sunspike ratio*:
173
+
174
+ - **During gradient bursts** → β₂ ↓ toward `Lower β₂` → faster reaction
175
+ - **During calm phases** → β₂ ↑ toward `The Selected β₂` → stronger smoothing
176
+
177
+ This is especially effective for **noisy training, small batch sizes, and high learning rates**, where gradient norms shift abruptly due to noise or aggressive LR schedules.
178
+
179
+ #### Pros/Cons
180
+
181
+ | **Category** | **Details** |
182
+ |--------------|-------------|
183
+ | ✅ **Pros** | • **Layer-wise adaptation** blends benefits of high β₂ (strong smoothing) and low β₂ (fast reaction).<br>• **Robust to sudden loss landscape shifts**, reacts quickly during gradient bursts, smooths during calm phases.<br>• **High tolerance to aggressive learning rates**. |
184
+ | ⚠️ **Cons** | • **Potentially unstable at the start of training** due to unreliable early gradient norms; mitigated by using `K-β Warmup Steps`. |
185
+
186
+ > 💡 **Best Practice**: Set `K_warmup_steps` equal to your standard LR warmup steps. During warmup, the optimizer uses the static `beta2`; adaptation begins only after warmup ends.
187
+
188
+ > 🔍 **Debugging Aid**: Enable `K_Logging` to monitor (min, max, mean) of dynamic β₂ values across layers every *N* steps.
189
+
190
+ #### 📊 Performance Validation
191
+
192
+ **ADAMW_ADV - full SDXL finetuning (aggressive LR: 3e-5) (BS=4, 2.5K steps)**
193
+ <img width="1460" height="382" alt="image" src="https://github.com/user-attachments/assets/007f278a-fbac-4f3d-9cc7-274c3b959cdd" />
194
+
195
+ - 🟣 Fixed `beta2=0.999`
196
+ - 🟠 Auto K-beta
197
+
198
+ **Observations:**
199
+ - K-beta is clearly better and more robust/stable for high LRs.
200
+
201
+ > 📚 **Reference**:
202
+ > - Paper: [Kourkoutas-β: A Sunspike-Driven Adam Optimizer with Desert Flair](https://arxiv.org/abs/2508.12996)
203
+ > - Code: [kbeta](https://github.com/sck-at-ucy/kbeta)
204
+
205
+ ---
206
+
207
+ ## Recommended Preset (Tested on LoRA/FT/Embedding)
208
+
209
+ ```yaml
210
+ Learning Rate: 1
211
+ optimizer: PRODIGY_Adv
212
+ settings:
213
+ - beta1: 0.99 # Controls momentum decay, ~100-step effective memory. Adjust to 0.999 (1000 steps) or 0.9999 (10000 steps) based on training length and stability needs.
214
+ - beta2: 0.999
215
+ - kourkoutas_beta: True # For Kourkoutas-β
216
+ - K-β Warmup Steps: 50 # Or 100, 200, depending on your run
217
+ - Simplified_AdEMAMix: True
218
+ - Grad α: 100
219
+ - OrthoGrad: True
220
+ - weight_decay: 0.0
221
+ - initial_d:
222
+ • LoRA: 1e-8
223
+ • Full fine-tune: 1e-10
224
+ • Embedding: 1e-7
225
+ - d_coef: 1
226
+ - d_limiter: True # To stablizie Prodigy with Simplified_AdEMAMix
227
+ - factored: False # Can be true or false, quality should not degrade due to Simplified_AdEMAMix’s high tolerance to 1-bit factorization.
228
+ ```
229
+
230
+ > ✅ **Why it works**:
231
+ > - `Kourkoutas-β` handles beta2 values
232
+ > - `Simplified_AdEMAMix` ensures responsiveness in small-batch noise
233
+ > - `OrthoGrad` prevents overfitting without weight decay
234
+
235
+ ---
236
+
237
+ ## 📚 References
238
+
239
+ 1. [Revisiting BFloat16 Training](https://arxiv.org/abs/2010.06192)
240
+ 2. [SMMF: Square-Matricized Momentum Factorization](https://arxiv.org/abs/2412.08894)
241
+ 3. [The AdEMAMix Optimizer](https://arxiv.org/abs/2409.03137)
242
+ 4. [Connections between Schedule-Free Optimizers, AdEMAMix, and Accelerated SGD](https://arxiv.org/abs/2502.02431)
243
+ 5. [AdaMeM: Memory Efficient Momentum for Adafactor](https://openreview.net/forum?id=fZqMVTz7K5)
244
+ 6. [Kourkoutas-β: A Sunspike-Driven Adam Optimizer with Desert Flair](https://arxiv.org/abs/2508.12996)
@@ -16,4 +16,4 @@ __all__ = [
16
16
  "Lion_Prodigy_adv",
17
17
  ]
18
18
 
19
- __version__ = "1.1.0.dev5"
19
+ __version__ = "1.1.2"
@@ -10,7 +10,7 @@ from ..util.Kourkoutas import KourkoutasHelper
10
10
 
11
11
  class AdamW_adv(torch.optim.Optimizer):
12
12
  """
13
- Implements a factored AdamW algorithm.
13
+ Implements an advanced AdamW algorithm.
14
14
  This is an advanced version of AdamW with optional features like
15
15
  low-rank factorization of optimizer states (SMMF), OrthoGrad, etc.
16
16
 
@@ -67,7 +67,7 @@ class AdamW_adv(torch.optim.Optimizer):
67
67
  "sunspike" ratio calculation to prevent division by zero. Corresponds
68
68
  to `ε_spike` in the paper. (default: 1e-9)
69
69
  k_warmup_steps (int): The number of initial steps during which β₂ is held
70
- at a fixed average value (`(beta2_min + beta2_max) / 2`) before the
70
+ at a fixed beta2 value before the
71
71
  dynamic logic activates. (default: 0)
72
72
  k_logging (int): if > 0 and kourkoutas_beta=True, enables periodic console
73
73
  logging of Kourkoutas-β statistics (min, max, mean of `β₂` across layers)
@@ -10,7 +10,7 @@ from ..util.Kourkoutas import KourkoutasHelper
10
10
 
11
11
  class Adopt_adv(torch.optim.Optimizer):
12
12
  """
13
- Implements a fusion of SMMF, and the ADOPT algorithm.
13
+ Implements an advanced ADOPT algorithm.
14
14
 
15
15
  The ADOPT update rule modifies Adam by:
16
16
  1. **Initialization:** The second moment `v` is initialized as `v₀ = g₀²`.
@@ -85,7 +85,7 @@ class Adopt_adv(torch.optim.Optimizer):
85
85
  "sunspike" ratio calculation to prevent division by zero. Corresponds
86
86
  to `ε_spike` in the paper. (default: 1e-9)
87
87
  k_warmup_steps (int): The number of initial steps during which β₂ is held
88
- at a fixed average value (`(beta2_min + beta2_max) / 2`) before the
88
+ at a fixed beta2 value before the
89
89
  dynamic logic activates. (default: 0)
90
90
  k_logging (int): if > 0 and kourkoutas_beta=True, enables periodic console
91
91
  logging of Kourkoutas-β statistics (min, max, mean of `β₂` across layers)