Skip to content

[User Experience] Muon optimizer 支持 lr_ratio#79466

Open
LCStayingdullCircuit wants to merge 2 commits into
PaddlePaddle:developfrom
LCStayingdullCircuit:fix/muon_support_lr_ratio
Open

[User Experience] Muon optimizer 支持 lr_ratio#79466
LCStayingdullCircuit wants to merge 2 commits into
PaddlePaddle:developfrom
LCStayingdullCircuit:fix/muon_support_lr_ratio

Conversation

@LCStayingdullCircuit

@LCStayingdullCircuit LCStayingdullCircuit commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

PR Category

User Experience

PR Types

New features

Description

Add lr_ratio support for Muon optimizer. This change uses effective_lr = learning_rate * lr_ratio(param) in the Muon orthogonal update path, and applies it to both decoupled weight decay and the final parameter update. When lr_ratio is None, the behavior remains unchanged.

Validation: PR diff does not include new tests.

是否引起精度变化

@LCStayingdullCircuit LCStayingdullCircuit force-pushed the fix/muon_support_lr_ratio branch from 8cc513b to 9d36f14 Compare July 13, 2026 06:23
PaddlePaddle-bot

This comment was marked as outdated.

@LCStayingdullCircuit LCStayingdullCircuit changed the title fix: muon支持lr_ratio [User Experience] Muon optimizer 支持 lr_ratio Jul 13, 2026
PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已复查当前提交。Muon 主路径的 lr_ratio 实现方向与 AdamW 的学习率缩放语义一致,但这个数值行为还缺少直接回归测试,细节已放在行级评论里。

  • P0 优先级:P0 非行级:PR 描述/CI 模板检查无法附到 changed diff 行。当前 ### 是否引起精度变化 仍为空,CI 日志明确报错“必须填写是否引起精度变化”,会阻塞合入。请在 PR 描述中填写“是”或“否”;如果填写“是”,请补充影响范围和验证方式,并等待模板检查通过。
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 优先级:P1
处理要求:请针对该评论修复并提交新的 commit。

这里把 lr_ratio 接入了 Muon 主更新路径,并同时影响 decoupled weight decay 和 final_step,属于优化器数值行为变更。但当前提交只修改了 python/paddle/optimizer/muon.py,仓库里 Muon 相关测试没有任何一处传入 lr_ratio=test/ai_edited_test/test_ai_optimizer_muon.py 也仍未覆盖这条新增路径。后续如果只缩放 final_step、漏掉 weight decay,或把 lr_ratio=None 兼容路径改坏,现有测试发现不了。

请补一个直接覆盖 Muon 2D 参数路径的回归测试,至少验证 lr_ratio=0.0 不更新参数、lr_ratio=0.5 的参数更新量是 lr_ratio=1.0 的一半,并开启 weight_decay > 0 覆盖本行下面的衰减逻辑。测试形态可以参考:

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,
    )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 优先级:P1
处理要求:请针对该评论继续修复并提交新的 commit。

这次提交新增的 test_freeze_parameter 已覆盖 lr_ratio=0.0 冻结路径,并且因为启用了 weight_decay=0.01,也能防止 0 比例时参数被 decoupled weight decay 误衰减;这部分可以认为已补上。

剩下还缺少非零比例的数值回归:当前测试只断言另一个参数“发生了变化”,没有验证 lr_ratio=0.5 的更新量确实是 lr_ratio=1.0 的一半。这样如果后续只对 final_step 缩放、漏掉非零 ratio 下的 weight decay 缩放,或者把非零 ratio 当成 1.0 处理,现有测试仍可能通过。

请继续补齐 0.5 vs 1.0 的比例断言,例如把更新逻辑抽成 helper 后增加类似检查:

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,
)

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已复查当前 PR 描述和 head。标题与“是否引起精度变化”说明已经补齐,之前的模板字段缺失项已解决;当前代码 head 没有新增测试提交,已有行级线程中的 Muon lr_ratio 回归测试缺口仍需通过新的 commit 修复。

  • P0 优先级:P0 非行级:CI/审批状态无法附到 changed diff 行。最新 Check PR Template 已能识别精度变化说明,但检查转为失败在精度变更审批上:日志显示缺少 required approver sneaxiy 的 approval。请完成对应精度变更审批并等待该检查通过。
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

@LCStayingdullCircuit

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已复查新提交。新增的 lr_ratio=0 冻结测试解决了原意见的一部分,但还缺少非零比例缩放的回归断言,细节已补充在既有行级线程中。

  • P0 优先级:P0 非行级:CI/审批状态无法附到 changed diff 行。当前 Check PR Template 仍因精度变化缺少 sneaxiy approval 失败;Check approval 还提示新增内容包含中文,需要相应 RD approval,或移除新增中文文本后重跑检查。请补齐这些审批/检查后再合入。
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Paddle-CI-Agent | pr_review | 2026-07-13 16:26:57

📋 Review 摘要

PR 概述:为 Muon optimizer 的正交更新路径接入 lr_ratio,并补充冻结参数场景测试。
变更范围python/paddle/optimizer/muon.pytest/ai_edited_test/test_ai_optimizer_muon.py
影响面 Tag[User Experience]

问题

未发现阻塞性问题。PR 规范问题在下面章节报,不在这里重复。

历史 Findings 修复情况

Finding 问题 状态
F1 新增的 lr_ratio Muon 主更新路径没有同步测试覆盖。 ✅ 已修复

📝 PR 规范检查

已修复:当前标题包含官方 [User Experience] Tag,PR 描述包含必填 sections,### 是否引起精度变化 已填写为 并说明了 lr_ratio 对学习率和 decoupled weight decay 的影响范围。

总体评价

当前实现将 lr_ratio(param) 转为 effective_lr,并同时用于 Muon 参数的 decoupled weight decay 和最终 orthogonal update;lr_ratio is None 时保持原学习率路径。新增单测构造 use_muon=True 的参数并通过 lr_ratio=0 验证冻结参数不被 weight decay 或主更新改动,已覆盖此前缺失的主路径回归场景。

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@8817599). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #79466   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         5           
  Branches           ?         0           
===========================================
  Hits               ?         5           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paddle-bot

paddle-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@LCStayingdullCircuit

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@LCStayingdullCircuit

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants