ITADN

[Code scan] Honor TensorFlow change-bias --numb-batch

#5684Opennjzjz 创建于 2026-06-30
bug
N
njzjzcommented
This issue comes from a Codex global scan of `deepmodeling/deepmd-kit` at commit `73de44b1f94471b2e3bdb6b11f57b34d7bc791bb`. ## Problem `change-bias --numb-batch` is documented as the number of frames to use per data system, with `0` meaning all data: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/main.py#L864-L870 The TensorFlow change-bias call stack threads `numb_batch` through `_change_bias_checkpoint_file()`: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/tf/entrypoints/change_bias.py#L134-L144 But the data-based bias path drops it and calls `_apply_data_based_bias(...)` without `numb_batch`: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/tf/entrypoints/change_bias.py#L231-L245 `_apply_data_based_bias()` then hard-codes `ntest=1` when computing the new bias: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/tf/entrypoints/change_bias.py#L377-L397 and `change_energy_bias_lower()` caps each system to `min(nframes, ntest)`: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/tf/fit/ener.py#L1040-L1044 ## Impact TensorFlow data-based `change-bias` always uses one frame per system regardless of `-n/--numb-batch`. Passing `-n 10` or relying on the documented `0 means all data` behavior does not affect the bias estimate. ## Suggested fix Pass `numb_batch` into `_apply_data_based_bias()` and forward it to `change_energy_bias_lower()` as `ntest`, preserving the existing `0 means all data` behavior if that helper needs a sentinel translation.
0 条评论