fix(paddle): freeze DPA3 descriptor parameters - #5802
Conversation
Apply Paddle stop_gradient to non-trainable DPA3 parameters after construction and after deserialization replaces child layers. Coding-Agent: Codex Codex-Version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDPA3 now applies Paddle’s ChangesDPA3 trainability lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Possible reviewers based on changed lines, exact file history, and exact-file review history:
No review request was made automatically. Coding agent: Codex |
Closes #5686.
Summary
stop_gradientflag instead of assigning a PyTorch-stylerequires_gradattribute;_apply_trainable();Root cause
Paddle's autograd contract is
parameter.stop_gradient. On the project's minimum supported Paddle 3.0.0, assigningparameter.requires_gradmerely adds an unrelated Python attribute and leavesstop_gradient=False, so optimizers can still update a descriptor configured withtrainable=False.Construction was not the only affected path.
DescrptDPA3.deserialize()constructs a descriptor and then replaces several registered child layers with freshly deserialized parameters. The descriptor-level freeze therefore needs to run again after all replacements are complete.Why existing tests missed this
Existing DPA3 consistency tests compare numerical outputs and serialization behavior, but do not inspect Paddle autograd flags. A model can produce identical inference values while its supposedly frozen parameters remain trainable.
The regression temporarily masks newer Paddle's
requires_gradcompatibility alias, retaining the minimum-version semantics even in nightly CI. It then requires every named parameter to havestop_gradient=Trueboth immediately after construction and after a round-trip. Enablingadd_chg_spin_ebd=Trueensures the optional replacement paths are included.Old-fail / new-pass validation
3.4.0.dev20260310: failed with the same 17 parameters under the minimum-version compatibility seam;3.4.0.dev20260310: round-trip failed with 28 unfrozen parameters;3.4.0.dev20260310: regression plus existing DPA3 consistency test passed (2 passed).Additional checks:
ruff format .;ruff check .;git diff --check;Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests