core: an audio generator of one branch over a hybrid language model -- the driver stages a delta net's state and convolution groups beside the paged one, with each entry's context and num_accepted, the generator loop zeroes the slots a request is granted, and a model may read its input with special tokens (its speaker tags)

This commit is contained in:
zivius committed 2026-10-20 23:07:16 +02:00
1 parent 0c35fc8070
commit baf6e89ecb
13 files changed
+339 -67

No files matched your search

+2
View File
@@ -169,6 +169,8 @@ ABI_FIELD(RadAudioGenDecl, prompt_whole)
ABI_FIELD(RadAudioGenDecl, first_frame)
ABI_FIELD(RadAudioGenDecl, voc_chunk)
ABI_FIELD(RadAudioGenDecl, voc_context)
ABI_FIELD(RadAudioGenDecl, branches)
ABI_FIELD(RadAudioGenDecl, input_special)
ABI_STRUCT(RadAudioFormat)
ABI_FIELD(RadAudioFormat, struct_size)
ABI_FIELD(RadAudioFormat, audio_open)
+3 -1
View File
@@ -134,7 +134,7 @@
{ "RadAudioGenBatch", "voc_left", 244, 4 },
{ "RadAudioGenBatch", "voc_right", 248, 4 },
{ "RadAudioGenBatch", "voc_frame0", 256, 8 },
{ "RadAudioGenDecl", "", 0, 224 },
{ "RadAudioGenDecl", "", 0, 232 },
{ "RadAudioGenDecl", "name", 0, 8 },
{ "RadAudioGenDecl", "tmpl", 8, 8 },
{ "RadAudioGenDecl", "neg_token", 16, 4 },
@@ -166,6 +166,8 @@
{ "RadAudioGenDecl", "first_frame", 204, 4 },
{ "RadAudioGenDecl", "voc_chunk", 208, 8 },
{ "RadAudioGenDecl", "voc_context", 216, 8 },
{ "RadAudioGenDecl", "branches", 224, 4 },
{ "RadAudioGenDecl", "input_special", 228, 4 },
{ "RadAudioFormat", "", 0, 72 },
{ "RadAudioFormat", "struct_size", 0, 4 },
{ "RadAudioFormat", "audio_open", 8, 8 },
+85
View File
@@ -209,4 +209,89 @@ TEST(the_unconditional_branch_is_the_conditional_prompt_at_guidance_one) {
}
}
/* A hybrid language model (paged attention beside a linear-attention state and a convolution
* group, as Qwen3.5's delta-net layers keep) of one branch: every pass stages one sequence a
* request, the state groups' rows are the sequence's slots, and each entry carries its context
* and a one-based num_accepted. The slots held at the prompt are the frames' too; guidance other
* than 1 is refused. */
TEST(a_hybrid_model_of_one_branch_stages_its_state_groups) {
AudioFixture f;
f.prog.audio_gen = decl_chunked();
f.prog.audio_gen.branches = 1;
f.prog.agen_str.name = "hybrid";
f.prog.ctx.max_tok = 64;
f.prog.ctx.max_seqs = 8;
f.prog.kv_groups.emplace_back();
for (int kind : { RAD_KV_FULL, RAD_KV_LINEAR, RAD_KV_CONV }) {
KVGroupInfo g;
g.name = kind == RAD_KV_FULL ? "attn" : kind == RAD_KV_LINEAR ? "state" : "conv";
g.decl.kind = kind;
g.block_size = kind == RAD_KV_FULL ? 16 : 0;
f.prog.kv_groups.push_back(g);
}
f.kv.setup(f.prog.kv_groups, 1 << 20, 256, 4);
CHECK_OK(f.start());
std::string why;
CHECK(f.drv.submit(f.req(2.0f), &why) < 0);
CHECK(has(why, "without guidance"));
CHECK_OK(f.drv.submit(f.req(1.0f), &why));
auto state_rows = [](const RadBatch* b, int32_t* st, int32_t* cv) {
*st = *cv = -2;
for (int i = 0; i < b->n_kv_groups; ++i) {
const RadKVGroupBatch& k = b->kv[i];
if (k.group == 1) continue;
REQUIRE(k.state_index != nullptr && k.block_table != nullptr);
CHECK_EQ(k.block_table[0], k.state_index[0]);
(k.group == 2 ? *st : *cv) = k.state_index[0];
}
};
const RadBatch* b = f.drv.next(0);
REQUIRE(b != nullptr && b->gen == RAD_GEN_PASS_PROMPT);
CHECK_EQ(b->n_seq, (int64_t)1);
CHECK_EQ(b->n_tok, (int64_t)4);
REQUIRE_EQ(b->n_kv_groups, 3);
int32_t st0 = 0, cv0 = 0;
state_rows(b, &st0, &cv0);
CHECK(st0 >= 0 && cv0 >= 0);
REQUIRE(b->ctx_lens != nullptr && b->num_accepted != nullptr);
CHECK_EQ(b->ctx_lens[0], 0);
CHECK_EQ(b->num_accepted[0], 1);
CHECK_EQ(b->agen_b->slot[0], b->agen_b->lane_h[0]); /* one branch: the slot is the lane */
f.answer(b, 0, 0.0f);
CHECK_OK(f.drv.done());
b = f.drv.next(1);
REQUIRE(b != nullptr && b->gen == RAD_GEN_PASS_FRAME);
CHECK_EQ(b->n_seq, (int64_t)1);
CHECK_EQ(b->n_tok, (int64_t)1);
CHECK_EQ(b->positions[0], 4); /* after the four prompt rows */
CHECK_EQ(b->ctx_lens[0], 4);
CHECK_EQ(b->num_accepted[0], 1);
int32_t st1 = 0, cv1 = 0;
state_rows(b, &st1, &cv1);
CHECK_EQ(st1, st0);
CHECK_EQ(cv1, cv0);
}
/* The driver stages one paged group beside state groups: a second paged group is refused at init,
* by name. */
TEST(a_second_paged_group_is_refused) {
AudioFixture f;
f.prog.audio_gen = decl_chunked();
f.prog.agen_str.name = "two";
f.prog.ctx.max_tok = 64;
f.prog.ctx.max_seqs = 8;
f.prog.kv_groups.emplace_back();
for (int i = 0; i < 2; ++i) {
KVGroupInfo g;
g.name = i ? "b" : "a";
g.decl.kind = RAD_KV_FULL;
g.block_size = 16;
f.prog.kv_groups.push_back(g);
}
f.kv.setup(f.prog.kv_groups, 1 << 20, 256, 4);
CHECK(f.start() < 0);
}
RAD_TEST_MAIN()
+22
View File
@@ -174,6 +174,28 @@ TEST(a_speech_model_takes_optional_instructions_and_renders_its_unconditional_pr
CHECK(m.last().neg_tokens.empty());
}
/* A model that declares input_special (its speaker tags are special tokens) has its input
* tokenised with them, and one of one branch refuses any guidance but 1 under its field; other
* models' input stays plain text. */
TEST(a_model_that_asks_has_its_input_read_with_special_tokens_and_one_branch_has_no_guidance) {
Speech s;
s.gen.inf.tmpl_plain = "<s>{input}";
s.gen.inf.default_steps = 0;
s.gen.inf.input_special = true;
s.gen.inf.branches = 1;
s.f->tok.last_parse_special = false;
CHECK_EQ(s.post({ { "input", "hi" } }).status, 200);
CHECK(s.f->tok.last_parse_special);
CHECK_EQ(s.refused({ { "input", "hi" }, { "guidance_scale", 2.0 } }),
std::string("guidance_scale"));
CHECK_EQ(s.post({ { "input", "hi" }, { "guidance_scale", 1.0 } }).status, 200);
Speech m;
m.gen.inf.tmpl_plain = "<s>{input}";
m.gen.inf.default_steps = 0;
CHECK_EQ(m.post({ { "input", "hi" } }).status, 200);
CHECK(!m.f->tok.last_parse_special);
}
/* ================================================================== the response */
/* The whole piece: the windows in order whatever order they were played in, as a WAV whose header