allenai / allenai/OLMo-core

[Bug] DionConfig incorrectly scales LM head learning rate for AdamW + Proposal for Dion3 integration

未關閉
#854 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
1.5k
分支
315
平均合併
1 天 9 小時
30 天內合併 PR
11

描述

### Summary
In `olmo_core/optim/dion.py` (line 98), the default LM head override divides the learning rate by `math.sqrt(model_dim)` when setting up the AdamW group:

```python
lm_head_override = OptimGroupOverride(
params=params["lm_head"],
opts=dict(algorithm="adamw", lr=self.lr / math.sqrt(model_dim)),
)
```

### Problem & Upstream Discrepancy

According to the reference implementation in `microsoft/dion` (`train.py`):

```python
def lm_head_lr_scale(scalar_opt: str, model_dim: int) -> float:
# See Dion paper App. D.2 and Fig. 14 for the Lion-specific 1 / sqrt(d_in) scale.
return 1 / math.sqrt(model_dim) if scalar_opt == "lion" else 1.0

```

The $1/\sqrt{d_{\text{in}}}$ scaling factor is explicitly Lion-specific because Lion uses `sign()` updates and cannot adjust for the growing gradient variance across wider embeddings. (See [Dion paper](https://arxiv.org/html/2504.05295v2#A4).)

Because OLMo uses **AdamW** for `lm_head`, the second-moment accumulator ($\sqrt{v}$) already normalizes the update magnitude. Applying `self.lr / math.sqrt(model_dim)` double-penalizes the layer, collapsing the effective learning rate (e.g., from `3e-4` down to `~8.4e-6` on a 1280-dim model) and preventing the projection head from training properly.

---

### Potential Contributions & Next Steps

I am happy to put together a PR (or split into two PRs) to address this and modernize the integration:

1. **Bug Fix PR:**
* Remove the $1/\sqrt{d_{\text{model}}}$ divisor when `algorithm == "adamw"` (or gate it strictly to `algorithm == "lion"` if Lion support is added).
* Ensure `lm_head` runs at the intended base scalar learning rate.

2. **Dion3 / Modernization PR:**
* Update `_import_dion()` and `DionConfig` to support the latest Dion3 release (`NorDion2`), exposing options for fractional updates (`fraction=0.25`), `selection_scope`, and megabatching.
* Update `MatrixAwareOptimConfig` parameter categorization to support 3D+ tensors (such as local 1D convolutions in hybrid architectures) via `flatten=True` rather than asserting and exiting.

Please let me know if you would like me to open a PR for the LM head fix first, or if you prefer a broader PR updating the integration to Dion3!

貢獻指南

開啟貢獻指南

研究方向

Start in olmo_core/optim/dion.py at line 98 and inspect how the AdamW lm_head override sets its learning rate. Compare that behavior with the lm_head_lr_scale logic in microsoft/dion's train.py. Done means the AdamW lm_head uses the intended base learning rate without the Lion-specific scaling; the separate Dion3 modernization proposals are broader follow-up work.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python, pytorch
領域
machine-learning
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
活躍
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。