radiance 1.0.6

- A text prompt to /v1/completions reads the model's control tokens as tokens, as vLLM and
  llama.cpp do. A client that renders its own chat template can send "<|im_start|>user ..." and
  the model sees the turn markers; they used to reach it as plain text. /tokenize and
  /v1/embeddings read a text prompt the same way, and a prompt that already opens with BOS gets
  no second one.
- The VRAM budget counts the engine's own hardware queues, which the driver backs with about
  33 MiB of VRAM each, and the KV tiers' copy staging. Both used to come out of
  --gpu-headroom-mib: Qwen3.8-Flash-Next ran with 9 MiB free under load against the 96 MiB it
  asked to keep, the room a kernel's first launch allocates from. The startup receipt has a
  "hardware queues" line.
- Running the whole model on the CPU (RADIANCE_HOST_DOMAIN=1 with no GPU visible) no longer
  repeats words or answers differently at temperature 0. A decode step could read its input
  token before the copy that delivers it had landed.
- The README says to clone the repository before installing.
This commit is contained in:
Deadcode committed 2026-10-04 20:07:08 +02:00
1 parent 6c11671bdd
commit 6df26315b9
25 files changed
+432 -82

No files matched your search

+63
View File
@@ -12,6 +12,7 @@
#include "rad_internal.h"
#include "device/device.h"
#include "device/directio.h"
#include "sched/advance.h"
#include <cstdio>
#include <cstdlib>
@@ -471,6 +472,68 @@ TEST(waiting_on_an_unrecorded_event_is_a_no_op) {
CHECK_OK(rad_stream_sync(st.s));
}
/* AN ADVANCE RUNS AT ITS PLACE IN STREAM ORDER. The sampled token it accepts is the last thing a
* step copies into place, and the advance is issued behind that copy without a host wait. The
* host backend's streams are queues with a worker thread each, so an advance run on the issuing
* thread without draining the stream read the token before the copy landed, and the next step
* continued from the previous token: CPU-only decode repeated words and differed at temperature
* 0. A long chain of copies goes ahead of the token's here, so an advance that jumps the queue
* reads the poison. */
TEST(an_advance_reads_the_token_a_copy_issued_before_it_delivers) {
const int64_t big = 4 << 20;
const int chain = 16;
RadStream s = nullptr;
REQUIRE(rad_stream_create(&s, 0) >= 0);
auto* blob_src = (uint8_t*)rad_dev_alloc(big, RAD_MEM_HOST_PINNED);
auto* blob_dst = (uint8_t*)rad_dev_alloc(big, RAD_MEM_DEVICE);
auto* slab = (char*)rad_dev_alloc(4096, RAD_MEM_DEVICE);
auto* src = (int32_t*)rad_dev_alloc(64, RAD_MEM_DEVICE);
auto* st = (rad::StepSlot*)rad_dev_alloc((int64_t)sizeof(rad::StepSlot), RAD_MEM_DEVICE);
auto* stage = (int32_t*)rad_dev_alloc(4096, RAD_MEM_HOST_PINNED);
REQUIRE(blob_src && blob_dst && slab && src && st && stage);
std::memset(blob_src, 0x5A, (size_t)big);
/* One device row that sampled row 0 with no drafts, at context 10, slot 0. */
rad::AdvanceArgs a;
a.mode = rad::ADV_ACCEPT;
a.n_seq = 1;
a.slab = slab;
a.row_off = 0; a.row_pitch = 1;
a.tok_off = 16; a.pos_off = 24; a.ctx_off = 32; a.acc_off = 40; a.out_off = 48;
a.sid_off = 56; a.cu_off = 64; a.q_off = 72; a.grp_off = 80;
a.st = st;
a.src = src;
const int32_t layout[20] = { 1, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
std::memcpy(stage, layout, sizeof(layout));
for (int round = 0; round < 3; ++round) {
stage[64] = 7; /* the poison: what src holds before the copy */
stage[65] = 4242 + round; /* the token the copy delivers */
REQUIRE(rad_memcpy_async(slab, stage, sizeof(layout), s) >= 0);
REQUIRE(rad_memcpy_async(src, stage + 64, 4, s) >= 0);
REQUIRE(rad_memset_async(st, 0, (int64_t)sizeof(rad::StepSlot), s) >= 0);
REQUIRE(rad_stream_sync(s) >= 0);
for (int i = 0; i < chain; ++i) REQUIRE(rad_memcpy_async(blob_dst, blob_src, big, s) >= 0);
REQUIRE(rad_memcpy_async(src, stage + 65, 4, s) >= 0);
CHECK_OK(rad::step_advance(a, s));
rad::StepSlot got{};
REQUIRE(rad_memcpy_async(stage + 128, st, (int64_t)sizeof(rad::StepSlot), s) >= 0);
REQUIRE(rad_stream_sync(s) >= 0);
std::memcpy(&got, stage + 128, sizeof(rad::StepSlot));
CHECK_EQ(got.tok[0], 4242 + round);
CHECK_EQ(got.ctx, 11);
CHECK_EQ(got.n_acc, 1);
}
rad_dev_free(stage, RAD_MEM_HOST_PINNED);
rad_dev_free(st, RAD_MEM_DEVICE);
rad_dev_free(src, RAD_MEM_DEVICE);
rad_dev_free(slab, RAD_MEM_DEVICE);
rad_dev_free(blob_dst, RAD_MEM_DEVICE);
rad_dev_free(blob_src, RAD_MEM_HOST_PINNED);
rad_stream_destroy(s);
}
TEST(the_null_stream_is_refused) {
/* HIP's stream 0 serialises against every other blocking stream in the process, which is the
* opposite of what a transfer is for here. Refusing it on both backends means a caller cannot
+45
View File
@@ -307,6 +307,51 @@ TEST(a_dense_model_has_no_expert_share_to_lose) {
CHECK(c.vram_weights_mib * MiB - f.statics < MiB);
}
/* THE ENGINE'S HARDWARE QUEUES ARE A FIXED TERM. Each one costs the card VRAM the driver backs it
* with, and the streams are made after the card is read, so a split that left them out spent
* them out of the headroom: 67 MiB a card on a two-card Flash-Next server, leaving 9 MiB free
* under load against 96. The rank that needs most sets the term, as every fold here does. */
TEST(the_engine_s_queues_come_off_the_card_before_the_split) {
Config c = small_config();
c.vram_weights_mib = 0;
c.vram_kv_mib = 0;
c.gpu_headroom_mib = 96;
c.expert_cache_ratio = 0.75;
VramFacts f{};
f.capacity = 32LL << 30;
f.free = f.capacity - (512LL << 20);
f.arena = 144LL << 20;
f.staging = 98LL << 20;
f.statics = 2LL << 30;
f.experts = 200LL << 30;
f.kv_ceiling = 100LL << 30;
VramBudget b0;
CHECK_OK(vram_budget_resolve(c, { f }, &b0));
/* A fresh config: the resolver writes its answer back into the one it is given. */
Config c2 = small_config();
c2.vram_weights_mib = 0;
c2.vram_kv_mib = 0;
c2.gpu_headroom_mib = 96;
c2.expert_cache_ratio = 0.75;
VramFacts g = f, h = f;
g.n_queues = 2; g.queue_bytes = 33LL << 20;
h.n_queues = 3; h.queue_bytes = 33LL << 20; /* a rank with a second compute lane */
VramBudget b;
CHECK_OK(vram_budget_resolve(c2, { g, h }, &b));
CHECK_EQ(b.queues, 99LL << 20);
CHECK_EQ(b.n_queues, 3);
CHECK_EQ(b.claimable, b0.claimable - (99LL << 20));
CHECK(b.report.find("hardware queues") != std::string::npos);
/* What is left after the pools is still the headroom, with the queues and the staging paid. */
const int64_t MiB = 1024 * 1024;
const int64_t unclaimed = f.capacity - (512LL << 20) - f.arena - f.staging - b.queues
- c2.vram_weights_mib * MiB - c2.vram_kv_mib * MiB;
CHECK(unclaimed >= 96 * MiB);
CHECK(unclaimed < 98 * MiB);
}
TEST(a_stated_budget_still_wins_and_the_other_side_still_derives) {
Config c = small_config();
c.vram_weights_mib = 20000; /* stated */
+44
View File
@@ -20,6 +20,7 @@
#include "runtime/ctx.h"
#include "runtime/rank_barrier.h"
#include "runtime/residency.h"
#include "runtime/wtab.h"
#include <chrono>
#include <cstdlib>
@@ -1261,4 +1262,47 @@ TEST(arena_plan_bytes_returns_the_total_with_or_without_its_out_parameters) {
CHECK_EQ(a, total);
}
/* A WEIGHT-TABLE PATCH LANDS AT ITS PLACE IN STREAM ORDER: work issued before it reads the old
* entry, work issued after it the new one. On the host backend the patch is a host write, and
* made without draining the stream it reached the table before a queued reader issued ahead of
* it. A chain of copies holds that reader back long enough for a write that jumps the queue to
* show. */
TEST(a_weight_table_patch_lands_in_stream_order) {
const int64_t big = 4 << 20;
const int chain = 16;
RadStream s = nullptr;
REQUIRE(rad_stream_create(&s, 0) >= 0);
auto* blob_src = (uint8_t*)rad_dev_alloc(big, RAD_MEM_HOST_PINNED);
auto* blob_dst = (uint8_t*)rad_dev_alloc(big, RAD_MEM_DEVICE);
auto* tab = (void**)rad_dev_alloc(64, RAD_MEM_DEVICE);
auto* stage = (void**)rad_dev_alloc(64, RAD_MEM_HOST_PINNED);
REQUIRE(blob_src && blob_dst && tab && stage);
std::memset(blob_src, 0x5A, (size_t)big);
for (int round = 0; round < 3; ++round) {
void* const before = (void*)(uintptr_t)(0x1000 + round);
void* const after = (void*)(uintptr_t)(0x2000 + round);
stage[0] = before;
stage[1] = stage[2] = nullptr;
REQUIRE(rad_memcpy_async(tab, stage, sizeof(void*), s) >= 0);
REQUIRE(rad_stream_sync(s) >= 0);
for (int i = 0; i < chain; ++i) REQUIRE(rad_memcpy_async(blob_dst, blob_src, big, s) >= 0);
REQUIRE(rad_memcpy_async(stage + 1, tab, sizeof(void*), s) >= 0);
rad::WtabPatch p;
p.n = 1;
p.dst[0] = tab;
p.val[0] = after;
CHECK_OK(rad::wtab_patch(p, s));
REQUIRE(rad_memcpy_async(stage + 2, tab, sizeof(void*), s) >= 0);
REQUIRE(rad_stream_sync(s) >= 0);
CHECK(stage[1] == before);
CHECK(stage[2] == after);
}
rad_dev_free(stage, RAD_MEM_HOST_PINNED);
rad_dev_free(tab, RAD_MEM_DEVICE);
rad_dev_free(blob_dst, RAD_MEM_DEVICE);
rad_dev_free(blob_src, RAD_MEM_HOST_PINNED);
rad_stream_destroy(s);
}
RAD_TEST_MAIN()
+18 -4
View File
@@ -2157,14 +2157,28 @@ TEST(tokenize_takes_a_prompt_or_messages_and_never_both) {
CHECK_EQ(f.post("/tokenize", "[1,2]").status, 400);
}
TEST(tokenize_never_lets_the_caller_choose_parse_special) {
TEST(a_raw_prompt_parses_control_tokens_on_every_endpoint_that_takes_one) {
/* A client that renders its own chat template sends "<|im_start|>" meaning the token, as vLLM
* and llama.cpp read it. /tokenize must count what /v1/completions will see. */
Fixture f;
/* A control token in `prompt` is raw text, or an /v1/completions built from these ids reaches
* the system role. The chat form is the opposite and must parse them. */
f.tok.last_parse_special = false;
CHECK_EQ(f.post("/v1/completions", R"({"prompt":"<|im_start|>user","max_tokens":4})").status, 200);
CHECK(f.tok.last_parse_special);
f.tok.last_parse_special = false;
CHECK_EQ(f.post("/v1/completions", R"({"prompt":["a","b"],"max_tokens":4})").status, 200);
CHECK(f.tok.last_parse_special);
f.tok.last_parse_special = false;
f.post("/tokenize", R"({"prompt":"<|im_start|>"})");
CHECK(!f.tok.last_parse_special);
CHECK(f.tok.last_parse_special);
f.tok.last_parse_special = false;
f.post("/tokenize", R"({"messages":[{"role":"user","content":"hi"}]})");
CHECK(f.tok.last_parse_special);
for (const char* body : {R"({"input":"<|im_start|>"})", R"({"input":["a","b"]})"}) {
OaiRequest r; ApiError e;
f.tok.last_parse_special = false;
CHECK_OK(parse_embeddings_request(body, f.odeps(), f.limits(), &r, &e));
CHECK(f.tok.last_parse_special);
}
}
TEST(detokenize_answers_under_the_key_vllm_uses) {
+26
View File
@@ -515,6 +515,32 @@ TEST(the_encoder_matches_the_reference_on_trained_vocabularies) {
}
}
/* A TEXT THAT OPENS WITH BOS GETS NO SECOND ONE. A client rendering its own chat template writes
* the BOS into the prompt; one the text spells anywhere else, or a second one at the start, is
* the client's and stays. */
TEST(a_text_that_opens_with_bos_gets_no_second_one) {
VocabBuild vb;
REQUIRE(parse_tokenizer_json_buf(k_tiny, "test.json", vb) >= 0);
vb.bos = 12;
vb.add_bos = true;
auto v = load(std::move(vb));
REQUIRE(v != nullptr);
Tokenizer t;
CHECK_OK(t.init(v));
auto enc = [&](const char* s, bool add_special, bool parse_special) {
std::vector<int32_t> ids;
t.encode(s, ids, add_special, parse_special);
return ids;
};
CHECK(enc("ab", true, true) == (std::vector<int32_t>{ 12, 4 }));
CHECK(enc("<|end|>ab", true, true) == (std::vector<int32_t>{ 12, 4 }));
CHECK(enc("<|end|><|end|>ab", true, true) == (std::vector<int32_t>{ 12, 12, 4 }));
CHECK(enc("ab<|end|>", true, true) == (std::vector<int32_t>{ 12, 4, 12 }));
CHECK(enc("<|end|>ab", false, true) == (std::vector<int32_t>{ 12, 4 }));
/* Not parsed, the spelling is not the token, so the BOS is still owed. */
CHECK(enc("<|end|>x", true, false) == (std::vector<int32_t>{ 12, 11 }));
}
/* SPECIAL TOKENS ARE CLAIMED LONGEST FIRST, not leftmost: "bcde" wins over "ab" in "abcde" even
* though "ab" starts earlier, and "<|im_start|>" is never cut by its prefix "<|im". */
TEST(special_tokens_are_claimed_by_priority) {