deepmodeling / deepmodeling/deepmd-kit
fix(loss): normalize global RMSE display metrics per frame for mixed-size batches
- Dominant language
- Python
- Stars
- 2k
- Forks
- 649
- Avg merge
- 6d 18h
- Merged PRs (30d)
- 15
Description
## Context
Follow-up from #5738 and its review thread: https://github.com/deepmodeling/deepmd-kit/pull/5738#discussion_r3563253502
#5738 correctly makes the **global loss** padding-invariant and does not need to expand scope for this display-only refinement. However, for masked `mixed_type` batches with unequal real atom counts, the reported global `rmse_*` metrics still compute a batch RMSE and divide it by `mean(real_natoms)`. That is not equivalent to normalizing each frame before aggregating.
For example, with real atom counts `[3, 5]` and extensive errors `[3, 5]` (per-atom error 1 in each frame), the current summary is:
```text
sqrt((3² + 5²) / 2) / 4 = 1.0308
```
while processing either frame alone reports `1`.
## Scope
For masked paths, define the global display metric as an aggregation of **per-frame normalized squared errors**, for example:
```python
sqrt(mean(mean(diff**2, axis=-1) / real_natoms**2))
```
Apply the same semantics consistently to:
- global DOS and CDF `rmse_*` displays;
- global `TensorLoss` `rmse_*` displays;
- their PyTorch (`deepmd/pt/loss/`) mirrors.
Likely touch points are `deepmd/dpmodel/loss/{dos,tensor}.py` and `deepmd/pt/loss/{dos,tensor}.py`.
## Acceptance criteria
- The training objective and gradients remain unchanged; this issue concerns diagnostics/display metrics only.
- A mixed-size masked batch reports the same normalized global RMSE as the corresponding per-frame calls, under the chosen aggregation semantics.
- All-ones / non-masked behavior remains unchanged from `master`.
- Tests cover an unequal-size batch (e.g. `[3, 5]`) for DOS, CDF, and tensor paths in both implementations.
— OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.6-terra)
Contributor guide
Assessment
This issue has not been assessed yet.