mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #524] [CLOSED] DeepSeek: cache-budgeted Engram prompt read-ahead #579
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#579
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/524
Author: @handmade0octopus
Created: 10/26/2026
Status: ❌ Closed
Base:
main← Head:pr/ds4-engram-prefetch📝 Commits (1)
ef55627DeepSeek: cache-budgeted Engram prompt read-ahead📊 Changes
7 files changed (+572 additions, -27 deletions)
View changed files
📝
README.md(+7 -0)📝
docs/SETTINGS.md(+29 -0)📝
src/ds4/ds4_engram_io.hpp(+224 -3)📝
src/ds4/ds4_main.cpp(+8 -0)📝
src/ds4/ds4_model.cu(+290 -19)📝
src/ds4/ds4_model.hpp(+3 -1)📝
src/ds4/ds4_os.hpp(+11 -4)📄 Description
Summary
Add opt-in, cache-budgeted Engram prompt read-ahead for one-GPU DeepSeek serving.
0remains explicit whole-prompt and positive values select a fixed compute-chunk look-ahead.std::sortfallbacks. Add aligned Windows unbuffered reads with buffered fallback.The feature is off by default. Decode does not use the prefetcher, and the row bytes supplied to the model are unchanged.
Motivation
On the Windows test machine, small random Engram reads plateaued at about 13.2k aligned reads/s. Long prompts left the GPU idle while the two Engram tables were read, and a short look-ahead could overwrite rows before their consuming layer.
This PR addresses both the I/O layout and the scheduling/policy problem rather than increasing reader-thread count.
Measurements
Test system: Windows 11, RTX 4090 D 48 GiB, Ryzen 5 3600, 128 GiB RAM, WD_BLACK SN850X NVMe; DeepSeek-V4.1-Flash IQ1_M with the 110.6 GB IQ4_NL Engram file.
Matched seeded 65,566-token prompts, fresh engine for each run, first request after boot, zero KV/prefix reuse, with all unrelated engine/configuration choices held constant:
Approximately 4.34× prefill throughput, with no swap growth. The baseline generated one token and the candidate generated 32, so the wall-time comparison includes slightly more decode work in the candidate.
The real-engine planner reduced per-layer sort time from 348.0/345.0 ms with indirect
std::sortto 57.1/56.3 ms with checked radix32. A standalone 24M-lookup/layer planning benchmark improved from 37.24 s to 2.68 s for two layers; this is a planning benchmark, not an end-to-end 1M-context claim.A final cleaned-config run read 32,798 fresh prompt tokens at 966.5 t/s, then generated 1,024 tokens at 34.0 t/s, with zero reuse and no swap growth. A separate small-window run generated 256 tokens at 33.3 t/s.
Correctness and robustness validation
std::sort/radix32 × dedup on/off) produced identical ordered payload hashes for both Engram layers and zero failed reads.ahead=1passed zoned/non-zoned and chunk-/layer-major cases; every consumer lookup was a cache hit.ahead=2at 512 MiB and exactlyahead=1at 384 MiB, with 1,574,304/1,574,304 consumer hits and no deadlock.finish=cancel, returned to idle in 22.47 s, and a subsequent natural request succeeded. This demonstrates wakeup/recovery, not instantaneous cancellation.upstream/mainbranch also built and passed a direct-engine 16,384-token request: automatic whole-prompt planning, checked radix32, 4 MiB zones, 16 generated tokens, zero reuse, and graceful QUIT. Its accounting matched the plans exactly: 786,432 lookups = 756,112 served without reads + 30,320 canonical physical read attempts.The row-hash and direct zone-check diagnostics used for validation are not required in production and are not included in this PR.
Related work / overlap check
This extends the bounded row cache and asynchronous reads from #275/#295 rather than proposing another cache. It builds on the Windows reader concurrency and unbuffered I/O from #361/#362, while preserving the RAM-only behavior from #368. It concerns Engram rows, not the CPU-lane expert-page prefetch in #425. The cancellation changes integrate the new worker with the existing stop path (#337); they do not replace server cancellation. No end-to-end 1M support is claimed here (#442 is context/setup work).
Notes
The automatic budget covers row payload/live-set planning, not all process memory. Hash indexes, scratch arrays, reader buffers, and model state require additional RAM. If even one bounded look-ahead unit cannot fit the estimate, the ordinary read path remains in use.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.