[Code scan] Freeze Paddle DPA3 parameters with stop_gradient

Open Beginner friendly
#5,686 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start in deepmd/pd/model/descriptor/dpa3.py at the parameter-freezing pass around lines 251-253, then compare the corresponding logic in se_a.py and dpa2.py. Replace the ineffective trainable-state handling with the Paddle pattern shown in the issue, and verify that non-trainable DPA3 descriptor parameters remain frozen during training.

Written by the indexing model from the issue text.

Description

bug

This issue comes from a Codex global scan of deepmodeling/deepmd-kit at commit 73de44b1f94471b2e3bdb6b11f57b34d7bc791bb.

Problem

The Paddle DPA3 descriptor tries to honor trainable=False by setting param.requires_grad = trainable:

https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/pd/model/descriptor/dpa3.py#L251-L253

Other Paddle descriptors freeze parameters with stop_gradient, which is the Paddle parameter flag used by autograd:

https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/pd/model/descriptor/se_a.py#L528-L531

https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/pd/model/descriptor/dpa2.py#L331-L333

Impact

Users configuring a non-trainable Paddle DPA3 descriptor can still update descriptor parameters during training because the freeze pass writes a PyTorch-style attribute instead of Paddle's stop_gradient flag. DPA3's RepFlow/MLP parameters rely on this outer descriptor freeze pass, so the requested freeze does not take effect.

Suggested fix

Use the same Paddle pattern as the neighboring descriptors:

for param in self.parameters():
    param.stop_gradient = not trainable

If Paddle exposes any additional trainable-state APIs in the supported versions, keep this consistent across all Paddle descriptor wrappers.

Dominant language
Python
Stars
2k
Forks
651
Avg merge
6d 1h
Merged PRs (30d)
18

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from deepmodeling/deepmd-kit

All issues in deepmodeling/deepmd-kit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.