Commit 1cd6556
fix(pd): preserve dtype in Paddle RepFlow dynamic aggregation (#5712)
## Problem
The Paddle `aggregate()` helper in `deepmd/pd/model/network/utils.py`
allocated its output with `paddle.zeros([num_owner, data.shape[1]])`
without specifying a dtype, so it fell back to Paddle's default floating
dtype (float32). It then cast the input `data` to `output.dtype` before
`index_add_`. For float64 Paddle RepFlow/DPA3 models, the
dynamic-selection aggregation therefore accumulated descriptor updates
in float32, silently downcasting intermediate values before returning
them to the descriptor path.
## Fix
Allocate the output with `dtype=data.dtype` so the input precision is
preserved (and the subsequent `data.astype(output.dtype)` becomes a
no-op for matching dtypes).
## Test
A new test aggregates float64 input and asserts the result stays float64
(and has the expected values). On the current code the output is
float32; after the fix it is float64. This exercises the shared `output
= paddle.zeros(..., dtype=data.dtype)` allocation via the summation
path.
## Note on verification
Verified locally with `paddlepaddle==3.3.1`. The CI target is a newer
nightly (`paddlepaddle==3.4.0.dev20260310`), but the behavior fixed here
is version-agnostic: `paddle.zeros` without `dtype` defaults to float32
in all versions, and `dtype=data.dtype` corrects it regardless. The test
is scoped to the summation path to keep it independent of an unrelated
`Tensor.where` API difference in the older local Paddle.
Fix #5688
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Preserved the input tensor’s numeric dtype when aggregating values,
preventing unintended dtype fallback during summation.
* **Tests**
* Added unit coverage to confirm aggregation keeps `float64` output
dtype and returns the expected summed values.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>1 parent e975e13 commit 1cd6556
2 files changed
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
0 commit comments