kvstream: the ring is never carved below the shipped floor of 32 768 tokens

The raise enforced only the validation union -- the largest block union one
decode launch selects, max_seqs x (1 + n_spec) x sel_pitch -- which on the
reference model is 1026 blocks = 4104 tokens. That is the depth below which a
step cannot be served at all, not the depth below which streaming pays: the
measured curve puts the cost point at 24 576 and the shipped value at 32 768
(docs/KV-STREAMING.md 3.9). --kv-resident 1 therefore carved a 4 104-token
ring, and one 7 800-token request took 7 213 misses over 8 decoded tokens.

kStreamFloorTokens (32 768) is now a floor the carve enforces:

  * kvstream_ring_shape raises any ring under it, then kvstream_ring raises
    that to the union when the union is larger; both are clamped to the
    group's context, so a context under 32 768 tokens streams nothing (the
    ring covers it and the group keeps the base engine's path);
  * RadBuildCtx::kv_resident_blocks carries the raised number into the
    declare, because kv_resolve sizes its residency table from it -- a carve
    deeper than the declared table is refused by the kernel;
  * the startup warning says which bound applied, and KVStreamRing::floor_blocks
    keeps the two distinct.

The flag is still the operator's: --kv-resident 65536 stays 65536, and a
context that fits is untouched apart from the 32 768 floor.
This commit is contained in:
C_Tamas committed 2026-10-25 09:29:17 +07:00
1 parent 2bf1096131
commit 613bbaacfd
5 files changed
+63 -23

No files matched your search

+13 -4
View File
@@ -74,10 +74,13 @@ int32_t kv_stream_group(const std::vector<KVGroupInfo>& groups, const Program* p
* numbers the engine already has, so the budget probe and the carve decision cannot disagree. */
struct KVStreamRing {
int64_t ring_blocks = 0; /* --kv-resident, rounded up to whole blocks and raised to the
* ceiling below when the flag asks for less */
int64_t raised_blocks = 0; /* the depth the flag was raised to (kvstream_ceiling_blocks), or 0
* when it already asked for that much: the ring is not the
* operator's number when this is set */
* floor below when the flag asks for less */
int64_t raised_blocks = 0; /* the depth the flag was raised to (the larger of
* kvstream_ceiling_blocks and the shipped floor), or 0 when it
* 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 */
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
@@ -128,6 +131,12 @@ struct KVStreamOps {
};
KVStreamOps kvstream_ops(const Program& prog, const KVGroupInfo* group);
/* The depth a ring is never carved below, in tokens: any --kv-resident under it is raised to it
* (never past the group's context). Below this the misses a decode step takes cost more than the
* VRAM the ring gives back -- the measured point is 24 576 tokens and the shipped value is 32 768
* (docs/KV-STREAMING.md §3.9, §5.1). A floor, not a default: --kv-resident 0 still means off. */
constexpr int64_t kStreamFloorTokens = 32768;
/* The ring's depth and the group's id space with nothing else decided: whether a ring covers the
* context, so that the caller can tell "this model has no streamed path" (a warning) from "this
* ring is below what a decode step can select" (a raise) without one hiding the other. */