Repository navigation
Pin BatchData so DataLoader pin_memory takes effect - #7
Merged
Merged
Conversation
DataLoader(pin_memory=True) pins only objects that expose pin_memory(), so BatchData batches were copied host->device synchronously from pageable memory. Add BatchData.pin_memory() and copy with non_blocking=True. Note in train_folds.md that num_workers must scale with example size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pin_memory=True(the CUDA default) was a silent no-op forBatchData: torch's pin thread pins only objects that exposepin_memory(). Every batch was copied host→device synchronously from pageable memory.BatchData.pin_memory()pins every non-None tensor._unpack_batch/_mlm_unpackcopy withnon_blocking=True.train_folds.md: sizenum_workersto the example size.On an H100 at 786 kb × 8361 targets, batch 4, the copy goes from 0.175 s to 0.063 s, about 3–5% of step time. The pinned cache adds ~28 GB of host RAM at 16 workers, so a memory-limited host can set
pin_mem: false.Tests: new
test_batchdata_pin_memory(CUDA only); the dataset, train, MLM, multidataset and sampler suites pass.🤖 Generated with Claude Code