Archived
radiance 1.2.0
- MXFP4 weights: block-fp8 Qwen3.5/3.6/3.8 dense models serve OCP-MXFP4 linears (e2m1, an E8M0 exponent per 32) at 4-bit weights against E4M3 activations. New libr4d rows: the decode GEMM (M <= 128, split-K with a fused last-arriver reduction) and the prefill GEMM on a fragment-tiled activation. Qwen3.8-27B MXFP4 (AMD Quark AWQ) is in the model table. - Cards without peer-to-peer access serve: every collective has a host-memory twin; --p2p auto|on|off. - Stop strings apply to the answer, not to the reasoning block a reply starts in. - A prefix hit ends one drafter window before the prompt's end, so a windowed block drafter (DFlash2) drafts from the first token of a follow-up turn.
This commit is contained in:
1 parent
7001841e45
commit
e95d397288
47 files changed
+2611
-219
No files matched your search
@@ -307,6 +307,22 @@ TEST(the_wire_mode_is_one_of_two_names) {
|
||||
CHECK_EQ(parse({ "--tp-wire", "EXACT" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
TEST(the_p2p_mode_is_one_of_three_names) {
|
||||
Config c;
|
||||
CHECK_EQ(c.p2p, RAD_P2P_AUTO);
|
||||
CHECK_EQ(parse({ "--p2p", "on" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.p2p, RAD_P2P_ON);
|
||||
CHECK_EQ(parse({ "--p2p", "off" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.p2p, RAD_P2P_OFF);
|
||||
CHECK_EQ(parse({ "--p2p", "auto" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.p2p, RAD_P2P_AUTO);
|
||||
/* A name this build does not know stops the server: `on` exists so a deployment measured on
|
||||
* P2P cannot quietly serve on host memory, and a typo falling through to auto would do that. */
|
||||
CHECK_EQ(parse({ "--p2p", "yes" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--p2p", "" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--p2p", "OFF" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
TEST(the_kv_cache_dtype_is_one_of_two_names) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "bf16" }, &c), RAD_OK);
|
||||
|
||||
@@ -1141,6 +1141,59 @@ TEST(split_lookup_reuses_attention_between_checkpoints) {
|
||||
CHECK_EQ(f.pc.lookup(other, {}).n_linear_tokens, 0);
|
||||
}
|
||||
|
||||
/* A CAPPED LOOKUP (HitCap) ends the hit at a block and the linear state at a checkpoint at or
|
||||
* below the cap, never past it -- unless that gives back more than the cap allows, in which case
|
||||
* the whole hit stands. The statistics count one lookup either way. */
|
||||
TEST(a_capped_lookup_lands_on_a_checkpoint_at_or_below_the_cap) {
|
||||
Fixture f;
|
||||
CHECK_OK(f.build(/*with_linear=*/true, /*ckpt_slots=*/4));
|
||||
auto prompt = tok_run(7000, 336);
|
||||
publish(f, 1, prompt, 320);
|
||||
BlockHash parent;
|
||||
std::vector<BlockHash> hs;
|
||||
for (int b = 0; b < 21; ++b) {
|
||||
parent = chain_block_hash(parent, prompt.data() + b * 16, 16, nullptr, 0, b * 16);
|
||||
hs.push_back(parent);
|
||||
}
|
||||
int32_t s128 = -1, s256 = -1;
|
||||
CHECK_OK(f.pc.reserve_checkpoint(1, 128, hs[128 / 16 - 1], &s128));
|
||||
f.pc.commit_checkpoint(hs[128 / 16 - 1]);
|
||||
CHECK_OK(f.pc.reserve_checkpoint(1, 256, hs[256 / 16 - 1], &s256));
|
||||
f.pc.commit_checkpoint(hs[256 / 16 - 1]);
|
||||
|
||||
const CacheHit u = f.pc.lookup(prompt, {});
|
||||
CHECK_EQ(u.n_attn_tokens, 320);
|
||||
CHECK_EQ(u.n_linear_tokens, 256);
|
||||
CHECK_EQ(u.given_back, 0);
|
||||
|
||||
HitCap cap;
|
||||
cap.tokens = 250;
|
||||
cap.max_give_back = 1000;
|
||||
const int64_t lookups = f.pc.stats().lookups;
|
||||
const CacheHit c = f.pc.lookup(prompt, {}, nullptr, &cap);
|
||||
CHECK_EQ(f.pc.stats().lookups, lookups + 1);
|
||||
CHECK_EQ(c.n_attn_tokens, 240);
|
||||
CHECK_EQ(c.n_linear_tokens, 128);
|
||||
CHECK_EQ(c.checkpoint_slot, s128);
|
||||
CHECK_EQ(c.given_back, 128); /* 256 reusable before, 128 after */
|
||||
|
||||
cap.tokens = 100; /* below every checkpoint: all 256 go back */
|
||||
const CacheHit z = f.pc.lookup(prompt, {}, nullptr, &cap);
|
||||
CHECK_EQ(z.n_attn_tokens, 96);
|
||||
CHECK_EQ(z.n_linear_tokens, 0);
|
||||
CHECK_EQ(z.checkpoint_slot, -1);
|
||||
CHECK_EQ(z.given_back, 256);
|
||||
|
||||
cap.max_give_back = 255; /* ...which is more than this cap allows */
|
||||
const CacheHit w = f.pc.lookup(prompt, {}, nullptr, &cap);
|
||||
CHECK_EQ(w.n_attn_tokens, 320);
|
||||
CHECK_EQ(w.n_linear_tokens, 256);
|
||||
CHECK_EQ(w.given_back, 0);
|
||||
|
||||
cap.tokens = 100000; /* a cap above the hit changes nothing */
|
||||
CHECK_EQ(f.pc.lookup(prompt, {}, nullptr, &cap).n_attn_tokens, 320);
|
||||
}
|
||||
|
||||
/* The chained block hashes of `tokens`, one a block, as the cache computes them. */
|
||||
static std::vector<BlockHash> chain_of(const std::vector<int32_t>& tokens, int bs) {
|
||||
std::vector<BlockHash> hs;
|
||||
|
||||
+105
-9
@@ -359,14 +359,35 @@ struct FakePC : IPrefixCache {
|
||||
}
|
||||
|
||||
mutable int64_t lookups = 0;
|
||||
CacheHit lookup(const Request&, std::vector<std::vector<int32_t>>* out) const override {
|
||||
/* A cap (HitCap) as prefix.cpp applies one: attention ends at a block at or below it, the
|
||||
* linear state at the deepest checkpoint under that -- checkpoints at multiples of `interval`,
|
||||
* none below `ckpt_lo` -- and the whole hit stands if that gives back too much. */
|
||||
int64_t ckpt_lo = 0;
|
||||
CacheHit lookup(const Request&, std::vector<std::vector<int32_t>>* out,
|
||||
const HitCap* cap) const override {
|
||||
++lookups;
|
||||
if (out) {
|
||||
out->resize(groups.size());
|
||||
for (size_t i = 0; i < groups.size() && i < seeded.size(); ++i)
|
||||
(*out)[i] = seeded[i];
|
||||
}
|
||||
return CacheHit{ attn, lin, src };
|
||||
CacheHit h{ attn, lin, src };
|
||||
const int64_t whole = src >= 0 ? lin : 0;
|
||||
if (cap && attn > cap->tokens / 16 * 16 && whole > cap->tokens) {
|
||||
const int64_t a = cap->tokens / 16 * 16;
|
||||
int64_t l = std::min<int64_t>(lin, a) / interval * interval;
|
||||
if (l < ckpt_lo) l = 0;
|
||||
if (whole - l <= cap->max_give_back) {
|
||||
h.n_attn_tokens = (int32_t)a;
|
||||
h.n_linear_tokens = (int32_t)l;
|
||||
h.checkpoint_slot = l > 0 ? src : -1;
|
||||
h.given_back = (int32_t)(whole - l);
|
||||
if (out)
|
||||
for (auto& b : *out)
|
||||
if ((int64_t)b.size() > a / 16) b.resize((size_t)(a / 16));
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
const std::vector<int32_t>& cached_groups() const override { return groups; }
|
||||
|
||||
@@ -462,7 +483,8 @@ struct Fixture {
|
||||
|
||||
~Fixture() { sch.fini(); for (void* p : owned) std::free(p); }
|
||||
|
||||
void build(int64_t blocks = 4096, int64_t states = 64, int64_t max_tok = 512) {
|
||||
void build(int64_t blocks = 4096, int64_t states = 64, int64_t max_tok = 512,
|
||||
int64_t max_ctx = 4096) {
|
||||
g_gdn_ki = RadKernelInfo{};
|
||||
g_gdn_ki.name = "gdn_fake";
|
||||
g_gdn_ki.op = "gdn_chunked";
|
||||
@@ -513,7 +535,7 @@ struct Fixture {
|
||||
|
||||
cfg.max_tok = max_tok;
|
||||
cfg.max_seqs = 32;
|
||||
cfg.max_ctx = 4096;
|
||||
cfg.max_ctx = max_ctx;
|
||||
cfg.checkpoint_interval = 256;
|
||||
cfg.prefix_cache = true;
|
||||
/* `Config::n_spec` defaults to -1, which is `auto`: a REQUEST that engine_bringup resolves
|
||||
@@ -1208,16 +1230,90 @@ TEST(a_prefix_hit_does_not_stop_a_full_attention_drafter) {
|
||||
* wrote: there is no hole and the floor is 0. Taking the floor to be the hit position
|
||||
* instead stops a windowless drafter from ever drafting again after a hit.
|
||||
*
|
||||
* THE OTHER SIDE -- a drafter whose group the cache SKIPS must still decline -- is not
|
||||
* testable here: giving the fixture a second paged group the FakePC does not index makes
|
||||
* its lookup hand back a block list that does not cover it, so the hit is refused and
|
||||
* ctx_len is 0 either way. That case needs a windowed drafter over a cache that leaves a
|
||||
* hole, which this fixture cannot construct. */
|
||||
* THE OTHER SIDE -- a windowed drafter whose group the cache SKIPS, so a hit leaves a hole
|
||||
* -- is the draft-refill cases below. */
|
||||
Scheduler::BlockRow rows[4];
|
||||
CHECK_EQ(f.sch.block_begin(/*block=*/8, /*depth=*/7, /*window=*/0, /*mask=*/99, rows, 4), 1);
|
||||
CHECK_EQ((int)rows[0].seq, (int)a);
|
||||
}
|
||||
|
||||
/* ====================================== a prefix hit and a windowed block drafter (draft refill)
|
||||
* The drafter's own windowed KV group is not prefix-cached, so a hit leaves it without K and V for
|
||||
* the cached tokens, and block_begin declines the sequence until the window has slid past the hole.
|
||||
* The scheduler ends such a hit one drafter window before the end of the prompt, at a checkpoint,
|
||||
* so the recompute covers the window and the drafter drafts from the first decode step. */
|
||||
namespace {
|
||||
struct RefillRun {
|
||||
int64_t n_after_first = 0; /* n_computed after the admitting step */
|
||||
int rows = -1; /* drafting rows block_begin offers at the first decode step */
|
||||
SchedMetrics m;
|
||||
};
|
||||
RefillRun refill_run(int n_prompt, int32_t seeded, int64_t ckpt_lo = 0) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/4096, /*states=*/64, /*max_tok=*/512, /*max_ctx=*/8192);
|
||||
f.cfg.n_spec = 7;
|
||||
f.prog.drafter.kind = RAD_DRAFT_BLOCK;
|
||||
f.prog.drafter.window = 512;
|
||||
KVGroupInfo w; /* the drafter's own group: paged, windowed, not prefix-cached */
|
||||
w.name = "draft";
|
||||
w.decl.kind = RAD_KV_WINDOW;
|
||||
w.decl.window = 512;
|
||||
w.block_size = 16;
|
||||
f.prog.kv_groups.push_back(w);
|
||||
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64);
|
||||
f.pc.groups = { 0 };
|
||||
f.pc.ckpt_lo = ckpt_lo;
|
||||
CHECK_OK(f.start());
|
||||
if (seeded > 0) { f.pc.seed(seeded); f.pc.lin = seeded; f.pc.src = 3; }
|
||||
RefillRun r;
|
||||
const uint64_t a = f.submit(n_prompt, 64);
|
||||
Scheduler::BlockRow rows[4];
|
||||
for (int st = 0; st < 40; ++st) {
|
||||
CHECK(f.sch.step() != nullptr);
|
||||
if (st == 0) r.n_after_first = f.sch.find(a)->n_computed;
|
||||
f.commit_plain(11);
|
||||
const int n = f.sch.block_begin(8, 7, 512, 99, rows, 4);
|
||||
f.sch.block_end();
|
||||
if (!f.sch.find(a)->output.empty()) { r.rows = n; break; }
|
||||
}
|
||||
r.m = f.sch.metrics();
|
||||
return r;
|
||||
}
|
||||
} /* namespace */
|
||||
|
||||
TEST(a_prefix_hit_ends_a_drafter_window_before_the_prompt_and_the_drafter_drafts_at_once) {
|
||||
const RefillRun r = refill_run(/*prompt=*/1100, /*seeded=*/1024);
|
||||
/* The cap is 1100 - 512 = 588: attention 576, and the checkpoint under it 512. */
|
||||
CHECK_EQ(r.n_after_first, 512);
|
||||
CHECK_EQ(r.rows, 1);
|
||||
CHECK_EQ(r.m.draft_refills, (int64_t)1);
|
||||
CHECK_EQ(r.m.draft_refill_tokens, (int64_t)512);
|
||||
CHECK_EQ(r.m.linear_cached_tokens, (int64_t)512); /* what was actually skipped */
|
||||
}
|
||||
|
||||
TEST(a_prefix_hit_already_a_window_back_is_kept_whole) {
|
||||
/* 5000 - 512 is past the 1024-token hit: the drafter's window is recomputed anyway. */
|
||||
const RefillRun r = refill_run(5000, 1024);
|
||||
CHECK_EQ(r.n_after_first, 1024);
|
||||
CHECK_EQ(r.m.draft_refills, (int64_t)0);
|
||||
CHECK_EQ(r.rows, 1);
|
||||
}
|
||||
|
||||
TEST(a_prefix_hit_with_no_checkpoint_near_the_cap_is_kept_whole) {
|
||||
/* No checkpoint below 2048: the cap would give back all 2048 tokens, more than two windows,
|
||||
* so the whole hit stands and the drafter waits for its window as it would without a cap. */
|
||||
const RefillRun r = refill_run(2200, 2048, /*ckpt_lo=*/2048);
|
||||
CHECK_EQ(r.m.draft_refills, (int64_t)0);
|
||||
CHECK_EQ(r.m.linear_cached_tokens, (int64_t)2048);
|
||||
CHECK_EQ(r.rows, 0);
|
||||
}
|
||||
|
||||
TEST(no_prefix_hit_gives_nothing_back) {
|
||||
const RefillRun r = refill_run(1100, 0);
|
||||
CHECK_EQ(r.m.draft_refills, (int64_t)0);
|
||||
CHECK_EQ(r.rows, 1);
|
||||
}
|
||||
|
||||
/* ================================================================== speculation */
|
||||
TEST(rejection_rolls_back_paged_kv_and_moves_the_linear_read_offset) {
|
||||
Fixture f;
|
||||
|
||||
@@ -258,6 +258,7 @@ struct FakeScheduler : IScheduler {
|
||||
std::mutex mu;
|
||||
std::vector<uint64_t> submitted;
|
||||
SamplingParams last_sp; /* what the last submitted request was to sample with */
|
||||
std::vector<std::string> last_stop; /* ...and the stop strings it was handed */
|
||||
std::vector<uint64_t> cancelled;
|
||||
std::vector<std::thread> workers;
|
||||
std::atomic<uint64_t> next_id{1};
|
||||
@@ -275,6 +276,7 @@ struct FakeScheduler : IScheduler {
|
||||
std::lock_guard<std::mutex> lk(mu);
|
||||
submitted.push_back(id);
|
||||
last_sp = r.sp;
|
||||
last_stop = r.stop;
|
||||
}
|
||||
void* sink = r.sink;
|
||||
int32_t cap = r.max_tokens;
|
||||
@@ -1797,6 +1799,38 @@ TEST(usage_reports_the_reasoning_tokens_inside_completion_tokens) {
|
||||
}
|
||||
}
|
||||
|
||||
/* A REPLY THAT STARTS INSIDE ITS REASONING BLOCK keeps its stop strings for the answer: one
|
||||
* written while thinking is text, and the first one after the closer cuts. The scheduler, which
|
||||
* cannot tell reasoning from answer, is handed none. A closer of several tokens arrives across
|
||||
* drains, which the incremental search for it has to bridge. */
|
||||
TEST(stop_strings_wait_for_the_reasoning_closer) {
|
||||
for (const char* close : { "|", "</t>" }) {
|
||||
Fixture f;
|
||||
f.tmpl.think_close = close;
|
||||
f.tmpl.think_starts_open = true;
|
||||
f.sched.reply = std::string("aENDb") + close + "cENDd";
|
||||
HttpResponse r = f.post("/v1/chat/completions",
|
||||
R"({"messages":[{"role":"user","content":"hi"}],"stop":["END"]})");
|
||||
CHECK_EQ(r.status, 200);
|
||||
const json j = json::parse(r.body);
|
||||
CHECK_EQ(j["choices"][0]["message"]["content"].get<std::string>(),
|
||||
std::string("aENDb") + close + "c");
|
||||
CHECK_EQ(j["choices"][0]["finish_reason"].get<std::string>(), std::string("stop"));
|
||||
CHECK(f.sched.last_stop.empty());
|
||||
}
|
||||
/* A stop string only inside the reasoning never stops the reply. */
|
||||
Fixture f;
|
||||
f.tmpl.think_close = "|";
|
||||
f.tmpl.think_starts_open = true;
|
||||
f.sched.reply = "aENDb|cd";
|
||||
HttpResponse r = f.post("/v1/chat/completions",
|
||||
R"({"messages":[{"role":"user","content":"hi"}],"stop":["END"]})");
|
||||
CHECK_EQ(r.status, 200);
|
||||
const json j = json::parse(r.body);
|
||||
CHECK_EQ(j["choices"][0]["message"]["content"].get<std::string>(), std::string("aENDb|cd"));
|
||||
CHECK(!f.sched.saw_cancel()); /* ended by the reply itself, not cut */
|
||||
}
|
||||
|
||||
/* THE BUDGET REACHES THE ENGINE in either spelling, with the block it is held on; one the block
|
||||
* cannot hold, a negative one, and two spellings that disagree are 400s naming the field. */
|
||||
TEST(a_thinking_budget_reaches_the_engine_or_is_refused_by_name) {
|
||||
|
||||
@@ -396,6 +396,37 @@ TEST(detokenize_stop_string_straddle) {
|
||||
CHECK_EQ(d.flush(), std::string());
|
||||
}
|
||||
|
||||
/* A reply that starts inside its reasoning block: a stop string written while thinking is text,
|
||||
* not a stop, and the first one after the closer cuts as usual. */
|
||||
TEST(detokenize_stops_wait_for_the_reasoning_closer) {
|
||||
if (!need_vocab("detokenize_stops_wait_for_the_reasoning_closer")) return;
|
||||
Tokenizer t;
|
||||
CHECK_OK(t.init(qwen_vocab()));
|
||||
|
||||
const std::string think = "restating it, Q: what is two and two</think>";
|
||||
std::vector<int32_t> ids;
|
||||
CHECK_OK(t.encode(think + "The answer is 4. Q: next", ids, false, true));
|
||||
Detokenizer d(qwen_vocab(), { "Q:" });
|
||||
d.defer_stops_until("</think>");
|
||||
std::string s;
|
||||
for (int32_t id : ids) {
|
||||
s += d.push(id);
|
||||
if (d.stopped()) break;
|
||||
}
|
||||
CHECK(d.stopped());
|
||||
CHECK_EQ(d.stop_hit(), std::string("Q:"));
|
||||
CHECK_EQ(s, think + "The answer is 4. ");
|
||||
|
||||
/* Without the deferral the same text stops inside the reasoning. */
|
||||
Detokenizer plain(qwen_vocab(), { "Q:" });
|
||||
std::string p;
|
||||
for (int32_t id : ids) {
|
||||
p += plain.push(id);
|
||||
if (plain.stopped()) break;
|
||||
}
|
||||
CHECK_EQ(p, std::string("restating it, "));
|
||||
}
|
||||
|
||||
/* A stop string that never completes must be released at flush() rather than swallowed. */
|
||||
TEST(detokenize_incomplete_stop_is_flushed) {
|
||||
if (!need_vocab("detokenize_incomplete_stop_is_flushed")) return;
|
||||
|
||||
Reference in new issue
Block a user