Skip to content

Prefetch mmap'd weight blobs to eliminate page fault bottleneck#18356

Merged
manuelcandales merged 1 commit into
release/1.2from
cherry-pick-18236-by-pytorch_bot_bot_
Mar 20, 2026
Merged

Prefetch mmap'd weight blobs to eliminate page fault bottleneck#18356
manuelcandales merged 1 commit into
release/1.2from
cherry-pick-18236-by-pytorch_bot_bot_

Conversation

@pytorchbot
Copy link
Copy Markdown
Collaborator

Weight loading via update_constants_from_blob was achieving only
0.3-0.4 GB/s (vs 8 GB/s hardware capability) because memcpy from
mmap'd pages triggers synchronous page faults — each 16K page traps
into the kernel for NVMe I/O.

Call madvise(MADV_WILLNEED) on the weights blob
early in Metal backend init, before writing/dlopen'ing the .so file.
The kernel prefaults pages asynchronously during the ~200ms of other
init work. By the time memcpy runs, pages are already resident and
throughput reaches 5-8 GB/s.

Metal init time: ~25s -> ~9s (2.7x faster) on int4 Voxtral model.

Weight loading via update_constants_from_blob was achieving only
0.3-0.4 GB/s (vs 8 GB/s hardware capability) because memcpy from
mmap'd pages triggers synchronous page faults — each 16K page traps
into the kernel for NVMe I/O.

Call madvise(MADV_WILLNEED) on the weights blob
early in Metal backend init, before writing/dlopen'ing the .so file.
The kernel prefaults pages asynchronously during the ~200ms of other
init work. By the time memcpy runs, pages are already resident and
throughput reaches 5-8 GB/s.

Metal init time: ~25s -> ~9s (2.7x faster) on int4 Voxtral model.

(cherry picked from commit b7ca1a4)
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 20, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18356

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 122 Pending

As of commit e3f3328 with merge base 8c0a60b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 20, 2026
@manuelcandales manuelcandales merged commit 2bba833 into release/1.2 Mar 20, 2026
201 of 204 checks passed
@manuelcandales manuelcandales deleted the cherry-pick-18236-by-pytorch_bot_bot_ branch March 20, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants