Commit e37cc00
authored
fix(data): preserve LMDB label availability across batches (#5839)
Fixes #5636
## Summary
- cache each LMDB frame availability signature from lightweight msgpack
metadata
- partition training, statistics, auto-probability, and distributed
batches by both atom count and scalar `find_*` signature
- allocate each auto-probability block target exactly across all
homogeneous groups with deterministic integer largest-remainder
apportionment
- retain the existing scalar loss contract and reject heterogeneous
collation defensively
- reset pt_expt sampling after data requirements change
- split full LMDB validation by atom count and availability so
default-filled labels are excluded from metrics
Simply stacking `find_*` values would not be safe here. Current PyTorch
and dpmodel losses reduce a whole batch before applying scalar
availability flags, and display/validation paths convert those flags to
booleans. A vector flag would broadcast incorrectly, produce
vector-valued losses, or fail boolean conversion. Homogeneous batching
is the smaller compatible fix.
## Why existing tests missed this
The direct collator test used `find_energy=1` in every frame and did not
assert the flag value. All LMDB factories stored energy and force in
every record, so same-nloc batching was also label-homogeneous by
accident. Reader consistency tests inspect individual frames before
collation, and loss tests construct homogeneous scalar flags without
connecting them to LMDB batches. Auto-probability tests also used one
availability signature, so they could not expose independent
per-signature rounding that changed a block target of 3 into 4 sampled
frames.
Full-validation coverage only varied atom count. `LmdbTestData`
therefore always observed globally present labels, and no test combined
real labels with default-filled frames or checked order-independent
optional-label metrics.
## Validation
- common dpmodel LMDB, PyTorch LMDB, and full-validation suites: 137
passed, 3 subtests passed
- isolated pt_expt LMDB data-system suite: 4 passed
- review-focused common/PT/pt_expt LMDB suites: 36 passed through the
pure-Python path (the locally installed optional PyTorch custom-op
library has a stale ABI)
- regression verifies an auto-probability target of 3 remains exactly 3
across two availability groups and sampler length stays exact
- regression verifies energy and force defaults contribute zero loss
when their corresponding `find_*` flag is zero
- regression consumes the pre-requirement pt_expt iterator and verifies
it is replaced before availability-homogeneous batching
- regression verifies energy and force full-validation metrics use only
their two labeled frames
- `ruff format .`
- `ruff check .`
Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Bug Fixes**
- LMDB training batching now partitions by both atom count and
consistent scalar label-availability flags, ensuring batches don’t mix
incompatible `find_*` settings.
- Batch collation now raises an error when label-availability flags
conflict across frames.
- Full validation now groups evaluation by atom count and label
availability so default-filled/missing labels don’t skew metrics.
- **Performance / Behavior**
- LMDB dataset loaders are now built lazily and refresh immediately
after adding new label requirements.
- **Tests**
- Added coverage for partially labeled LMDB batching, validator
grouping, and block-target distribution across label-availability
signatures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: njzjz-bot <njzjz.bot@gmail.com>1 parent dd0e511 commit e37cc00
8 files changed
Lines changed: 860 additions & 116 deletions
File tree
- deepmd
- dpmodel/utils
- pt_expt/utils
- pt
- train
- utils
- source/tests
- common/dpmodel
- pt_expt
- pt
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
434 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
435 | 436 | | |
436 | 437 | | |
437 | 438 | | |
438 | 439 | | |
439 | | - | |
440 | | - | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
441 | 444 | | |
442 | 445 | | |
443 | 446 | | |
444 | 447 | | |
445 | | - | |
446 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
447 | 452 | | |
448 | 453 | | |
449 | 454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
178 | 182 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
192 | 209 | | |
193 | 210 | | |
194 | 211 | | |
| |||
229 | 246 | | |
230 | 247 | | |
231 | 248 | | |
| 249 | + | |
232 | 250 | | |
233 | 251 | | |
234 | 252 | | |
| |||
328 | 346 | | |
329 | 347 | | |
330 | 348 | | |
331 | | - | |
332 | | - | |
| 349 | + | |
| 350 | + | |
333 | 351 | | |
334 | 352 | | |
335 | 353 | | |
336 | | - | |
| 354 | + | |
337 | 355 | | |
338 | | - | |
339 | | - | |
| 356 | + | |
| 357 | + | |
340 | 358 | | |
341 | | - | |
| 359 | + | |
342 | 360 | | |
343 | 361 | | |
344 | 362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
783 | 815 | | |
784 | 816 | | |
785 | 817 | | |
| |||
0 commit comments