-
Notifications
You must be signed in to change notification settings - Fork 6k
[User Experience] Muon optimizer 支持 lr_ratio #79466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -606,6 +606,9 @@ def ortho_fn(m): | |
| self._master_weights[param.name] if find_master else None | ||
| ) | ||
|
|
||
| lr_ratio = 1.0 if self._lr_ratio is None else self._lr_ratio(param) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这里把 请补一个直接覆盖 Muon 2D 参数路径的回归测试,至少验证 def test_muon_lr_ratio_scales_muon_update(self):
paddle.disable_static()
weight_np = np.array([[0.2, -0.4], [0.6, 0.8]], dtype="float32")
grad_np = np.array([[0.1, 0.3], [-0.2, 0.4]], dtype="float32")
def run(ratio):
p = paddle.create_parameter(shape=[2, 2], dtype="float32")
p.set_value(weight_np)
p.grad = paddle.to_tensor(grad_np)
opt = Muon(
parameters=[p],
learning_rate=0.01,
weight_decay=0.01,
ns_steps=1,
ns_matmul_dtype=paddle.float32,
muon_param_info_map={p.name: MuonParamInfo(use_muon=True)},
lr_ratio=lambda _: ratio,
)
opt.step()
return p.numpy()
full = run(1.0)
half = run(0.5)
zero = run(0.0)
np.testing.assert_allclose(zero, weight_np, rtol=1e-6, atol=1e-6)
np.testing.assert_allclose(
weight_np - half,
0.5 * (weight_np - full),
rtol=1e-5,
atol=1e-6,
)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这次提交新增的 剩下还缺少非零比例的数值回归:当前测试只断言另一个参数“发生了变化”,没有验证 请继续补齐 full = run(ratio=1.0)
half = run(ratio=0.5)
np.testing.assert_allclose(
weight_np - half,
0.5 * (weight_np - full),
rtol=1e-5,
atol=1e-6,
) |
||
| effective_lr = lr * lr_ratio | ||
|
|
||
| with_decay = True | ||
| if ( | ||
| self._apply_decay_param_fun is not None | ||
|
|
@@ -614,11 +617,11 @@ def ortho_fn(m): | |
| with_decay = False | ||
| if with_decay and weight_decay > 0: | ||
| if find_master: | ||
| master_weight.scale_(1.0 - lr * weight_decay) | ||
| master_weight.scale_(1.0 - effective_lr * weight_decay) | ||
| else: | ||
| param.scale_(1.0 - lr * weight_decay) | ||
| param.scale_(1.0 - effective_lr * weight_decay) | ||
|
|
||
| final_step = orthogonal_update * lr | ||
| final_step = orthogonal_update * effective_lr | ||
|
|
||
| if find_master: | ||
| master_weight.subtract_(final_step) | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.