Archived
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:
1 parent
2bf1096131
commit
613bbaacfd
5 files changed
+63
-23
No files matched your search
+5
-4
@@ -90,10 +90,11 @@ static const Flag g_flags[] = {
|
|||||||
" the card. At or above the group's context (sequences x\n"
|
" the card. At or above the group's context (sequences x\n"
|
||||||
" --max-model-len) nothing streams either: the group stays a\n"
|
" --max-model-len) nothing streams either: the group stays a\n"
|
||||||
" plain resident pool and the engine takes its ordinary path,\n"
|
" plain resident pool and the engine takes its ordinary path,\n"
|
||||||
" with no mirror, no stage and no resolve. Below it, the rest\n"
|
" with no mirror, no stage and no resolve. Under 32768 the\n"
|
||||||
" of each block lives in pinned host memory and the ring must\n"
|
" ring is raised to it (and to one decode step's selection\n"
|
||||||
" hold one decode step's whole selection; a smaller ring is\n"
|
" when that is larger); below it a decode pays more in misses\n"
|
||||||
" raised to that many blocks at startup, with a warning" },
|
" than the ring saves. A context under 32768 tokens streams\n"
|
||||||
|
" nothing at all" },
|
||||||
{ "--host-pool-mib", "N", "pinned host tier" },
|
{ "--host-pool-mib", "N", "pinned host tier" },
|
||||||
{ "--host-headroom-mib", "N", "host RAM to leave free for the system when radiance\n"
|
{ "--host-headroom-mib", "N", "host RAM to leave free for the system when radiance\n"
|
||||||
" pins its host memory at startup (default 4096)" },
|
" pins its host memory at startup (default 4096)" },
|
||||||
|
|||||||
@@ -917,8 +917,14 @@ RadBuildCtx Engine::build_ctx(int rank, int64_t max_tok) const {
|
|||||||
* (Scheduler::step), so a wider step is one sequence; 0 without a span. */
|
* (Scheduler::step), so a wider step is one sequence; 0 without a span. */
|
||||||
bc.max_mixed_tok = cfg_.prefill_span > 1 ? std::min(max_tok, prefill_shared_tok(cfg_)) : 0;
|
bc.max_mixed_tok = cfg_.prefill_span > 1 ? std::min(max_tok, prefill_shared_tok(cfg_)) : 0;
|
||||||
/* --kv-resident, in tokens: the ring a streamed group carves. Declared geometry states it where
|
/* --kv-resident, in tokens: the ring a streamed group carves. Declared geometry states it where
|
||||||
* an op needs a ring depth (kv_resolve), so the report is the ring and not the context. */
|
* an op needs a ring depth (kv_resolve), so the report is the ring and not the context. Raised
|
||||||
bc.kv_resident_blocks = cfg_.kv_resident;
|
* to the shipped floor here, before the declare: the arch states the residency table's depth
|
||||||
|
* from this number (kv_resolve's `slots`), and a carve deeper than the declared table is
|
||||||
|
* refused by the kernel. The floor is the same one kvstream_ring_shape applies, so the two
|
||||||
|
* cannot disagree. */
|
||||||
|
bc.kv_resident_blocks = cfg_.kv_resident > 0 && cfg_.kv_resident < kStreamFloorTokens
|
||||||
|
? kStreamFloorTokens
|
||||||
|
: cfg_.kv_resident;
|
||||||
/* The probe's answer, so a streamed-only op is declared only for an architecture that serves
|
/* The probe's answer, so a streamed-only op is declared only for an architecture that serves
|
||||||
* one AND a deployment that asked (core/kvstream/bringup.cpp, kvstream_op_gated). */
|
* one AND a deployment that asked (core/kvstream/bringup.cpp, kvstream_op_gated). */
|
||||||
bc.kv_stream_ok = arch_probe_.kv_stream_ok;
|
bc.kv_stream_ok = arch_probe_.kv_stream_ok;
|
||||||
|
|||||||
+26
-12
@@ -117,18 +117,32 @@ int kvstream_configure(const Config& cfg, int64_t ctx, const std::vector<KVGroup
|
|||||||
* line that says what was asked, what it became and why. */
|
* line that says what was asked, what it became and why. */
|
||||||
KVStreamRing ring;
|
KVStreamRing ring;
|
||||||
kvstream_ring(cfg, ctx, bs, ops.sel_pitch, &ring);
|
kvstream_ring(cfg, ctx, bs, ops.sel_pitch, &ring);
|
||||||
if (ring.raised_blocks > 0)
|
if (ring.raised_blocks > 0) {
|
||||||
/* Anything under the computed amount is ignored and pulled up to it, the way Strata sizes
|
/* Two floors, and the line names whichever bound: the shipped one (a ring under
|
||||||
* this: the engine knows what a decode step names, and --kv-resident is a request for
|
* kStreamFloorTokens is not worth carving -- the misses cost more than the VRAM saved) or
|
||||||
* streaming rather than for one number. A warning, so startup proceeds -- and a different
|
* one decode step's selection, which is a correctness bound rather than a preference. A
|
||||||
* sentence from the ignored-flag one above, because this model does stream. */
|
* warning, so startup proceeds -- and a different sentence from the ignored-flag one
|
||||||
RAD_WARN("--kv-resident %lld raised to %lld tokens: a decode step can name %lld blocks of "
|
* above, because this model does stream. */
|
||||||
"%lld blocks each (--max-num-seqs %lld x %lld for speculation x %lld), and the ring "
|
const int64_t asked_blocks = (out->asked_tokens + bs - 1) / bs;
|
||||||
"must hold them all; the ring takes the raised depth and startup proceeds",
|
const int64_t step = kvstream_ceiling_blocks(cfg, ops.sel_pitch);
|
||||||
(long long)out->asked_tokens, (long long)(ring.ring_blocks * bs),
|
if (step > asked_blocks && step <= ring.raised_blocks) {
|
||||||
(long long)ring.raised_blocks, (long long)bs,
|
RAD_WARN("--kv-resident %lld raised to %lld tokens: a decode step can name %lld blocks "
|
||||||
(long long)(cfg.max_seqs > 0 ? cfg.max_seqs : 1),
|
"of %lld blocks each (--max-num-seqs %lld x %lld for speculation x %lld), and "
|
||||||
(long long)(1 + (cfg.n_spec > 0 ? cfg.n_spec : 0)), (long long)ops.sel_pitch);
|
"the ring must hold them all; the ring takes the raised depth and startup "
|
||||||
|
"proceeds",
|
||||||
|
(long long)out->asked_tokens, (long long)(ring.ring_blocks * bs),
|
||||||
|
(long long)step, (long long)bs,
|
||||||
|
(long long)(cfg.max_seqs > 0 ? cfg.max_seqs : 1),
|
||||||
|
(long long)(1 + (cfg.n_spec > 0 ? cfg.n_spec : 0)),
|
||||||
|
(long long)ops.sel_pitch);
|
||||||
|
} else {
|
||||||
|
RAD_WARN("--kv-resident %lld raised to %lld tokens: a ring under %lld tokens (%lld "
|
||||||
|
"blocks of %lld) misses more than it saves, so the shipped floor is what the "
|
||||||
|
"carve takes. Startup proceeds; raise the flag to go deeper",
|
||||||
|
(long long)out->asked_tokens, (long long)(ring.ring_blocks * bs),
|
||||||
|
(long long)kStreamFloorTokens, (long long)ring.raised_blocks, (long long)bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* The raised ring may be the whole context, which is not a streamed group at all: it keeps
|
/* The raised ring may be the whole context, which is not a streamed group at all: it keeps
|
||||||
* every block on the card and the report says which context the ring covers. */
|
* every block on the card and the report says which context the ring covers. */
|
||||||
out->ring_blocks = ring.ring_blocks;
|
out->ring_blocks = ring.ring_blocks;
|
||||||
|
|||||||
+11
-1
@@ -156,6 +156,16 @@ KVStreamRing kvstream_ring_shape(const Config& cfg, int64_t ctx, int64_t block_s
|
|||||||
const int64_t bs = block_size > 0 ? block_size : 1;
|
const int64_t bs = block_size > 0 ? block_size : 1;
|
||||||
out.ctx_blocks = kv_context_blocks(bs, ctx, cfg.max_seqs);
|
out.ctx_blocks = kv_context_blocks(bs, ctx, cfg.max_seqs);
|
||||||
out.ring_blocks = cfg.kv_resident > 0 ? (cfg.kv_resident + bs - 1) / bs : 0;
|
out.ring_blocks = cfg.kv_resident > 0 ? (cfg.kv_resident + bs - 1) / bs : 0;
|
||||||
|
/* The shipped floor, unless the context is smaller than it (a model that cannot hold 32 768
|
||||||
|
* tokens of this group streams nothing at all, which is the pre-existing behaviour). */
|
||||||
|
if (out.ring_blocks > 0) {
|
||||||
|
out.floor_blocks = (kStreamFloorTokens + bs - 1) / bs;
|
||||||
|
if (out.floor_blocks > out.ctx_blocks) out.floor_blocks = out.ctx_blocks;
|
||||||
|
if (out.ring_blocks < out.floor_blocks) {
|
||||||
|
out.ring_blocks = out.floor_blocks;
|
||||||
|
out.raised_blocks = out.floor_blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (out.ring_blocks > out.ctx_blocks) out.ring_blocks = out.ctx_blocks;
|
if (out.ring_blocks > out.ctx_blocks) out.ring_blocks = out.ctx_blocks;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -178,7 +188,7 @@ void kvstream_ring(const Config& cfg, int64_t ctx, int64_t block_size, int64_t s
|
|||||||
const int64_t ceiling = kvstream_ceiling_blocks(cfg, sel_pitch);
|
const int64_t ceiling = kvstream_ceiling_blocks(cfg, sel_pitch);
|
||||||
if (out->ring_blocks < ceiling) {
|
if (out->ring_blocks < ceiling) {
|
||||||
out->ring_blocks = ceiling < out->ctx_blocks ? ceiling : out->ctx_blocks;
|
out->ring_blocks = ceiling < out->ctx_blocks ? ceiling : out->ctx_blocks;
|
||||||
out->raised_blocks = ceiling;
|
out->raised_blocks = out->ring_blocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-4
@@ -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. */
|
* numbers the engine already has, so the budget probe and the carve decision cannot disagree. */
|
||||||
struct KVStreamRing {
|
struct KVStreamRing {
|
||||||
int64_t ring_blocks = 0; /* --kv-resident, rounded up to whole blocks and raised to the
|
int64_t ring_blocks = 0; /* --kv-resident, rounded up to whole blocks and raised to the
|
||||||
* ceiling below when the flag asks for less */
|
* floor below when the flag asks for less */
|
||||||
int64_t raised_blocks = 0; /* the depth the flag was raised to (kvstream_ceiling_blocks), or 0
|
int64_t raised_blocks = 0; /* the depth the flag was raised to (the larger of
|
||||||
* when it already asked for that much: the ring is not the
|
* kvstream_ceiling_blocks and the shipped floor), or 0 when it
|
||||||
* operator's number when this is set */
|
* 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 */
|
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
|
/* 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
|
* 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);
|
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
|
/* 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
|
* 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. */
|
* ring is below what a decode step can select" (a raise) without one hiding the other. */
|
||||||
|
|||||||
Reference in new issue
Block a user