Skip to content

Serve token_embd.weight from the host mapping under DS4_EMBD_MMAP (default OFF) - #690

Open
nexus-cw wants to merge 1 commit into
antirez:mainfrom
nexus-cw:embd-host-mapping
Open

Serve token_embd.weight from the host mapping under DS4_EMBD_MMAP (default OFF)#690
nexus-cw wants to merge 1 commit into
antirez:mainfrom
nexus-cw:embd-host-mapping

Conversation

@nexus-cw

@nexus-cw nexus-cw commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Addresses #688.

token_embd.weight is accessed one row (~8-16 KB) per decoded token but held fully resident (~1 GiB on DeepSeek V4 Flash Q8_0). With DS4_EMBD_MMAP=1 (default OFF):

  • ds4.c: startup span preparation leaves token_embd.weight out of the resident device spans (logged).
  • ds4_cuda.cu: cuda_model_range_ptr resolves the token_embd label to the read-only host model mapping instead of a resident copy, so row lookups are served at page-cache speed.

Measured on GB10 (DeepSeek V4 Flash Q8_0, streaming, ctx 131072): -1010 MiB resident, warm decode within run-to-run noise (4.25/4.28/4.36 vs 4.19/4.23/4.33 t/s), no cold-prefill cost, worst case a one-time ~2.5 s first-token transient after a full page-cache drop, recovered by the next request. Full numbers in #688.

Caveat, stated plainly: this relies on unified-memory ATS/HMM pageable access (GB10/Grace class) -- the GPU reads the file-backed host pages directly. Discrete-GPU targets would need the cudaHostRegister'd-mapping path that cuda_model_range_ptr already has for the same idea; that is honest future work, and the env gate defaults OFF precisely so non-unified targets are unaffected.

Build: make cpu clean (x86_64), ds4_cuda.o + ds4.o compile clean with nvcc (arm64 GB10). Companion observability work: #687 / its PR.

🤖 Generated with Claude Code

token_embd.weight is accessed one row (~8-16 KB) per decoded token but
held fully resident on the device (~1 GiB on DeepSeek V4 Flash Q8_0).
With DS4_EMBD_MMAP=1 (default OFF) the startup span preparation leaves
the table out of the resident device spans and the embed path resolves
it to the read-only host model mapping instead, so row lookups are
served at page-cache speed.

Measured on a GB10 streaming deployment: -1010 MiB resident, warm
decode within run-to-run noise (4.25/4.28/4.36 vs 4.19/4.23/4.33 t/s),
no cold-prefill cost, worst case a one-time ~2.5 s transient after a
full page-cache drop.

Caveat: this relies on unified-memory ATS/HMM pageable access (GB10 /
Grace class); discrete-GPU targets would need the cudaHostRegister'd
mapping path for the same idea. The env gate defaults OFF precisely so
non-unified targets are unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants