[PR #524] [CLOSED] DeepSeek: cache-budgeted Engram prompt read-ahead #579

Closed
opened 2026-10-29 21:27:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • ef55627 DeepSeek: 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.

  • Fill the existing Engram row cache before the consuming layers, with consumers waiting for their own published units rather than racing the prefetcher.
  • Choose whole-prompt or bounded look-ahead from a 75%-of-cache live-set budget. 0 remains explicit whole-prompt and positive values select a fixed compute-chunk look-ahead.
  • Sort misses, coalesce them into bounded zone reads, and fill duplicate destinations from one canonical row.
  • Use radix32 only after every row proves its row-ID/offset mapping, with radix64 and std::sort fallbacks. Add aligned Windows unbuffered reads with buffered fallback.
  • Wake the prefetch worker on halt/abort and use post-consumption credits so bounded operation cannot run past its budget.
  • Keep sparse YOCO unit lists on the ordinary path, size layer credits from the pack's actual Engram-layer count, and restrict automatic bounded planning to chunk-major runs whose two-window estimate is valid.
  • Report prefetch rows/hits/physical reads and timing separately from the consumer's lookup/on-demand-read counters.

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:

Baseline This PR
Prefill throughput 300.5 t/s 1,304.4 t/s
Prefill time 218.214 s 50.264 s
Streaming TTFT — 50.472 s
Request wall time 218.437 s 51.861 s

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::sort to 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

  • Four fresh 64k runs (std::sort/radix32 × dedup on/off) produced identical ordered payload hashes for both Engram layers and zero failed reads.
  • A direct zone-vs-buffered-file diagnostic compared 94,841 canonical rows: 0 mismatches.
  • Post-sort dedup covered duplicate destinations, canonical-read failure, completion countdowns, and cache insertion.
  • Fixed ahead=1 passed zoned/non-zoned and chunk-/layer-major cases; every consumer lookup was a cache hit.
  • Automatic bounded tests selected ahead=2 at 512 MiB and exactly ahead=1 at 384 MiB, with 1,574,304/1,574,304 consumer hits and no deadlock.
  • Natural-answer, small-window, sustained-decode, and two idle shutdown checks passed.
  • Disconnecting an active 65,566-token prefill produced finish=cancel, returned to idle in 22.47 s, and a subsequent natural request succeeded. This demonstrates wakeup/recovery, not instantaneous cancellation.
  • The clean upstream/main branch 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.
  • After a clean rebase onto v1.1.29, the full 101-test server suite passed (3 platform skips), along with the 32-test DS4 conformance suite and an incremental Windows CUDA build.
  • Windows CUDA build and the HIP name-compatibility scan pass. Linux, AMD, and multi-GPU runtime behavior were not measured.

The row-hash and direct zone-check diagnostics used for validation are not required in production and are not included in this PR.

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.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/524 **Author:** [@handmade0octopus](https://github.com/handmade0octopus) **Created:** 10/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/ds4-engram-prefetch` --- ### 📝 Commits (1) - [`ef55627`](https://github.com/mw00/project-maya/commit/ef55627758d4fff4c226aa38879cac0d04b82143) DeepSeek: cache-budgeted Engram prompt read-ahead ### 📊 Changes **7 files changed** (+572 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description ## Summary Add opt-in, cache-budgeted Engram prompt read-ahead for one-GPU DeepSeek serving. - Fill the existing Engram row cache before the consuming layers, with consumers waiting for their own published units rather than racing the prefetcher. - Choose whole-prompt or bounded look-ahead from a 75%-of-cache live-set budget. `0` remains explicit whole-prompt and positive values select a fixed compute-chunk look-ahead. - Sort misses, coalesce them into bounded zone reads, and fill duplicate destinations from one canonical row. - Use radix32 only after every row proves its row-ID/offset mapping, with radix64 and `std::sort` fallbacks. Add aligned Windows unbuffered reads with buffered fallback. - Wake the prefetch worker on halt/abort and use post-consumption credits so bounded operation cannot run past its budget. - Keep sparse YOCO unit lists on the ordinary path, size layer credits from the pack's actual Engram-layer count, and restrict automatic bounded planning to chunk-major runs whose two-window estimate is valid. - Report prefetch rows/hits/physical reads and timing separately from the consumer's lookup/on-demand-read counters. 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: | | Baseline | This PR | | --- | ---: | ---: | | Prefill throughput | 300.5 t/s | **1,304.4 t/s** | | Prefill time | 218.214 s | **50.264 s** | | Streaming TTFT | — | **50.472 s** | | Request wall time | 218.437 s | **51.861 s** | 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::sort` to **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 - Four fresh 64k runs (`std::sort`/radix32 × dedup on/off) produced identical ordered payload hashes for both Engram layers and zero failed reads. - A direct zone-vs-buffered-file diagnostic compared **94,841 canonical rows: 0 mismatches**. - Post-sort dedup covered duplicate destinations, canonical-read failure, completion countdowns, and cache insertion. - Fixed `ahead=1` passed zoned/non-zoned and chunk-/layer-major cases; every consumer lookup was a cache hit. - Automatic bounded tests selected `ahead=2` at 512 MiB and exactly `ahead=1` at 384 MiB, with **1,574,304/1,574,304 consumer hits** and no deadlock. - Natural-answer, small-window, sustained-decode, and two idle shutdown checks passed. - Disconnecting an active 65,566-token prefill produced `finish=cancel`, returned to idle in 22.47 s, and a subsequent natural request succeeded. This demonstrates wakeup/recovery, not instantaneous cancellation. - The clean `upstream/main` branch 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**. - After a clean rebase onto v1.1.29, the full 101-test server suite passed (3 platform skips), along with the 32-test DS4 conformance suite and an incremental Windows CUDA build. - Windows CUDA build and the HIP name-compatibility scan pass. Linux, AMD, and multi-GPU runtime behavior were not measured. 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:27:07 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#579
No description provided.