[PR #318] [MERGED] DeepSeek long prompts skip layers 20-39 where the answer does not need them, exact #463

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/318
Author: @mw00
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @mw00

Base: main ← Head: rel-1119


📝 Commits (1)

  • 208f77e DeepSeek long prompts skip layers 20-39 where the answer does not need them, exact

📊 Changes

2 files changed (+161 additions, -38 deletions)

View changed files

📝 docs/SETTINGS.md (+14 -0)
📝 src/ds4/ds4_model.cu (+147 -38)

📄 Description

DeepSeek-V4.1-Flash's layers 20-39 see a prompt's earlier tokens only through layer 20's compressed KV and index keys,
and each looks back one 128-token window more than the layer before - so they need their own work only on the last
(40 - 20) x 127 + 128 = 2,668 tokens of a prompt for its last rows and the decode's rings to be what the full work gives
(DeepSeek's own deployment notes: rebuilding them exactly "would require running the last 2,560 tokens through 20
decoder layers"; their serving replays 128). A long prompt (3,692+ new tokens) now skips the rest:

  • The chunks stay as they are. Those before the cut go through layers 0-19 and layer 20's kv_only (layer_chunk: the
    hyper-connection pre-norm, the compressor latent, the index keys, the compressed KV - nothing of its attention or
    experts); the cut's chunk through layers 20-39 from the cut on only (a view of its buffers from that row,
    run_layer); the chunks after it through every layer. The flow plans no experts for the skipped (chunk, layer)s and
    sizes its early reads by the rows a layer runs on, so each layer's experts are read as without the skip.
  • The answers stay the same up to the order the experts' outputs are added in (the logits of a prompt's last row
    against the full work: KL 1.5e-4, the same greedy tokens); DeepSeek's 128-row replay as an option shifts them more.
  • MAYA_DS4_PROMPT_SKIP: 1 (the default, one GPU) the exact skip, 2 DeepSeek's serving's (the last 128 tokens only), 0
    off. Several GPUs read prompts as before. docs/SETTINGS.md: "DeepSeek: long prompts read without the second half's
    work".

🔄 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/318 **Author:** [@mw00](https://github.com/mw00) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `rel-1119` --- ### 📝 Commits (1) - [`208f77e`](https://github.com/mw00/project-maya/commit/208f77e138310b8638e5673005de8ad7d35534dc) DeepSeek long prompts skip layers 20-39 where the answer does not need them, exact ### 📊 Changes **2 files changed** (+161 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+14 -0) 📝 `src/ds4/ds4_model.cu` (+147 -38) </details> ### 📄 Description DeepSeek-V4.1-Flash's layers 20-39 see a prompt's earlier tokens only through layer 20's compressed KV and index keys, and each looks back one 128-token window more than the layer before - so they need their own work only on the last (40 - 20) x 127 + 128 = 2,668 tokens of a prompt for its last rows and the decode's rings to be what the full work gives (DeepSeek's own deployment notes: rebuilding them exactly "would require running the last 2,560 tokens through 20 decoder layers"; their serving replays 128). A long prompt (3,692+ new tokens) now skips the rest: - The chunks stay as they are. Those before the cut go through layers 0-19 and layer 20's kv_only (layer_chunk: the hyper-connection pre-norm, the compressor latent, the index keys, the compressed KV - nothing of its attention or experts); the cut's chunk through layers 20-39 from the cut on only (a view of its buffers from that row, run_layer); the chunks after it through every layer. The flow plans no experts for the skipped (chunk, layer)s and sizes its early reads by the rows a layer runs on, so each layer's experts are read as without the skip. - The answers stay the same up to the order the experts' outputs are added in (the logits of a prompt's last row against the full work: KL 1.5e-4, the same greedy tokens); DeepSeek's 128-row replay as an option shifts them more. - MAYA_DS4_PROMPT_SKIP: 1 (the default, one GPU) the exact skip, 2 DeepSeek's serving's (the last 128 tokens only), 0 off. Several GPUs read prompts as before. docs/SETTINGS.md: "DeepSeek: long prompts read without the second half's work". --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:43 +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#463
No description provided.