deepmodeling / deepmodeling/deepmd-kit

[Code scan] Freeze Paddle DPA3 parameters with stop_gradient

Open Beginner friendly
#5,686 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
2k
Forks
649
Avg merge
6d 18h
Merged PRs (30d)
15

Description

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:

```python
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.

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.