Skip to content

fix(pt-expt): group LMDB statistics by atom count#5828

Merged
OutisLi merged 3 commits into
deepmodeling:masterfrom
OutisLi:pr/lmdb
Jul 17, 2026
Merged

fix(pt-expt): group LMDB statistics by atom count#5828
OutisLi merged 3 commits into
deepmodeling:masterfrom
OutisLi:pr/lmdb

Conversation

@OutisLi

@OutisLi OutisLi commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • expose fixed-nloc statistical partitions for PT-experimental LMDB data while preserving one logical training dataset
  • let the common statistics collector consume shape-compatible partitions and cap sampling to each partition's available batches
  • add regression coverage for mixed-nloc statistics packing and end-to-end PT-experimental training

Test plan

  • python -m pytest source/tests/pt_expt/test_lmdb_training.py source/tests/consistent/test_make_stat_input.py -v
  • repository pre-commit hooks, including Ruff and pylint
  • full OMat24 initialization (intentionally omitted because of dataset size; covered by synthetic mixed-nloc tests)

Summary by CodeRabbit

  • New Features
    • Added statistical data collection and batching across statistical systems, including support for mixed fixed-atom-count frames in LMDB datasets.
    • Exposed per-statistical-system access to batch retrieval and system/batch counts for trainer workflows.
  • Documentation
    • Clarified how statistical views are computed independently from the underlying training dataset.
    • Expanded statistical input semantics for variable atom counts and per-system packing behavior.
  • Tests
    • Added coverage for mixed-nloc LMDB statistics and end-to-end training with statistical batching enabled.

Expose fixed-nloc statistical partitions without changing the LMDB's logical dataset identity, preventing mixed-size batches from being concatenated during model-stat initialization. Add regression coverage for statistics packing and end-to-end mixed-nloc training.
Copilot AI review requested due to automatic review settings July 16, 2026 04:39
@dosubot dosubot Bot added the enhancement label Jul 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a64d64ff-a080-4ed3-9e37-c6c2d95bdef9

📥 Commits

Reviewing files that changed from the base of the PR and between d73862b and 77a6511.

📒 Files selected for processing (2)
  • deepmd/utils/model_stat.py
  • source/tests/pt_expt/test_lmdb_training.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/utils/model_stat.py

📝 Walkthrough

Walkthrough

LmdbDataSystem now exposes per-nloc statistical systems and batches. model_stat uses these APIs when available, while retaining fallbacks for existing data sources. Tests cover mixed-nloc LMDB statistics and end-to-end training.

Changes

LMDB statistical batching

Layer / File(s) Summary
Per-nloc LMDB statistical API
deepmd/pt_expt/utils/lmdb_dataset.py
Tracks fixed-nloc groups, provides collated statistical batches with cycling offsets, reports statistical system and batch counts, and documents the single logical training dataset.
Shape-compatible statistics integration
deepmd/utils/model_stat.py
Adds optional statistical-system helpers with fallbacks, and updates statistic collection and system-count handling.
Mixed-nloc validation and training
source/tests/pt_expt/test_lmdb_training.py
Adds mixed-nloc LMDB fixtures and verifies separated shape groups, batch limits, offset cycling, and end-to-end trainer execution.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Trainer
  participant model_stat
  participant LmdbDataSystem
  participant LMDB
  Trainer->>model_stat: make_stat_input(data)
  model_stat->>LmdbDataSystem: get_stat_nsystems()
  model_stat->>LmdbDataSystem: get_stat_numb_batches(sys_idx)
  loop statistical systems and batches
    model_stat->>LmdbDataSystem: get_stat_batch(sys_idx)
    LmdbDataSystem->>LMDB: load nloc-group frames
    LMDB-->>LmdbDataSystem: frame data
    LmdbDataSystem-->>model_stat: collated batch
  end
  model_stat-->>Trainer: statistical input
Loading

Possibly related PRs

Suggested labels: bug

Suggested reviewers: iprozd, njzjz

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: LMDB statistics are grouped into fixed atom-count partitions while preserving one logical training dataset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deepmd/utils/model_stat.py`:
- Line 46: Rename the unused loop variable jj to _jj in both loops in
deepmd/utils/model_stat.py at lines 46-46 and 84-84, preserving the loop
behavior while satisfying Ruff B007.

In `@source/tests/pt_expt/test_lmdb_training.py`:
- Around line 300-301: Update test_mixed_nloc_statistics_and_training with the
project’s pytest timeout decorator configured for 60 seconds, and add the pytest
import if it is not already present. Preserve the test’s existing body and
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 227d9aed-6591-4c45-9079-5381272dd296

📥 Commits

Reviewing files that changed from the base of the PR and between 1c5ff68 and d73862b.

📒 Files selected for processing (3)
  • deepmd/pt_expt/utils/lmdb_dataset.py
  • deepmd/utils/model_stat.py
  • source/tests/pt_expt/test_lmdb_training.py

Comment thread deepmd/utils/model_stat.py
Comment thread source/tests/pt_expt/test_lmdb_training.py
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.33%. Comparing base (d155800) to head (77a6511).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
deepmd/pt_expt/utils/lmdb_dataset.py 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5828      +/-   ##
==========================================
- Coverage   78.57%   78.33%   -0.24%     
==========================================
  Files        1050     1050              
  Lines      120549   120677     +128     
  Branches     4351     4354       +3     
==========================================
- Hits        94718    94530     -188     
- Misses      24267    24587     +320     
+ Partials     1564     1560       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@OutisLi
OutisLi requested a review from wanghan-iapcm July 16, 2026 08:54

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core fix is correct and well-tested: grouping frames by atom count into fixed-nloc partitions is sound, the min(nbatches, ceil(nframes/bs)) cap and sequential offset-with-wraparound visit every frame once per pass, the _collate_indices extraction is behavior-preserving, and the getattr-based shims fall back byte-identically to the legacy get_nsystems()/get_batch(sys_idx=) path for non-LMDB datasets (TF/jax/pd). test_stat_input_partitions_mixed_nloc_batches genuinely fails pre-fix (a single-system LMDB would concatenate ragged mixed-nloc shapes). LGTM.

Two non-blocking follow-ups:

  1. Batch-count test coverage. The new test uses 4 frames with batch_size=2 — evenly divisible, so it cannot distinguish the correct ceil-division in get_stat_numb_batches from a floor-division regression, and it never exercises the offset-wraparound reset or the undersampling case (nbatches smaller than available). This is exactly the class of bug that shipped in #5488 (floor-division under-reporting batch counts in the sibling pt LMDB dataloader), caught only when reviewers added non-divisible-boundary tests. Please add a case with a non-divisible frame count (e.g. 5 frames at batch_size=2) and an undersampling case to lock the counting contract.

  2. Stale Parameters docstring. In deepmd/utils/model_stat.py the make_stat_input summary now mentions that data sources may expose dedicated statistical-system methods, but the Parameters blocks of both make_stat_input and collect_batches still document the contract as only "must support get_nsystems() and get_batch(sys_idx=)". Since the implementation now probes get_stat_nsystems/get_stat_numb_batches/get_stat_batch and they change the effective per-shape system count, please name those three optional hooks in the Parameters section so the documented contract matches the code.

@OutisLi
OutisLi enabled auto-merge July 17, 2026 03:07
@OutisLi
OutisLi added this pull request to the merge queue Jul 17, 2026
Merged via the queue into deepmodeling:master with commit 32881be Jul 17, 2026
57 checks passed
@OutisLi
OutisLi deleted the pr/lmdb branch July 17, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants