This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/tests/speech_stream_test.cpp
T
Deadcode 9ed3ef7a7b radiance 1.15.0
New models and formats:
- IQR for Qwen3.8-27B: weights on the int8 grid under GPTQ, a trellis down each GPTQ column
  (IQR-V2), and IQR-V3, a computed trellis code under one scale a row, kept at its codes' width in
  VRAM and decoded in the GEMM; 15 IQR-V3 recipes from ~2 to ~7 bits a weight
  (data/recipes/q38-27b-*-v3.recipe, docs/IQR.md)
- libhalo: a kernel library for Strix Halo (gfx1151), preferred there over libr3d
- Nemotron 3.5 Embed 1B and 8B (nemotron35_embed): text and image embeddings through a Pixtral
  tower, on the card and on the CPU
- Nemotron 3.5 Rerank 8B
- /v1/systemone: Cloudflare's clef and clef-flash, Convai Innovations' Laya and Mica beside
  LiquidAI d1; scored steps read the candidates' logits from the head table with no lm_head pass
- LFM2's 8-bit trunk: block-fp8 or int8 linears with the fused producers, and the d1-3B recipe
- DeepSeek-V4.1's reply format with DSML tool calls and typed argument tags

Weights on the drive:
- The file tier reads only the experts the pass routes rows to; the draft head's weights stay in
  the host pool
- A hot VRAM cache for routed experts read off the drive, reads deposited straight into free host
  pool slots, and copyless evictions; the file tier's counters are now ssd_*
- GLM-5 Next shards its routed experts by expert, not by width, so they can live on the drive
- The stall watch counts drive reads as progress, and the DMA lane's room check reads the lane's
  own completion fence

Quantisation tooling:
- --calib-corpus, --calib-dir and --calib-layers record each linear's input Hessian; beside
  --kld-record the reference's own run records them
- --kld-top N records a sparse KL reference (the N most likely tokens and the tail's mass)
- GPTQ in a third of the time with the same codes, trellis GPTQ on the card, vector codebooks
  with coordinate descent, and rad-convert --reuse repeated, each container supplying what the
  earlier ones lack

Speculation:
- Prompt lookup alone (--spec-ngram K, --spec-ngram-min/-max): each sequence keeps an index of its
  n-grams, and a proposal is verified only when its measured step cost says it pays;
  --draft-window adaptive follows it

Speed:
- IQR decode: the narrow tile splits K for four times the int8 tile's waves and folds each 128-K
  block once; at 8 tokens down and the output projections run in 0.61-0.82x and 0.70-0.92x FP8's
  time (2-6 bits); IQ6R-S-V3 with its DFlash2 drafter steps in 26.3 ms at TP2, against 29.4 ms
  before and FP8's 27.3
- Qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8
- libr4d: the gated prefill fold, the short-prompt split row, and the rows forms of rmsnorm and
  rope; KLATE again for the head-256 gqa6 paged prefill; gram_accum on the matrix cores

Features:
- /health, /v1/health and /ping answer 503 with "status": "stuck" once the device has advanced
  nothing for a minute or a queue has faulted, so a supervisor can restart a wedged server (#356)
- --image-gen-max-pixels and --image-gen-max-refs size an image generator's buffers (#344)
- The startup report lists only the options not at their default, with a count; -v lists all
  (#250)
- --preempt-wait-ms bounds how long a preempted prefill waits for its whole-recompute room
- --placement layer_offload spills dense layers so one --max-model-len sequence fits
- Startup refuses amdgpu with CWSR off and says how to fix it;
  --proceed-with-incompatible-configuration starts anyway under an UNSUPPORTED banner

Fixes:
- The n-gram read-ahead hands each row to the reader once and reads only as far ahead as the row
  cache holds, and pauses while decode reads: about one drive read a row instead of two (#355)
- A file-tier window reads each of its runs once, not once a run per run
- The decode split law's verify floor is bounded by the batch's workgroups: max_seqs 256 no longer
  declares 64x the scratch (#342)
- A prefetch DMA list's mark stays out of the signal pool until the engine has read it, and a
  prefill stage copies only the blocks its own tables name (#343)
- The split-KV row sum is read with fetch-inactive (#328)
- LFM2 on the host backend: libref and libavx serve the row-form ops it declares (#348)
- The preempted-prefill gate skips a KV group that holds no blocks (#352)
- Every request entry point bounded, gated and sanitised (JSON depth, invalid UTF-8, control bytes
  in the log, the dashboard's CSP, cross-origin browsers on the loopback-only routes); a prompt id
  outside the vocabulary refused at admission; --api-key "" refused at startup
- The telemetry the HTTP thread reads is atomic
- An RMS norm row no longer depends on how many rows its launch carries; prefill attention's
  rescale is decided by live rows only
- A --kld-record prefill chunk that finishes no sequence gets its logits on a tied-head model
- A kernel's lazily made counter block is zeroed outside the lock other ranks take (a TP2 first-step
  hang)

Changes: Plugin ABI 32. Every plugin exports a layout fingerprint of the ABI structs and the loader
refuses a plugin without it or with another (#302), so out-of-tree plugins must be rebuilt.
Appended: RadBuildCtx calib_* and gen_max_*, RadArchProbe gen_max_*, RadBatch score_only and
plugin_words, RadDeviceProps::unified, RadChatFormat arg_json_value_prefix.
2026-10-30 22:01:01 +01:00

388 lines
16 KiB
C++

/* tests/speech_stream_test.cpp -- vLLM-Omni's realtime speech session over a WebSocket
* (core/server/speech_stream.cpp), against server_fakes.h's audio generator.
*
* These pin what the server owns: that text sent in pieces is spoken a sentence at a time in
* order, each sentence's events around its audio, the audio the same bytes the POST route gives
* for the same request, sent whole or as it is made and as PCM or WAV, the utterance's end, the
* refusals that leave the session going, and a close that cancels the sentence being spoken.
*/
#include "server_fakes.h"
#include <chrono>
#include <condition_variable>
#include <cstring>
#include <deque>
#include <thread>
namespace {
/* A WebSocket the test plays the client of: what the session sends, text and binary, in order. */
struct Conn : WsConn {
std::mutex m;
std::condition_variable cv;
std::deque<std::string> in;
bool hung_up = false;
bool closed = false;
int close_code = 0;
std::vector<std::pair<std::string, bool>> out; /* (message, binary) */
bool read(std::string* msg, bool* binary) override {
std::unique_lock<std::mutex> lk(m);
cv.wait(lk, [&] { return !in.empty() || hung_up || closed; });
if (in.empty()) return false;
*msg = std::move(in.front());
*binary = false;
in.pop_front();
return true;
}
bool send(const std::string& t) override { return put(t, false); }
bool send_binary(const std::string& b) override { return put(b, true); }
bool put(const std::string& t, bool binary) {
std::lock_guard<std::mutex> lk(m);
out.emplace_back(t, binary);
cv.notify_all();
return !closed;
}
void close(int code, const std::string&) override {
std::lock_guard<std::mutex> lk(m);
closed = true;
close_code = code;
cv.notify_all();
}
void client(const json& j) {
std::lock_guard<std::mutex> lk(m);
in.push_back(j.dump());
cv.notify_all();
}
void hangup() {
std::lock_guard<std::mutex> lk(m);
hung_up = true;
cv.notify_all();
}
/* The `nth` event of `type` (from 0), waiting for it; null when it does not come. */
json wait_for(const std::string& type, size_t nth = 0, int timeout_ms = 10000) {
std::unique_lock<std::mutex> lk(m);
const auto until = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout_ms);
for (;;) {
size_t seen = 0;
for (const auto& o : out) {
if (o.second) continue;
json j = json::parse(o.first);
if (j.value("type", "") == type && seen++ == nth) return j;
}
if (cv.wait_until(lk, until) == std::cv_status::timeout) return json();
}
}
bool wait_closed(int timeout_ms = 10000) {
std::unique_lock<std::mutex> lk(m);
return cv.wait_for(lk, std::chrono::milliseconds(timeout_ms), [&] { return closed; });
}
/* Every message so far: an event's type, or "#<bytes>" for a binary one. */
std::vector<std::string> trace() {
std::lock_guard<std::mutex> lk(m);
std::vector<std::string> t;
for (const auto& o : out)
t.push_back(o.second ? "#" + std::to_string(o.first.size())
: json::parse(o.first).value("type", ""));
return t;
}
/* The binary messages between sentence `k`'s audio.start and audio.done, in order. */
std::vector<std::string> frames(int64_t k) {
std::lock_guard<std::mutex> lk(m);
std::vector<std::string> f;
bool in_k = false;
for (const auto& o : out) {
if (o.second) {
if (in_k) f.push_back(o.first);
continue;
}
const json j = json::parse(o.first);
if (j.value("type", "") == "audio.start") in_k = j.value("sentence_index", -1) == k;
if (j.value("type", "") == "audio.done") in_k = false;
}
return f;
}
};
/* A server over the fake generator with one session connected to it. */
struct Stream {
FakeAudioGen gen;
std::unique_ptr<Fixture> f;
Conn conn;
std::thread route;
Stream() {
f.reset(new Fixture(Fixture::Tweak{ [this](ServerOptions& o, Deps& d) {
d.audio = &gen;
o.audio_model = true;
} }));
const SocketHandler* h = f->srv->router().socket_for("/v1/audio/speech/stream");
REQUIRE(h != nullptr);
route = std::thread([this, h] {
HttpRequest q;
q.method = "GET";
q.path = "/v1/audio/speech/stream";
(*h)(q, conn);
});
}
~Stream() {
conn.hangup();
if (route.joinable()) route.join();
}
void config(json extra = json::object()) {
json c = { { "type", "session.config" }, { "instructions", "calm" } };
for (auto it = extra.begin(); it != extra.end(); ++it) c[it.key()] = it.value();
conn.client(c);
}
void text(const std::string& t) { conn.client({ { "type", "input.text" }, { "text", t } }); }
void done() { conn.client({ { "type", "input.done" } }); }
/* The POST route's audio for the same request: the fake's samples, whatever the text. */
std::string post_pcm() {
json b = { { "input", "x" }, { "instructions", "calm" }, { "response_format", "pcm" } };
HttpResponse r = f->post("/v1/audio/speech", b.dump());
CHECK_EQ(r.status, 200);
return r.body;
}
};
std::string joined(const std::vector<std::string>& v) {
std::string s;
for (const auto& x : v) s += x;
return s;
}
uint32_t le32(const std::string& s, size_t at) {
uint32_t v = 0;
std::memcpy(&v, s.data() + at, 4);
return v;
}
} /* namespace */
/* Text sent in pieces is spoken a sentence at a time, in order: each sentence an audio.start
* naming it, its audio in one binary message (the bytes the POST route gives for the same
* request), and an audio.done counting them; the utterance ends with session.done once its last
* sentence, the text input.done flushed, is spoken. Each sentence is its own request, rendered
* from the session's instructions. The session then takes the next utterance. */
TEST(text_in_pieces_is_spoken_a_sentence_at_a_time) {
Stream s;
const std::string pcm = s.post_pcm();
s.config();
s.text("Hello wor");
s.text("ld. How are ");
s.text("you? Fine");
s.done();
const json end = s.conn.wait_for("session.done");
REQUIRE(!end.is_null());
CHECK_EQ(end.value("utterance_index", -1), 0);
CHECK_EQ(end.value("total_sentences", -1), 3);
const std::string n = "#" + std::to_string(pcm.size());
CHECK(s.conn.trace() == std::vector<std::string>({ "audio.start", n, "audio.done",
"audio.start", n, "audio.done",
"audio.start", n, "audio.done",
"session.done" }));
const char* want[] = { "Hello world.", "How are you?", "Fine" };
for (int k = 0; k < 3; ++k) {
const json st = s.conn.wait_for("audio.start", (size_t)k);
CHECK_EQ(st.value("sentence_index", -1), k);
CHECK_EQ(st.value("sentence_text", ""), std::string(want[k]));
CHECK_EQ(st.value("format", ""), std::string("pcm"));
CHECK_EQ(st.value("sample_rate", 0), 8000);
CHECK_EQ(st.value("channels", 0), 2);
const json dn = s.conn.wait_for("audio.done", (size_t)k);
CHECK_EQ(dn.value("total_bytes", -1), (int)pcm.size());
CHECK_EQ(dn.value("error", true), false);
CHECK(joined(s.conn.frames(k)) == pcm);
}
/* The POST request was the first; the sentences are the three after it. */
REQUIRE_EQ(s.gen.n_got(), (size_t)4);
CHECK_EQ(s.gen.prompt_of(1), std::string("<s>calm|Hello world."));
CHECK_EQ(s.gen.prompt_of(2), std::string("<s>calm|How are you?"));
CHECK_EQ(s.gen.prompt_of(3), std::string("<s>calm|Fine"));
s.text("Again.");
s.done();
const json next = s.conn.wait_for("session.done", 1);
REQUIRE(!next.is_null());
CHECK_EQ(next.value("utterance_index", -1), 1);
CHECK_EQ(next.value("total_sentences", -1), 1);
CHECK_EQ(s.conn.wait_for("audio.start", 3).value("sentence_index", -1), 0);
CHECK(!s.conn.closed);
}
/* With stream_audio the audio goes out as the generator makes it, in order however its pieces
* arrive: here windows 1, 0, 2 become two messages, the first two windows and the third, which
* together are the whole response's bytes. A WAV says its length in one message, and while it
* streams opens with a header that states none. */
TEST(audio_is_sent_whole_or_as_it_is_made_as_pcm_or_wav) {
{
Stream s;
const std::string pcm = s.post_pcm();
s.config({ { "stream_audio", true } });
s.text("One.");
s.done();
REQUIRE(!s.conn.wait_for("session.done").is_null());
const std::vector<std::string> f = s.conn.frames(0);
CHECK_EQ(f.size(), (size_t)2);
CHECK(joined(f) == pcm);
CHECK_EQ(s.conn.wait_for("audio.done").value("total_bytes", -1), (int)pcm.size());
}
{
Stream s;
const std::string pcm = s.post_pcm();
s.config({ { "response_format", "wav" } });
s.text("One.");
s.done();
REQUIRE(!s.conn.wait_for("session.done").is_null());
CHECK_EQ(s.conn.wait_for("audio.start").value("format", ""), std::string("wav"));
const std::vector<std::string> f = s.conn.frames(0);
REQUIRE_EQ(f.size(), (size_t)1);
REQUIRE(f[0].size() == 44 + pcm.size());
CHECK_EQ(f[0].substr(0, 4), std::string("RIFF"));
CHECK_EQ(le32(f[0], 40), (uint32_t)pcm.size());
CHECK(f[0].substr(44) == pcm);
}
{
Stream s;
const std::string pcm = s.post_pcm();
s.config({ { "response_format", "wav" }, { "stream_audio", true } });
s.text("One.");
s.done();
REQUIRE(!s.conn.wait_for("session.done").is_null());
const std::vector<std::string> f = s.conn.frames(0);
REQUIRE_EQ(f.size(), (size_t)3);
CHECK_EQ(f[0].size(), (size_t)44);
CHECK_EQ(le32(f[0], 40), 0xffffffffu);
CHECK(f[1] + f[2] == pcm);
CHECK_EQ(s.conn.wait_for("audio.done").value("total_bytes", -1), (int)(44 + pcm.size()));
}
}
/* A message the session cannot take is answered with an error naming it, and the session goes on:
* text before any configuration, an unknown message type, the commitment text mode, a field the
* configuration does not have (or the input in it), a bad granularity or format, a request field
* the model refuses. A configuration refused is not applied; a later one is, and the text after it
* is spoken. */
TEST(a_speech_session_refuses_what_it_cannot_take_and_goes_on) {
Stream s;
size_t n = 0;
auto refused = [&](const json& msg, const char* param, const char* says) {
s.conn.client(msg);
const json e = s.conn.wait_for("error", n++);
REQUIRE(!e.is_null());
if (param) CHECK_EQ(e.value("param", std::string()), std::string(param));
const bool named = has(e.value("message", ""), says);
CHECK(named);
if (!named) std::fprintf(stderr, " error said: %s\n", e.value("message", "").c_str());
};
refused({ { "type", "input.text" }, { "text", "Hi." } }, nullptr, "session.config");
refused({ { "type", "response.create" } }, "type", "response.create");
refused({ { "type", "session.config" }, { "text_input_mode", "commitment" } },
"text_input_mode", "commitment");
refused({ { "type", "session.config" }, { "temperature", 0.5 } }, "temperature",
"temperature");
refused({ { "type", "session.config" }, { "input", "Hi." } }, "input", "input.text");
refused({ { "type", "session.config" }, { "split_granularity", "word" } },
"split_granularity", "clause");
refused({ { "type", "session.config" }, { "response_format", "mp3" } }, "response_format",
"pcm or wav");
refused({ { "type", "session.config" }, { "instructions", "calm" }, { "guidance_scale", 0.5 } },
"guidance_scale", "[1, 30]");
refused({ { "type", "session.config" } }, "instructions", "instructions");
/* None of it applied: text still waits for a configuration. */
refused({ { "type", "input.done" } }, nullptr, "session.config");
s.config({ { "split_granularity", "clause" } });
s.text("Yes, no");
s.done();
REQUIRE(!s.conn.wait_for("session.done").is_null());
CHECK_EQ(s.conn.wait_for("audio.start", 0).value("sentence_text", ""), std::string("Yes,"));
CHECK_EQ(s.conn.wait_for("audio.start", 1).value("sentence_text", ""), std::string("no"));
CHECK(!s.conn.closed);
}
/* A frame that is brackets alone, nested tens of thousands deep, is still valid JSON: parsing it
* into a tree and tearing that tree down both recurse once per level, so the session parses it
* bounded -- the tree never outgrows the stack -- answers its invalid-message error, and goes on.
*/
TEST(a_deeply_nested_frame_is_refused_not_fatal) {
Stream s;
const std::string deep = std::string(20000, '[') + std::string(20000, ']');
{
std::lock_guard<std::mutex> lk(s.conn.m);
s.conn.in.push_back(deep);
s.conn.cv.notify_all();
}
CHECK(!s.conn.wait_for("error").is_null());
CHECK(!s.conn.closed);
s.config();
s.text("Still here.");
s.done();
REQUIRE(!s.conn.wait_for("session.done").is_null());
}
/* A sentence the generator refuses or fails is an error and an audio.done saying so; the next
* sentence is spoken as usual. */
TEST(a_failed_sentence_says_so_and_the_next_is_spoken) {
Stream s;
s.config();
s.gen.finish_status = RAD_E_IO;
s.gen.finish_why = "the vocoder ran out of memory";
s.text("One. ");
const json e = s.conn.wait_for("error");
REQUIRE(!e.is_null());
CHECK_EQ(e.value("message", ""), s.gen.finish_why);
const json d = s.conn.wait_for("audio.done");
REQUIRE(!d.is_null());
CHECK_EQ(d.value("error", false), true);
CHECK_EQ(d.value("total_bytes", -1), 0);
s.gen.finish_status = RAD_OK;
s.text("Two.");
s.done();
REQUIRE(!s.conn.wait_for("session.done").is_null());
CHECK_EQ(s.conn.wait_for("audio.done", 1).value("error", true), false);
/* A sentence too long for the model's prompt is refused by name before it runs. */
s.text(std::string(80, 'a') + ".");
s.done();
const json e2 = s.conn.wait_for("error", 1);
REQUIRE(!e2.is_null());
CHECK_EQ(e2.value("param", std::string()), std::string("input"));
CHECK(!s.conn.wait_for("session.done", 1).is_null());
}
/* session.close ends the session at once: the sentence being spoken is cancelled and the socket
* is closed normally. The admission place the session held comes back. */
TEST(session_close_cancels_the_sentence_being_spoken) {
Stream s;
s.gen.hold = true;
s.config();
s.text("Hello there. More");
REQUIRE(!s.conn.wait_for("audio.start").is_null());
for (int i = 0; i < 1000 && s.gen.n_got() == 0; ++i)
std::this_thread::sleep_for(std::chrono::milliseconds(2));
REQUIRE_EQ(s.gen.n_got(), (size_t)1);
CHECK_EQ(s.f->srv->in_flight(), (int64_t)1);
s.conn.client({ { "type", "session.close" } });
REQUIRE(s.conn.wait_closed());
CHECK_EQ(s.conn.close_code, 1000);
s.route.join();
CHECK(s.gen.ticket_of(0)->cancel.load());
CHECK_EQ(s.f->srv->in_flight(), (int64_t)0);
CHECK(s.conn.wait_for("audio.done", 0, 100).is_null());
}
/* A plain GET of the path is told it is a socket; a model that makes no audio refuses the session
* and closes it. */
TEST(the_speech_socket_wants_an_upgrade_and_an_audio_model) {
Fixture text_model;
CHECK_EQ(text_model.srv->router().call("GET", "/v1/audio/speech/stream").status, 426);
Conn c;
HttpRequest q;
q.path = "/v1/audio/speech/stream";
(*text_model.srv->router().socket_for("/v1/audio/speech/stream"))(q, c);
CHECK(c.closed);
CHECK_EQ(c.close_code, 1008);
REQUIRE(!c.out.empty());
CHECK(has(c.out.front().first, "audio generation model"));
}
RAD_TEST_MAIN()