Repository navigation
fix(stat): cap data-stat batches at the available batches per system - #6099
ShryukGrandhi wants to merge 1 commit into
Conversation
The backend-agnostic collect_batches/make_stat_input used by TF, JAX and pt_expt drew data_stat_nbatch batches from every system, wrapping around and resampling systems with fewer batches. The PT backend stops at the dataloader length. Cap the count at the system's batch count so small systems are not overweighted and the backends collect the same frames. Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
njzjz-bot
left a comment
There was a problem hiding this comment.
Agent: dot
Source LGTM at 7558f37. I checked the changed helper against DeepmdDataSystem's per-system get_nbatches() list, both collection call paths, the existing LMDB-specific hook precedence, and the pair-clearance scan behavior. The fallback now caps small systems instead of wrapping; explicit statistical-system hooks still take precedence, and sources without either count hook retain their previous behavior.
Independent verification: 31 assertions executing the exact helper/collector source with NumPy and bounded data/normalization/filter doubles passed, covering zero/small/large batch counts, requested limits, dedicated-hook precedence, legacy sources, merged/unmerged collect_batches, make_stat_input, and the filter-enabled count bound. This is not a native backend integration run. I also inspected the added 3/7-frame cross-backend regression and updated cyclic fixture. The author's reported native runs are supplementary evidence, not independently rerun here: this environment has no PyTorch, and TF/JAX/GPU execution is unverified.
Current CI is not green acceptance: seven workflows are action_required awaiting approval (including Test Python/C++/CUDA); only triage/labeler ran successfully. No source-blocking finding from this review.
Summary
The backend-agnostic data-stat helpers in
deepmd/utils/model_stat.py(collect_batches, used by TF, andmake_stat_input, used by JAX/pt_expt) always drewdata_stat_nbatchbatches from every system. For aDeepmdDataSystem, a system with fewer batches than that wraps around and gets resampled, so small systems are overweighted in the statistics. The PT backend instead stops aftermin(data_stat_nbatch, len(dataloader))batches. The same input could therefore produce different descriptor/output statistics depending on the backend.Changes
_get_stat_numb_batchesnow caps the batch count at the system's available batches whenever the data source exposes them: through the existingget_stat_numb_batcheshook (LMDB) or, as a fallback,get_nbatches()(DeepmdDataSystem). This reuses_get_stat_pass_length, which already encoded that lookup for the pair-clearance filter path. Data sources that expose neither keep the old behavior.TestMakeStatInputSmallSystemsinsource/tests/consistent/test_make_stat_input.py: builds two systems with 3 and 7 frames, usesdata_stat_nbatch=10, and checks that the universal path,collect_batches, and the PT path all collect exactly 3 and 7 frames.test_disabled_filter_takes_the_next_batchesintest_dist_check.py, which asserted the old wrap-around (a 2-frame system sampled as[0, 1, 0]); it now expects[0, 1].Testing
pytest source/tests/consistent/test_make_stat_input.py: the new test fails before the fix (10 != 3 : system 0, key 'atype': nframes mismatch) and passes after it.pytest source/tests/consistent/test_make_stat_input.py source/tests/common/dpmodel/test_dist_check.py source/tests/pt_expt/test_lmdb_training.py: 71 passed, 1 skippedpytest source/tests/pt_expt/test_training.py: 45 passed, 18 skippedruff check/ruff formaton the touched files: cleanTensorFlow was not installed locally, so the TF-specific tests were not run. The TF path goes through the same
collect_batches, and the new test exercises it directly.Fixes #5594
Summary by CodeRabbit