[PR #10] [MERGED] serve: read short prompt parts through the decode windows (~1 s faster first token) #2413

Closed
opened 2026-11-04 01:59:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/10
Author: @Mirtraxxx
Created: 9/26/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @Niko1221

Base: main ← Head: short-read


📝 Commits (2)

  • 23f6b15 serve: conversation cache - keep the chat between requests, read only what is new
  • 9d9351b serve: read short prompt parts through the decode windows

📊 Changes

5 files changed (+411 additions, -34 deletions)

View changed files

📝 README.md (+2 -2)
📝 docs/DETAILS.md (+8 -3)
📝 include/strata/core/mtp.hpp (+2 -0)
📝 serve/server.py (+4 -0)
📝 src/program/generate.cpp (+395 -29)

📄 Description

Builds on #8. This branch is #8 plus one commit (9d9351b); only that commit is new here. I can rebase it once #8 is merged or changed.

What it does

The batched prompt path has a fixed cost of ~300 ms per run however few tokens it reads: it streams every non-resident expert the chunk routes to over PCIe. On top of that, refilling the 1,131 expert-cache slots it borrows takes ~180 ms. So "hi" waited ~1.4 s for its first token. With #8, every chat follow-up paid the same fixed cost for a message of a few dozen tokens plus the 6-token assistant header.

Now each part of the prompt (up to the turn checkpoint, then the header) picks its own path:

  • A part of at most --short-read N tokens (default 64, 0 = off) goes through the verify windows, S tokens at a time, as decode reads them: ver.run → ver.commit → mtp.prefill, with misses on the CPU pool. That's ~16 ms a token.
  • Longer parts, and parts with picture rows, stay batched. So a long first message is read batched, and its header still goes through the windows.
  • The slots are lent just before a batched run and refilled before a window read, so windows always see the whole expert cache. If the prompt ends on a batched part, the refill happens at the end, as before.
  • STRATA_CKPT_REREAD keeps every read batched, so it still compares a checkpoint against a batched re-read.

Measured

RTX 3090, Ryzen 7 5700X, 64 GB DDR4, Windows 11, Swift 1.5 IQ2_XS, --serve --expert-cache auto --spec 4 --adapt-swaps 0. Old and new engine back to back, same flags.

old new
First token, "hi" (13 tokens) 1.37 s 0.35 s
First token, 22-56 token prompts 1.25-1.53 s 0.41-0.85 s
Follow-up turn in a 5K-token chat (13-34 new tokens) 1.11-1.25 s 0.30-0.53 s
First turn, 5K tokens: the header part 340-358 ms 131 ms
Long prompt, 7,685 tokens 362 tok/s 359 tok/s
Decode, 966 tokens over 3 prompts 52.5 tok/s 53.9 tok/s

Output: greedy answers match the batched path except at near-ties, which the two paths round differently. On one prompt the first token flipped, and I dumped the logits to check it: "Think" 23.09 vs "Imagine" 23.02 through the windows, 23.03 vs 22.90 batched. The windows are the same computation decode uses.

Only tested on Windows / one machine, text prompts. Picture rows always take the batched path, so image prompts should be unaffected, but I haven't tested that.

🤖 Generated with Claude Code


🔄 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/Niko1221/Strata/pull/10 **Author:** [@Mirtraxxx](https://github.com/Mirtraxxx) **Created:** 9/26/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@Niko1221](https://github.com/Niko1221) **Base:** `main` ← **Head:** `short-read` --- ### 📝 Commits (2) - [`23f6b15`](https://github.com/Niko1221/Strata/commit/23f6b15b6b8078eccd6947aa44fa96ae816c051b) serve: conversation cache - keep the chat between requests, read only what is new - [`9d9351b`](https://github.com/Niko1221/Strata/commit/9d9351b9abdda139cb41913b9e0ed6d96444c7e3) serve: read short prompt parts through the decode windows ### 📊 Changes **5 files changed** (+411 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+2 -2) 📝 `docs/DETAILS.md` (+8 -3) 📝 `include/strata/core/mtp.hpp` (+2 -0) 📝 `serve/server.py` (+4 -0) 📝 `src/program/generate.cpp` (+395 -29) </details> ### 📄 Description **Builds on #8.** This branch is #8 plus one commit (9d9351b); only that commit is new here. I can rebase it once #8 is merged or changed. ## What it does The batched prompt path has a fixed cost of ~300 ms per run however few tokens it reads: it streams every non-resident expert the chunk routes to over PCIe. On top of that, refilling the 1,131 expert-cache slots it borrows takes ~180 ms. So "hi" waited ~1.4 s for its first token. With #8, every chat follow-up paid the same fixed cost for a message of a few dozen tokens plus the 6-token assistant header. Now each part of the prompt (up to the turn checkpoint, then the header) picks its own path: - A part of at most `--short-read N` tokens (default 64, `0` = off) goes through the verify windows, S tokens at a time, as decode reads them: `ver.run` → `ver.commit` → `mtp.prefill`, with misses on the CPU pool. That's ~16 ms a token. - Longer parts, and parts with picture rows, stay batched. So a long first message is read batched, and its header still goes through the windows. - The slots are lent just before a batched run and refilled before a window read, so windows always see the whole expert cache. If the prompt ends on a batched part, the refill happens at the end, as before. - `STRATA_CKPT_REREAD` keeps every read batched, so it still compares a checkpoint against a batched re-read. ## Measured RTX 3090, Ryzen 7 5700X, 64 GB DDR4, Windows 11, Swift 1.5 IQ2_XS, `--serve --expert-cache auto --spec 4 --adapt-swaps 0`. Old and new engine back to back, same flags. | | old | new | |---|---:|---:| | First token, "hi" (13 tokens) | 1.37 s | **0.35 s** | | First token, 22-56 token prompts | 1.25-1.53 s | **0.41-0.85 s** | | Follow-up turn in a 5K-token chat (13-34 new tokens) | 1.11-1.25 s | **0.30-0.53 s** | | First turn, 5K tokens: the header part | 340-358 ms | 131 ms | | Long prompt, 7,685 tokens | 362 tok/s | 359 tok/s | | Decode, 966 tokens over 3 prompts | 52.5 tok/s | 53.9 tok/s | Output: greedy answers match the batched path except at near-ties, which the two paths round differently. On one prompt the first token flipped, and I dumped the logits to check it: "Think" 23.09 vs "Imagine" 23.02 through the windows, 23.03 vs 22.90 batched. The windows are the same computation decode uses. Only tested on Windows / one machine, text prompts. Picture rows always take the batched path, so image prompts should be unaffected, but I haven't tested that. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 01:59:55 +07:00
Sign in to join this conversation.
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
Niko1221/Strata#2413
No description provided.