Skip to content

llama : reuse the tensor staging buffer and skip the direct-io bounce buffer - #31321

Merged
am17an merged 1 commit into
masterfrom
aman/loader-staging-reuse
Oct 29, 2026
Merged

am17an merged 1 commit into
masterfrom
aman/loader-staging-reuse

Conversation

@am17an

@am17an am17an commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Overview

Without mmap, tensors in non-host buffers that can't use the async upload path (RPC, -sm row/-sm tensor split buffers, CPU repack buffers, --check-tensors) are loaded through a staging buffer. Today that buffer is allocated per tensor, so its pages are faulted again for every tensor, and with -lm dio read_raw also bounces each tensor through read_aligned_chunk.

This PR:

  • keeps one staging buffer for the whole load, reallocated only when it is too small or more than 2x what the current tensor needs (tensors are already loaded biggest-first)
  • with direct IO, reads the aligned range around the tensor straight into an aligned spot in that buffer and uploads from the offset inside it, so there is no bounce buffer

Split out from #29413.

Additional information

Requirements

@am17an
am17an requested a review from a team as a code owner October 28, 2026 15:19
am17an added a commit that referenced this pull request Oct 28, 2026

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave it a spin on my RTX PRO 6000 with gemma-4-12b and --no-mmap: with --check-tensors on CUDA the load goes from 6.5s to 2.9s, CPU repack is about twice as fast too, and RPC on localhost is a bit quicker. Same outputs as master, LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants