Archived
New models: - Tencent Hy-Memory (HYV3) from its BF16, FP8 and GGUF checkpoints, with its native tool calls - M2XFP4: metadata-augmented MXFP4 weights for Qwen3.8-27B and its DFlash2 drafter (top-1 89.1% -> 92.4% against plain MXFP4), its quantiser and recipe, and ParoQuant's M2XFP4 checkpoints - Gemma 4 E2B/E4B audio input; NVIDIA-Nemotron-3.5-Bolt-E4B in int8 and 4-bit, on two cards by default; Ornith-1.5-122B compose files Speed: - Weight reads beside the decode all-reduces (qwen35_fp8, gemma3; --weight-prefetch, on by default): the 27B MXFP4 with DFlash2 61.2 -> 67.9 tok/s at c1, TranslateGemma 27B +13% - Head-256 split-KV decode attention at 256 workgroups and without bank conflicts (27B: +3-5% a step at 25-41K context), and the prefill KV split for small launches (a short turn over a long context decodes the other sequences 27% faster in that step) - MXFP4 decode gate_up, activation and fp8 quantiser in one launch (27B, Gemma 3 up to 64 rows: TranslateGemma +2-5% at 2-8 streams) - ParoQuant int4/int5 tiled GEMMs 6-9% faster - Speculation: a step's tokens are sent before the drafter's passes end, no step waits behind one that ends its requests, and the MTP head's first draft no longer collapses after short chats in the prefix cache Features: - --kv-resident N: KV streaming for a context bigger than VRAM (qwen4exp_fp8, GLM-5.3) - MiniMax-H3: reference media and keyframe conditioning with the VAE encoders - Krea 2 rebalance presets balanced, detail and subtle - The dashboard's request history; a stall watch that reports a frozen step's thread and stack - rad-tune at the served configuration, collectives measured as the exchange; Gemma 4 E2B/E4B's per-layer embeddings read ahead off the step path - A GPTQ calibration tap and recipe for Gemma 4 31B's w4a8 container Fixes: - The two-rank all-reduce checks that a peer's push has landed before reducing it - z-lab's DFlash drafter on Gemma 4 31B keeps drafting after a prefix-cache hit - MiniMax-H3's modulation rows Changes: Plugin ABI 31: out-of-tree plugins must be rebuilt. RADIANCE_PREFETCH_BESIDE is --weight-prefetch now; RADIANCE_NO_HUGE_PAGES, RADIANCE_IDS_EARLY, RADIANCE_ATTN_BAND_SPLIT, R4D_PREFILL_SPLITS, RAD_PLE_TIMING and RAD_PLE_CACHE_ROWS are gone.
184 lines
9.7 KiB
C++
184 lines
9.7 KiB
C++
/* bringup.cpp -- see bringup.h. */
|
|
#include "kvstream/bringup.h"
|
|
|
|
#include "device/device.h"
|
|
#include "engine_hostmem.h"
|
|
#include "kvstream/plan.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
|
|
namespace rad {
|
|
|
|
/* The ops whose only job is the host mirror or the ring. `kv_store` and the fused
|
|
* `qk_norm_rope_gate_kv_store` serve resident groups too. */
|
|
static const char* const kStreamOnlyOps[] = {
|
|
"kv_store_streamed",
|
|
"qk_norm_rope_gate_kv_store_streamed",
|
|
"kv_resolve",
|
|
};
|
|
|
|
bool kvstream_op_gated(const RadBuildCtx& ctx, const char* op) {
|
|
if (!op) return false;
|
|
if (ctx.kv_stream_ok != 0 && ctx.kv_resident_blocks > 0) return false; /* a ring is carved */
|
|
for (const char* s : kStreamOnlyOps)
|
|
if (std::strcmp(s, op) == 0) return true;
|
|
return false;
|
|
}
|
|
|
|
int kvstream_configure(const Config& cfg, int64_t ctx, const std::vector<KVGroupInfo>& groups,
|
|
const Program& prog, KVStreamSetup* out) {
|
|
*out = KVStreamSetup{};
|
|
if (cfg.kv_resident <= 0) return RAD_OK;
|
|
/* On Flash-Next the group is `kv_attn`. The indexer's `kv_qsa_bkey` is full too, but qsa_score
|
|
* reads it over the whole history every step, so it is dense-read and stays resident
|
|
* (docs/KV-STREAMING.md §2). A model with only windowed groups has nothing to stream. */
|
|
int32_t g = kv_stream_group(groups, &prog);
|
|
/* With no streamed path anywhere, the widest full group is still chosen, so the warning below
|
|
* can name it and the op it lacks. */
|
|
if (g < 0) g = kv_stream_group(groups);
|
|
if (g < 0) return RAD_OK;
|
|
const KVGroupInfo& gi = groups[(size_t)g];
|
|
const int64_t bs = gi.block_size > 0 ? gi.block_size : 1;
|
|
/* A ring that covers the context is not a refusal: the group stays a resident pool. */
|
|
const KVStreamRing shape = kvstream_ring_shape(cfg, ctx, bs);
|
|
out->asked_tokens = cfg.kv_resident;
|
|
out->context_tokens = ctx * cfg.max_seqs;
|
|
out->group_name = gi.name;
|
|
out->ring_blocks = shape.ring_blocks;
|
|
out->ring_tokens = shape.ring_blocks * bs;
|
|
out->block_size = bs;
|
|
out->ctx_blocks = shape.ctx_blocks;
|
|
if (!shape.streams()) return RAD_OK;
|
|
/* Before anything is allocated: the group needs the ops its streamed path issues (KVStreamOps).
|
|
* The gated fp8 attention (rad_block_attn_gated_fp8.h) and GLM-5.3's MLA block
|
|
* (rad_block_glm_mla.h) declare both. Without them the flag is ignored and the configuration is
|
|
* exactly the one without it. */
|
|
const KVStreamOps ops = kvstream_ops(prog, &gi);
|
|
if (!ops.streams()) {
|
|
/* A packed cache (fp8_v4, k6_v4) is declared to the core as plain E4M3, so the dtype check
|
|
* below cannot see it; its architecture declares the resolve but no store row. The
|
|
* operator's answer is then the cache layout, not the model. */
|
|
if ((cfg.kv_cache_dtype == "fp8_v4" || cfg.kv_cache_dtype == "k6_v4") && ops.resolve &&
|
|
!ops.store && !ops.folded)
|
|
RAD_WARN("--kv-resident %lld ignored: group '%s' has a %s cache, and the streamed store "
|
|
"has no writer for that layout (E4M3 and bf16 only); the group stays "
|
|
"resident",
|
|
(long long)cfg.kv_resident, gi.name.c_str(), cfg.kv_cache_dtype.c_str());
|
|
else
|
|
RAD_WARN("--kv-resident %lld ignored: architecture '%s' declares no %s for group '%s', "
|
|
"so the group stays resident",
|
|
(long long)cfg.kv_resident,
|
|
prog.meta.arch_id && *prog.meta.arch_id ? prog.meta.arch_id : "(unnamed)",
|
|
ops.missing(), gi.name.c_str());
|
|
*out = KVStreamSetup{};
|
|
return RAD_OK;
|
|
}
|
|
/* The streamed store has E4M3 and bf16 rows only. Packed layouts were ignored above; this
|
|
* refuses a core dtype no architecture ships a full group in (f32, f16). */
|
|
if (gi.decl.dtype != RAD_F8E4M3 && gi.decl.dtype != RAD_BF16) {
|
|
RAD_ERR("--kv-resident %lld: group '%s' has a %s cache, and the streamed store has E4M3 "
|
|
"and bf16 rows only (--kv-cache-dtype fp8 or bf16); leave --kv-resident off",
|
|
(long long)cfg.kv_resident, out->group_name.c_str(),
|
|
rad_dtype_name(gi.decl.dtype));
|
|
return RAD_E_INVAL;
|
|
}
|
|
KVStreamRing ring;
|
|
kvstream_ring(cfg, ctx, bs, ops.sel_pitch, &ring);
|
|
if (ring.raised_blocks > 0) {
|
|
/* The line names the floor that bound: one decode step's selection (a correctness bound) or
|
|
* kStreamFloorTokens (a cost bound). */
|
|
const int64_t asked_blocks = (out->asked_tokens + bs - 1) / bs;
|
|
const int64_t step = kvstream_ceiling_blocks(cfg, ops.sel_pitch);
|
|
if (ring.by_union && step > asked_blocks) {
|
|
RAD_WARN("--kv-resident %lld raised to %lld tokens: one decode step can select %lld "
|
|
"blocks of %lld tokens (--max-num-seqs %lld x %lld rows x %lld), and the ring "
|
|
"must hold them",
|
|
(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",
|
|
(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 cover the whole context, which does not stream. */
|
|
out->ring_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 takes the stage and never resolves: above `qsa_exact_to` a launch selects a chunk's
|
|
* union, which no ring could hold. The stage is the group's context one layer deep, addressed
|
|
* by block id (kvstream/bind.h says which passes take it). */
|
|
out->stage_blocks = ring.streams() ? ring.ctx_blocks : 0;
|
|
return RAD_OK;
|
|
}
|
|
|
|
void kvstream_host_add(KVStreamHostUse* use, const KVManager& kv) {
|
|
const KVStreamCost c = kv.stream_cost();
|
|
use->sum.groups += c.groups;
|
|
use->sum.host_bytes += c.host_bytes;
|
|
use->sum.map_bytes += c.map_bytes;
|
|
use->max_rank_bytes = std::max(use->max_rank_bytes, c.host_bytes);
|
|
}
|
|
|
|
int kvstream_host_gate(const KVStreamHostUse& use, int n_ranks, int64_t still, int64_t headroom) {
|
|
if (use.sum.host_bytes <= 0) return RAD_OK;
|
|
std::string why;
|
|
if (lockable_room(use.sum.host_bytes, still, headroom, false, &why)) return RAD_OK;
|
|
RAD_ERR("kv streaming: the host mirror for %lld streamed KV group(s) needs up to %s of "
|
|
"pinned host memory a rank (%s over %d ranks), and %s. It holds one full context a "
|
|
"sequence: lower --max-model-len or --max-num-seqs, or set --kv-resident 0 "
|
|
"(--host-pool-mib sizes the experts' tier, not this one)",
|
|
(long long)use.sum.groups, humanb(use.max_rank_bytes).c_str(),
|
|
humanb(use.sum.host_bytes).c_str(), n_ranks, why.c_str());
|
|
return RAD_E_NOMEM;
|
|
}
|
|
|
|
int kvstream_fill(KVManager& kv) {
|
|
/* After the carve, which backs an elastic pool's range; drained before the first pass reads the
|
|
* maps. */
|
|
RadStream st = nullptr;
|
|
int rc = rad_stream_create(&st, 0);
|
|
if (rc == RAD_OK) rc = kv.init_stream(st);
|
|
if (rc == RAD_OK) rc = rad_stream_sync(st);
|
|
rad_stream_destroy(st);
|
|
return rc;
|
|
}
|
|
|
|
void kvstream_report(const KVStreamSetup& s, const KVStreamHostUse& host, int n_ranks) {
|
|
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: --kv-resident %lld became %lld tokens (%lld -> %lld blocks of "
|
|
"%lld tokens), %s",
|
|
(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,
|
|
s.raised_by_union ? "the blocks one decode step can select"
|
|
: "the floor below which misses cost more than the ring saves");
|
|
if (host.sum.groups > 0)
|
|
RAD_INFO("kv streaming: %lld group(s) stream (%s): up to %s of pinned host mirror a "
|
|
"rank (%s over %d), %s of ring maps in the KV pools",
|
|
(long long)host.sum.groups, s.group_name.c_str(),
|
|
humanb(host.max_rank_bytes).c_str(), humanb(host.sum.host_bytes).c_str(), n_ranks,
|
|
humanb(host.sum.map_bytes).c_str());
|
|
if (s.stage_blocks > 0)
|
|
RAD_INFO("kv streaming: prefill staging, group '%s' ring %lld blocks, one-layer stage %lld "
|
|
"blocks (one layer of its %lld-block context); decode passes use the ring",
|
|
s.group_name.c_str(), (long long)s.ring_blocks,
|
|
(long long)s.stage_blocks, (long long)s.ctx_blocks);
|
|
if (s.group < 0 && s.asked_tokens > 0 && s.ctx_blocks > 0)
|
|
RAD_INFO("kv streaming: nothing streams: --kv-resident %lld covers group '%s''s "
|
|
"%lld-token context (%lld blocks), so the group stays resident; below %lld "
|
|
"tokens it would stream",
|
|
(long long)flag, s.group_name.c_str(), (long long)s.context_tokens,
|
|
(long long)s.ctx_blocks, (long long)s.context_tokens);
|
|
}
|
|
|
|
} /* namespace rad */
|