Repository navigation
Opt-in coalesced reads for overlapping lazy FIF windows - #1511
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Tested the coalesced-read commit 2384f93b against stack parent 6b3dd995, with execution on final head 5dc4a91a. On recorded PhysioNet S001R04 converted to lazy FIF, a 16-window overlapping batch takes one reader call instead of 16. All 504 exported sample/target arrays match the parent byte-for-byte; unaugmented samples also match the standard MNE reader. Cases include cropped/reordered channels, variable window lengths and channel targets. Double-precision FIF, projections, preloaded data and adjacent windows retain the fallback behavior.
In-place stochastic augmentation preserves data and NumPy/Python/CPU-Torch RNG state with 0/2 DataLoader workers. Two Adam updates of ShallowFBCSPNet on each of CPU/CUDA give identical losses, model/optimizer/gradient hashes and next NumPy/Python/CPU-Torch RNG state with the option on/off and on the parent. Environment: torch 2.7.0+cu128, MNE 1.13.2, RTX 5070. The added test file passes 95 tests with 9 optional Zarr skips.
No additional defect found in these paths. This checks recorded-data/training parity; I did not reproduce timing/RSS claims or review the rest of the stack.
BaseConcatDataset(..., coalesce_reads=False) is keyword-only and off by default. When enabled, a DataLoader batch of consecutive, overlapping windows of one lazy FIF recording is read as one bounded union of samples instead of one read per window; every other batch takes the unchanged default path. Samples, targets, crop indices, order and RNG use are equal to the default. Part of braindecode#1489.
5dc4a91 to
b51530f
Compare
Summary
Part of #1489.
With overlapping windows, for example 4 s windows every 1 s, a DataLoader batch of consecutive windows from one lazy FIF recording reads most samples several times.
BaseConcatDataset(..., coalesce_reads=True)reads such a batch as one bounded union of samples and cuts the windows out of it. The option is off by default.Changes
benchmarks/acceleration/bench_coalesced_reads.py: the standalone benchmark behind the numbers below. It imports only braindecode, so this PR does not depend on the benchmark-tooling PR.braindecode/datasets/base.py:BaseConcatDataset(..., coalesce_reads=False); non-bool values are rejected;__getitems__coalesces a batch only if (one check,_get_coalesced_items):EEGWindowsDataset;[min start, max stop)of its crops is at most a third of the summed window samples, and at most 2 MiB;WindowsDataset;_finish_window: float32 copy, transform, targets, channel mask), which__getitem__now also calls, so they cannot drift apart; default outputs are byte-identical to upstream;False, outputs are unchanged;coalesce_reads=False.whats_newentry under Enhancements.Defaults
The default stays off, so nothing changes without
coalesce_reads=True. With it on, samples, targets, crop indices, order and RNG use are equal to the default path.Evidence
Tests
test/unit_tests/datasets/test_coalesced_reads.py(new) covers:Some variable-length batches with gaps now coalesce where the previous version of this PR did not; outputs are identical (the equality matrix covers variable and unsorted layouts), and none of the measured cells changes eligibility, but their speed is unmeasured.
Branch tip
b51530f34999(tree6b541a30bf71) on upstreammasterec07f32, after the earlier PRs of the series merged with exactly their verified trees. This tree is byte-identical to the one verified inbdw3-stack-verify-4-20261031t211836z-371a1219(default suite, pre-commit, slow tier, CI collection and docs all passed). Every check ran in one Voyager CPU Job,bdw3-stack-verify-3-20261031t201512z-cca0e0cc(its docs step was re-run inbdw3-stack-docs-1after a fix to the check script):pytest test/ -n 8from the repository root at this tip: 6,493 passed, 375 skipped, 2 xfailed, 0 failed. Upstreammasterunder the same settings: 5,995 passed, 375 skipped, 1 xfailed.pre-commit run --files <files changed by this PR>, with the repository's pinned hooks (Ruff, mypy, docstrfmt, blacken-docs, codespell, sphinx-lint): passed.Open review point
The
whats_newentry and thecoalesce_readsdocstring list the cells that failed the acceleration gate: 4 workers on overlapping windows; adjacent windows and cross-recording batches with 2 workers. Whether to keep that wording for the adjacent-window cell is still open, and it is left unchanged here.