From 8af24965cc0fdc596b342e9bfc8ea92d2d2ad511 Mon Sep 17 00:00:00 2001 From: C_Tamas Date: Sun, 25 Oct 2026 09:58:22 +0700 Subject: [PATCH] kvstream: the raise names the floor that bound it With only the union raise, "raised to N tokens" always meant "one decode step's selection". Now that the shipped floor can bind instead, both startup lines said the wrong thing: --kv-resident 1 reported "a decode step can name 1026 blocks" while carving 8192. KVStreamRing::by_union carries which bound won, and KVStreamSetup::raised_by_union hands it to the report. Verified on 2x16 GB: --kv-resident 1 now prints "a ring under 32768 tokens (8192 blocks of 4) misses more than it saves, so the shipped floor is what the carve takes", the report line says the same, kv_resident_blocks reads 8192 and the engine serves. --- core/kvstream/bringup.cpp | 12 ++++++++---- core/kvstream/bringup.h | 6 ++++-- core/kvstream/plan.cpp | 2 ++ core/kvstream/plan.h | 6 +++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/kvstream/bringup.cpp b/core/kvstream/bringup.cpp index b9d0d208..1b500644 100644 --- a/core/kvstream/bringup.cpp +++ b/core/kvstream/bringup.cpp @@ -125,7 +125,7 @@ int kvstream_configure(const Config& cfg, int64_t ctx, const std::vectorasked_tokens + bs - 1) / bs; const int64_t step = kvstream_ceiling_blocks(cfg, ops.sel_pitch); - if (step > asked_blocks && step <= ring.raised_blocks) { + if (ring.by_union && step > asked_blocks) { RAD_WARN("--kv-resident %lld raised to %lld tokens: a decode step can name %lld blocks " "of %lld blocks each (--max-num-seqs %lld x %lld for speculation x %lld), and " "the ring must hold them all; the ring takes the raised depth and startup " @@ -148,6 +148,7 @@ int kvstream_configure(const Config& cfg, int64_t ctx, const std::vectorring_blocks = ring.ring_blocks; out->ring_tokens = ring.ring_blocks * bs; out->raised_tokens = ring.raised_blocks > 0 ? ring.ring_blocks * bs : 0; + out->raised_by_union = ring.raised_blocks > 0 && ring.by_union; out->group = ring.streams() ? g : -1; /* Prefill runs on the stage and never resolves: above `qsa_exact_to` one launch's selection is * a chunk's union, which no serving ring could hold, so the pass gets the group's context one @@ -200,11 +201,14 @@ void kvstream_report(const KVStreamSetup& s, const KVStreamHostUse& host, int n_ const int64_t flag = s.raised_tokens > 0 ? s.raised_tokens : s.asked_tokens; if (s.raised_tokens > 0 && s.block_size > 0) RAD_INFO("kv streaming: the ring is the raised one, not the flag's: --kv-resident %lld " - "became %lld tokens (%lld -> %lld blocks of %lld tokens each), the fewest blocks " - "one decode step's selection fits in; what was carved below is that ring", + "became %lld tokens (%lld -> %lld blocks of %lld tokens each), %s; what was " + "carved below is that ring", (long long)s.asked_tokens, (long long)s.raised_tokens, (long long)((s.asked_tokens + s.block_size - 1) / s.block_size), - (long long)(s.raised_tokens / s.block_size), (long long)s.block_size); + (long long)(s.raised_tokens / s.block_size), (long long)s.block_size, + s.raised_by_union ? "the fewest blocks one decode step's selection fits in" + : "the shipped floor, under which the misses cost more than " + "the VRAM the ring gives back"); if (host.sum.groups > 0) RAD_INFO("kv streaming: %lld group(s) stream (%s): kv_store_streamed writes the host " "mirror and the resident ring slots, kv_resolve rewrites each selection as ring " diff --git a/core/kvstream/bringup.h b/core/kvstream/bringup.h index 3fc3da98..eca40d4e 100644 --- a/core/kvstream/bringup.h +++ b/core/kvstream/bringup.h @@ -26,8 +26,10 @@ struct KVStreamSetup { int32_t group = -1; /* the group that streams; -1 when nothing does */ std::string group_name; /* the group that would have: named by the report */ int64_t asked_tokens = 0; /* --kv-resident as given; 0 is no streaming at all */ - int64_t raised_tokens = 0; /* what the flag became when the ring's ceiling raised - * it; 0 when it was not raised */ + int64_t raised_tokens = 0; /* what the flag became when a floor raised it; 0 when it + * was not raised */ + bool raised_by_union = false; /* the raise was the decode-step union, not the shipped + * floor (kStreamFloorTokens): the report's wording */ int64_t context_tokens = 0; /* --max-model-len x --max-num-seqs */ int64_t ring_tokens = 0; /* the ring that is carved, in tokens: the raised flag, * rounded to whole blocks */ diff --git a/core/kvstream/plan.cpp b/core/kvstream/plan.cpp index 97a6f672..0c54d6d5 100644 --- a/core/kvstream/plan.cpp +++ b/core/kvstream/plan.cpp @@ -189,6 +189,8 @@ void kvstream_ring(const Config& cfg, int64_t ctx, int64_t block_size, int64_t s if (out->ring_blocks < ceiling) { out->ring_blocks = ceiling < out->ctx_blocks ? ceiling : out->ctx_blocks; out->raised_blocks = out->ring_blocks; + /* The union above the floor, or above the flag: either way it is the union that bound. */ + out->by_union = true; } } diff --git a/core/kvstream/plan.h b/core/kvstream/plan.h index 645888e6..2b23dd8e 100644 --- a/core/kvstream/plan.h +++ b/core/kvstream/plan.h @@ -80,7 +80,11 @@ struct KVStreamRing { * already asked for that much: the ring is not the operator's * number when this is set */ int64_t floor_blocks = 0; /* the shipped floor (kStreamFloorTokens) in blocks, or 0 when the - * context is smaller than it: which of the two bound the raise */ + * context is smaller than it */ + /* Which floor bound the raise: true when it was the decode-step union rather than the shipped + * floor. Both are applied in kvstream_ring_shape/kvstream_ring; this only tells the two + * startup lines which sentence to print. */ + bool by_union = false; int64_t ctx_blocks = 0; /* max_seqs x ceil(ctx / block_size): the group's whole context */ /* A ring that covers the context is not a streamed group. The pool then holds every block * with its own id, so the group keeps the base engine's path exactly: no mirror, no residency