Enhance remote checkpoint loading with parallel mmap chunk downloading (#21868) - #21869
Open
yuxin00j wants to merge 10 commits into
Open
Enhance remote checkpoint loading with parallel mmap chunk downloading (#21868)#21869yuxin00j wants to merge 10 commits into
yuxin00j wants to merge 10 commits into
Conversation
yuxin00j
requested review from
ethanwharris,
justusschock and
tchaton
as code owners
July 30, 2026 08:12
for more information, see https://pre-commit.ci
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #21869 +/- ##
=======================================
- Coverage 87% 87% -0%
=======================================
Files 270 270
Lines 24069 24153 +84
=======================================
+ Hits 20904 20972 +68
- Misses 3165 3181 +16 |
…ard mmap with torch version
…cloud_io coverage
…d Windows CI compatibility
…32') to avoid NTFS share-read locks preventing checkpoint deletion
…t caching to prevent corrupted cache on interruption
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.
What does this PR do?
Fixes #21868
This PR optimizes
lightning.fabric.utilities.cloud_io._load()for monolithic, multi-gigabyte checkpoints stored on remote object stores by replacing sequential streaming reads with multiprocess parallel chunk downloads and zero-copy memory mapping (mmap=True).Motivation and Context
Currently, loading large remote checkpoints via
_load()streams bytes sequentially. This underutilizes network bandwidth and forces Python to allocate heap buffers for incoming data while simultaneously constructing unpickled model tensors in memory, causing severe restore bottlenecks and high transient heap RAM spikes.Summary of Changes
_download_chunk_mmap()helper: Implements parallel chunk writes into a pre-allocated file usingmmap.mmap()and explicitmm.flush()._load(): Remote filesconcurrent.futures.ProcessPoolExecutor(spawncontext, up to 16 workers)./dev/shm/ disk): Checkpoints are cached in/dev/shmif free space exceedstempfile.gettempdir().FileLock: Eliminates redundant downloads by synchronizing processes across multi-GPU/multi-node setups; only one process downloads the file while others reuse the cache.torch.load(..., mmap=True)for both local paths and downloaded remote caches, significantly cutting peak heap RAM requirements.os.remove) if chunk downloading fails or is interrupted.docs/source-pytorch/common/remote_fs.rstandsrc/lightning/fabric/CHANGELOG.md.Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
Reviewer checklist