From 116cdf2a35d0946c50f1f6a59112c828de00a058 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 12 Nov 2026 22:40:12 +0100 Subject: [PATCH] serve: --short-read defaults to 24 where the staged fused entry reads short pieces With the staged group entry on (Windows gfx1151, a layer set with no MMQ tile that the fused kernels take, STRATA_PF_STAGED_FO not 0) a batched read of a short piece is cheaper than the verify windows from about 28 tokens. Strix Halo, UD-Q4_K_XL, prompt ms, median of 3 (windows / batched): 24 tokens 231 / 261, 32 tokens 303 / 265-270, 48 tokens 453 / 293-299, 64 tokens 598 / 314-316. The class default of --short-read is therefore 24 (the largest size measured where the windows win; 64 stays everywhere else). A --short-read on the command line wins; the setting is not part of the draft-cost table key unless it is given. --- include/strata/prefill/prefill.hpp | 4 ++++ include/strata/prefill/staged_fo_rule.hpp | 10 ++++++++++ src/prefill/prefill.cpp | 6 ++++++ src/program/generate.cpp | 8 ++++++-- tests/prefill/staged_fo_rule_test.cpp | 10 +++++++++- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/strata/prefill/prefill.hpp b/include/strata/prefill/prefill.hpp index 02040bb449..ea62fa8697 100644 --- a/include/strata/prefill/prefill.hpp +++ b/include/strata/prefill/prefill.hpp @@ -96,6 +96,10 @@ public: /// stages only the experts it routes to. 1024, or STRATA_PREFILL_STREAM_MIN, or the CPU share's limit once that /// is armed (3072 when STRATA_PREFILL_CPU_SHARE is set). static int64_t stream_all_min_tokens(); + /// --serve's `--short-read` default for this run: `base` (64), or, where the staged walk's fused entry takes the pieces below the floor on this class + /// (staged_fo_rule.hpp: Windows gfx1151, every layer without an MMQ tile and on the fused kernels, entry on), the measured crossing of the verify windows and that entry. + /// A `--short-read` given on the command line is not asked. Call once the expert layout is known. + static int64_t short_read_default(int64_t base); /// --prefill-pipe (opt-in): the chunk a layer split's first stage reads an `n`-token prompt in, for `stages` /// stages, chunks of at most `cap` (the buffers' size) and a stage-chunk cost of b + a C with b/a = `ratio` tokens /// (0: unknown - STRATA_PREFILL_EQUAL's rule: the same chunk count as `cap` gives, evened out when its last chunk diff --git a/include/strata/prefill/staged_fo_rule.hpp b/include/strata/prefill/staged_fo_rule.hpp index 1c508d9daa..75789eef83 100644 --- a/include/strata/prefill/staged_fo_rule.hpp +++ b/include/strata/prefill/staged_fo_rule.hpp @@ -24,6 +24,16 @@ inline bool staged_fo_decide(const char* env, bool class_default) { return class_default; } +/// `--short-read` (serve: pieces of at most N fresh tokens, compared without the last one, are read through the verify windows, longer ones batched), 64 by default. With the entry on +/// the batched read of a short piece is cheaper than the windows from about 28 tokens (Strix Halo, UD-Q4_K_XL, par/RESULTS-STRIX-SHORT.md job s8: 24 tokens windows 231 ms against 261 ms +/// batched; 32 tokens 303 against 265-270; 48 tokens 453 against 293-299; 64 tokens 598 against 314-316), so on that class the default is the largest size where the windows won. +inline constexpr long long kStagedEntryShortRead = 24; + +/// `base`: the engine's own default (64). `class_measured` / `all_layers_fused_only`: stream_floor_rule.hpp's class; `entry_on`: staged_fo_decide(). +constexpr long long short_read_default(long long base, bool class_measured, bool all_layers_fused_only, bool entry_on) { + return class_measured && all_layers_fused_only && entry_on ? kStagedEntryShortRead : base; +} + /// A layer the staged group entry may take on the layer-side rule: it has an MMQ tile (the entry's earlier rule), or it is fused-only and the entry is on (staged_fo_decide). /// The rest of the entry's conditions (native pack, no CPU share, no peer, no Hadamard fold, ...) stay where they are in prefill.cpp. constexpr bool staged_entry_layer(bool use_mmq, bool fused_only, bool fo_on) { return use_mmq || (fused_only && fo_on); } diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index c21b203864..68d17ee024 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -2996,6 +2996,12 @@ void Prefill::set_ring_budget(int slots, int64_t small_max) { } double Prefill::pinned_share() { return g_pinned_share; } int64_t Prefill::stream_all_min_tokens() { return stream_all_min(); } +int64_t Prefill::short_read_default(int64_t base) { + const auto& lay = strata::kernels::cpu::expert_layout(); + if (!lay.native || lay.fmt.empty()) return base; + const bool cls = stream_floor_class_measured(); + return strata::prefill::short_read_default(base, cls, cls && layers_all_fused_only(), staged_fo_on()); +} // --prefill-pipe (opt-in; STRATA_PREFILL_PIPE): a layer split reads a prompt as a pipeline - stage s reads chunk c while // stage s+1 reads chunk c-1. A stage-chunk costs its layers x (b + a C): a fixed part per chunk (b: the pass over the diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 30bf411bbe..468f515ef2 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -996,6 +996,7 @@ struct Options { /// result) goes through the verify windows, S tokens at a time, instead of the batched prompt path (0 = always /// the batched path) int64_t short_read = 64; + bool short_read_set = false; // --short-read given: the class default (Prefill::short_read_default) does not apply bool prefill_head_alias = false; // lend the native output head's VRAM to prompt buffers between request phases /// --pipeline-windows N (--serve, a layer split on exactly two GPUs; opt-in): 1 = a prompt's short reads through /// the verify windows run with the stages overlapped (stage 0 reads window K+1 while stage 1 reads window K); @@ -1180,7 +1181,8 @@ void usage() { " --tail-role-token ID --serve: a turn of this role right before the last turn is left out of\n" " the conversation checkpoint (a trailing effort turn; default -1 = off)\n" " --short-read N --serve: read at most N fresh text tokens through the decode windows instead\n" - " of the batched prompt path (default 64, 0 = off)\n" + " of the batched prompt path (default 64, or 24 on Windows Strix Halo with a\n" + " UD-Q4_K_XL set, where the batched path is quicker from 26 tokens; 0 = off)\n" " --prefill-head-alias --serve: unload the native output head while each fresh prompt is read,\n" " then release prompt buffers and reload it before decode\n" " --suffix-draft N prompt lookup: draft from an earlier repeat of the last N+ tokens of context\n" @@ -3786,7 +3788,7 @@ int main(int argc, char** argv) { else if (a == "--prompt-cache-root") o.prompt_cache_root = std::max(0LL, std::atoll(next("--prompt-cache-root"))); else if (a == "--turn-token") o.turn_token = std::atoll(next("--turn-token")); else if (a == "--tail-role-token") o.tail_role_token = std::atoll(next("--tail-role-token")); - else if (a == "--short-read") o.short_read = std::max(0LL, std::atoll(next("--short-read"))); + else if (a == "--short-read") { o.short_read = std::max(0LL, std::atoll(next("--short-read"))); o.short_read_set = true; } else if (a == "--prefill-head-alias") o.prefill_head_alias = true; else if (a == "--pipeline-windows") o.pipeline_windows = std::max(0, std::min(2, std::atoi(next("--pipeline-windows")))); else if (a == "--suffix-draft") o.suffix_draft = std::max(0, std::atoi(next("--suffix-draft"))); @@ -12252,6 +12254,8 @@ int main(int argc, char** argv) { // the verify windows after the batched part). The retry reads that tail batched (--short-read 0 for one request): // a reporter's prompts failed there every time and passed with --short-read 0. bool nf_prompt_windows = false, short_read_off_once = false; + // --short-read's default (64) is a class default where the staged fused entry takes the pieces the windows would otherwise read (Prefill::short_read_default); the user's own value wins + if (!o.short_read_set) o.short_read = strata::prefill::Prefill::short_read_default(o.short_read); std::vector checks; // KVA: which prefixes of token ids a KVA read approximated, so the draft layer knows, for whatever state a request // continues from, the first cell built from a real row (kva_floor.hpp). Empty without KVA. diff --git a/tests/prefill/staged_fo_rule_test.cpp b/tests/prefill/staged_fo_rule_test.cpp index ca185828e4..bf56191ce9 100644 --- a/tests/prefill/staged_fo_rule_test.cpp +++ b/tests/prefill/staged_fo_rule_test.cpp @@ -6,7 +6,9 @@ using strata::prefill::staged_entry_layer; using strata::prefill::staged_fo_decide; -using strata::prefill::staged_fo_off;using strata::prefill::staged_fo_switch; +using strata::prefill::staged_fo_off; +using strata::prefill::short_read_default; +using strata::prefill::staged_fo_switch; static int failed = 0; #define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) @@ -33,6 +35,12 @@ int main() { CHECK(staged_fo_decide("1", true)); CHECK(!staged_fo_decide("0", true)); // the way back: the measured class with the entry off CHECK(!staged_fo_decide("0", false)); + // --short-read: the class default only where the entry is on for a measured class with every layer fused-only; elsewhere the engine's own 64 + static_assert(strata::prefill::kStagedEntryShortRead > 0 && strata::prefill::kStagedEntryShortRead < 64, "the entry's crossing is below the windows' 64"); + static_assert(strata::prefill::short_read_default(64, true, true, true) == strata::prefill::kStagedEntryShortRead, "the class default"); + static_assert(strata::prefill::short_read_default(64, true, true, false) == 64, "entry off (STRATA_PF_STAGED_FO=0): the windows' 64"); + static_assert(strata::prefill::short_read_default(64, false, true, true) == 64, "another class: unchanged"); + static_assert(strata::prefill::short_read_default(64, true, false, true) == 64, "a layer on MMQ or FP16: unchanged"); // the layer rule: a layer with an MMQ tile is the entry's earlier rule, whatever the decision says static_assert(staged_entry_layer(true, false, false), "an MMQ layer keeps the entry"); static_assert(staged_entry_layer(true, false, true), "an MMQ layer keeps the entry");