Skip to content

[Code scan] Freeze Paddle DPA3 parameters with stop_gradient #5686

Description

@njzjz

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:

# set trainable
for param in self.parameters():
param.requires_grad = trainable

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

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

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions