deepmodeling / deepmodeling/deepmd-kit
[Code scan] Honor documented fparam/aparam shorthand in dpmodel DeepEval
- 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 dpmodel `DeepEval` backend documents broadcastable `fparam` and `aparam` input forms, but `_eval_model()` reshapes them directly to full multi-frame shapes.
The backend docstring says a single `dim_fparam` vector applies to all frames, and that `aparam` may be provided as `natoms x dim_aparam` or `dim_aparam` shorthand:
https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/infer/deep_eval.py#L209-L219
`_eval_model()` instead reshapes `fparam` directly to `(nframes, dim_fparam)`:
https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/infer/deep_eval.py#L349-L352
It also reshapes `aparam` directly to `(nframes, natoms, dim_aparam)`:
https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/infer/deep_eval.py#L353-L356
For `nframes > 1`, the documented shorthand arrays have too few elements for those reshapes and are rejected instead of being tiled.
The higher-level inference wrapper already implements this tiling contract:
https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/infer/deep_eval.py#L854-L875
## Impact
Users calling the dpmodel backend directly can pass parameter arrays that the API explicitly documents as valid, only to get reshape failures for multi-frame inference.
## Suggested fix
Normalize `fparam` and `aparam` in the dpmodel backend using the same size checks and tiling behavior as the higher-level inference wrapper. Add regressions for multi-frame dpmodel inference with `fparam.shape == (dim_fparam,)`, `aparam.shape == (natoms, dim_aparam)`, and `aparam.shape == (dim_aparam,)`.
Contributor guide
Research direction
Start in deepmd/dpmodel/infer/deep_eval.py at _eval_model() and compare its fparam/aparam handling with the tiling behavior in deepmd/infer/deep_eval.py. Add regression coverage for multi-frame inputs using the three documented shorthand shapes, and verify that dpmodel inference accepts them without reshape failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100