radiance 1.7.0

- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-16 18:25:18 +02:00
1 parent b068190326
commit 1e968f6e1d
739 files changed
+128447 -84632

No files matched your search

+26 -25
View File
@@ -98,6 +98,7 @@ int Bench::bind(const ChatRequest& rq, const ojson& tools, std::string* why) {
req_ = rq;
tools_ = tools;
prompt_ = ChatPrompt{};
replies_.clear();
const ChatOptions opt = options_for(rq);
if (tmpl_->apply(user_turn(), rq.tools ? tools_ : ojson(), opt, &prompt_) < 0) {
*why = "render failed: " + prompt_.error;
@@ -127,17 +128,26 @@ ReplyMessage Bench::new_parse(const std::string& text, bool* strict) const {
}
std::string Bench::render_reply(const ojson& assistant) const {
/* A render is a function of the template, the request and the message, and the first two are
* fixed for a bench; the corpora render the same messages many times. */
std::string key = assistant.dump();
auto it = replies_.find(key);
if (it != replies_.end()) return it->second;
return replies_[std::move(key)] = render_reply_uncached(assistant);
}
std::string Bench::render_reply_uncached(const ojson& assistant) const {
/* The head is bind()'s render: the same user turn, tools and options. */
const std::string& head = prompt_.prompt;
ChatOptions opt = options_for(req_);
ChatPrompt head, whole;
if (tmpl_->apply(user_turn(), req_.tools ? tools_ : ojson(), opt, &head) < 0) return "";
ChatPrompt whole;
ojson msgs = user_turn();
msgs.push_back(assistant);
opt.add_generation_prompt = false;
if (tmpl_->apply(msgs, req_.tools ? tools_ : ojson(), opt, &whole) < 0) return "";
if (whole.prompt.size() < head.prompt.size() ||
whole.prompt.compare(0, head.prompt.size(), head.prompt) != 0)
if (whole.prompt.size() < head.size() || whole.prompt.compare(0, head.size(), head) != 0)
return "";
std::string reply = whole.prompt.substr(head.prompt.size());
std::string reply = whole.prompt.substr(head.size());
while (!reply.empty() && reply.back() == '\n') reply.pop_back();
for (const std::string& t : model_.terminators)
if (reply.size() >= t.size() && reply.compare(reply.size() - t.size(), t.size(), t) == 0) {
@@ -191,16 +201,15 @@ Verdict compare(const Bench& b, const std::string& text) {
o.content.find(f.call_open.substr(a, e - a)) != std::string::npos;
}
v.same = o.content == m.content && o.reasoning == m.reasoning && o.calls.size() == m.calls.size();
/* ARGUMENTS THE OLD READER LEFT AS NO JSON AT ALL are not a reading to agree with: it passed a
* typed value's text through bare (`"verbose":True`, `"extra":}`), which no client can parse,
* and the new reader makes every complete such value JSON (chatparse.cpp, ValueOut). So the
* arguments are compared only where the old object is JSON, and there byte for byte; the new
* reader's own reading of the rest is held by the decided shapes and the streaming checks. */
/* Arguments are compared only where the old object is JSON, and then byte for byte. The old
* reader can pass a typed value's text through bare (`"verbose":True`, `"extra":}`), while the
* new one makes every complete value JSON (chatparse.cpp, ValueOut); the decided shapes and
* streaming checks cover the new reader there. */
auto args_agree = [](const std::string& old_a, const std::string& new_a) {
if (old_a == new_a || !nlohmann::json::accept(old_a)) return true;
/* NOR IS A NEWLINE THE OLD READER TOOK OFF A VALUE'S FRONT that the tag before it had
* already ended with -- Qwen's `<parameter=NAME>\n` -- the newline the template writes
* when the value itself starts with one. Every other byte must agree. */
/* One allowed difference: a leading newline the old reader stripped from a value after
* a tag that already ends with one (Qwen's `<parameter=NAME>\n`), which the template
* writes when the value itself starts with a newline. Every other byte must agree. */
const ojson o = ojson::parse(old_a, nullptr, false);
const ojson n = ojson::parse(new_a, nullptr, false);
if (!o.is_object() || !n.is_object() || o.size() != n.size()) return false;
@@ -309,8 +318,8 @@ std::string check_stream(const ReplyParser& p, const std::string& text,
if (!err.empty()) return err;
if (!same(got, expect)) return "the deltas add up to\n " + show(got);
if (!same(s->message(), expect)) return "the message is\n " + show(s->message());
/* Where each call begins in the reply, which an open call's text is read back from, is a
* fact of the reply, not of how it was cut. */
/* Where each call begins (an open call's text is read back from there) depends on the reply,
* not on how it was cut. */
for (size_t i = 0; i < expect.calls.size(); ++i) {
const ReplyCall& a = s->message().calls[i];
const ReplyCall& b = expect.calls[i];
@@ -320,9 +329,8 @@ std::string check_stream(const ReplyParser& p, const std::string& text,
if (b.at >= text.size() || (i > 0 && b.at <= expect.calls[i - 1].at))
return "call " + std::to_string(i) + " begins at " + std::to_string(b.at) + ", outside the reply";
}
/* A closed call is one a client is handed to run: its arguments are JSON, whatever the
* model wrote into them -- in a reply that is UTF-8, as every reply is once the decoder has
* sanitised it. */
/* A closed call is handed to a client to run, so its arguments are JSON whatever the model
* wrote, for any valid UTF-8 reply (the decoder sanitises every reply). */
if (sanitize(text) == text)
for (const ReplyCall& c : expect.calls)
if (c.closed && !nlohmann::json::accept(c.arguments))
@@ -401,7 +409,6 @@ std::vector<ojson> rendered_corpus() {
return v;
}
std::string qcall(const std::string& name,
const std::vector<std::pair<std::string, std::string>>& args) {
std::string s = "<tool_call>\n<function=" + name + ">\n";
@@ -421,7 +428,6 @@ std::string C(const Model& m, const std::string& name,
return is_qwen(m) ? qcall(name, args) : mcall(name, args);
}
std::vector<Adversarial> adversarial(const Model& m) {
const std::string T = "Thinking it over.\n</think>\n\n";
std::vector<Adversarial> v;
@@ -537,7 +543,6 @@ std::vector<Adversarial> adversarial(const Model& m) {
return v;
}
std::vector<std::string> fragments(const Model& m) {
std::vector<std::string> f = {
"</think>\n\n", "<think>\n", "ls -la", "30", "-1.5e3", "[1,2]", "{\"a\":true}", "{'a': 1}",
@@ -576,7 +581,6 @@ std::string mutate(std::mt19937& rng, std::string s, const std::vector<std::stri
return s;
}
std::string long_reply(const Model& m, size_t target) {
std::string think, file, prose;
while (think.size() < target / 4) think += "Considering the failing assertion in test_add again. ";
@@ -586,8 +590,5 @@ std::string long_reply(const Model& m, size_t target) {
C(m, "write", { { "path", "/work/big.py" }, { "content", file } });
}
} /* namespace chatdiff */
} /* namespace rad */
+26 -25
View File
@@ -2,10 +2,9 @@
*
* Shared by tests/chatparse_test.cpp and tools/rad_chatparse.cpp. A Bench holds one model's chat
* template, its reply format and, for one rendered request, both parsers: the legacy path
* (toolparse_legacy.h, the `old` side) and the streaming parser (core/text/chatparse.h, the `new`
* side). compare() says whether they agree on a reply and, when they do not, which side left its
* grammar; check_stream() feeds a reply to the streaming parser in pieces and checks the streaming
* contract on every piece.
* (toolparse_legacy.h, `old`) and the streaming parser (core/text/chatparse.h, `new`). compare()
* says whether they agree on a reply and, if not, which side left its grammar; check_stream()
* feeds a reply in pieces and checks the streaming contract on every piece.
*/
#pragma once
#include "text/chat.h"
@@ -17,6 +16,7 @@ struct RadChatFormat;
#include <nlohmann/json.hpp>
#include <map>
#include <memory>
#include <random>
#include <string>
@@ -70,12 +70,14 @@ public:
legacy::Answer old_parse(const std::string& text, bool partial = false) const;
ReplyMessage new_parse(const std::string& text, bool* strict = nullptr) const;
/* The reply as the template writes an assistant turn -- which is exactly what the model is
* trained to produce -- without the turn terminator the decoder would not render. "" when the
* template does not render the turn as a continuation of the generation prompt. */
/* The reply as the template writes an assistant turn (what the model is trained to produce),
* without the turn terminator the decoder would not render. "" when the template does not
* render the turn as a continuation of the generation prompt. */
std::string render_reply(const ojson& assistant) const;
private:
std::string render_reply_uncached(const ojson& assistant) const;
Model model_;
std::string jinja_;
std::shared_ptr<ChatTemplate> tmpl_;
@@ -86,6 +88,8 @@ private:
ChatPrompt prompt_;
std::unique_ptr<legacy::ToolParser> old_;
std::shared_ptr<const ReplyParser> parser_;
/* render_reply's results, by the message's JSON. */
mutable std::map<std::string, std::string> replies_;
};
struct Verdict {
@@ -93,15 +97,14 @@ struct Verdict {
bool strict = false; /* the streaming parser read the reply within the grammar */
bool old_clean = false; /* the legacy strict parse matched and nothing was lifted */
bool bare_lift = false; /* the legacy path lifted a call written without the call opener */
/* The legacy answer's content still carries a wrapped format's call syntax -- a call written
* without its wrapper, which the legacy lifter takes only when nothing else in the reply
* parses as a call, and which the streaming parser always reads as one. */
/* The legacy content still carries a wrapped format's call syntax: a call written without
* its wrapper, which the legacy lifter takes only when nothing else parses as a call and the
* streaming parser always reads as one. */
bool old_call_syntax = false;
/* A call in the legacy answer has a raw control character in its arguments: its JSON reader
* took a string holding one, which the schema grammar refuses -- the reply goes on in the
* grammar's text arm, and ends the value at its suffix, where the legacy reader kept reading
* -- or it passed a typed value's text through bare. Neither is JSON, and neither is a
* reading to hold the streaming parser to. */
/* A legacy call has a raw control character in its arguments: either its JSON reader took a
* string holding one (the schema grammar refuses it, continues in its text arm and ends the
* value at its suffix, where the legacy reader kept reading), or it passed a typed value's
* text through bare. Neither is JSON, so the streaming parser is not held to it. */
bool old_raw_control = false;
std::string detail; /* both answers, when they differ */
};
@@ -111,10 +114,9 @@ Verdict compare(const Bench& b, const std::string& text);
* within the grammar, and a documented difference otherwise. "" or the reason it is not. */
std::string judge(const Verdict& v);
/* Feed `text` to a fresh stream cut at `cuts` (ascending offsets), checking on every piece that
* what has been emitted is a prefix of `expect` and that the held bytes stay under the bound, and
* at the end that the concatenated deltas and the message both equal `expect`. "" or the first
* violation. */
/* Feed `text` to a fresh stream cut at `cuts` (ascending offsets). On every piece, the emitted
* text must be a prefix of `expect` and the held bytes within the bound; at the end, the
* concatenated deltas and the message must equal `expect`. Returns "" or the first violation. */
std::string check_stream(const ReplyParser& p, const std::string& text,
const std::vector<size_t>& cuts, const ReplyMessage& expect);
@@ -126,7 +128,6 @@ bool same(const ReplyMessage& a, const ReplyMessage& b);
* before any reply reaches a parser. */
std::string sanitize(const std::string& s);
/* ================================================================== the corpora */
bool is_qwen(const Model& m);
@@ -136,13 +137,13 @@ ojson call(const std::string& name, const ojson& args);
ojson message(const std::string& reasoning, const std::string& content,
const std::vector<ojson>& calls);
/* Assistant messages that, rendered through a model's template, are the replies the model is
* trained to write: content only, reasoning, one to five calls, every argument type, unicode, and
* values holding the format's own punctuation. */
/* Assistant messages that, rendered through a model's template, are replies the model is trained
* to write: content only, reasoning, one to five calls, every argument type, unicode, and values
* holding the format's own punctuation. */
std::vector<ojson> rendered_corpus();
/* Replies written by hand in a model's own spelling: the shapes models actually write when they
* leave their format, and the ones a streaming parser is easiest to get wrong. */
/* Hand-written replies in a model's own spelling: shapes models write when they leave their
* format, and those a streaming parser most easily gets wrong. */
struct Adversarial { std::string name, text; };
std::vector<Adversarial> adversarial(const Model& m);
+37 -35
View File
@@ -288,8 +288,7 @@ size_t utf8_cut(const std::string& s) {
const unsigned char c = (unsigned char)s[k - 1];
if ((c & 0xC0) == 0x80) { --k; ++back; continue; }
size_t need = 1;
if ((c & 0x80) == 0x00) need = 1;
else if ((c & 0xE0) == 0xC0) need = 2;
if ((c & 0xE0) == 0xC0) need = 2;
else if ((c & 0xF0) == 0xE0) need = 3;
else if ((c & 0xF8) == 0xF0) need = 4;
else return n;
@@ -317,28 +316,43 @@ std::string chunk(const nlohmann::ordered_json& delta) {
"\n\n";
}
/* The new text `cand` adds to `sent`, cut at a UTF-8 boundary unless final, and `sent` advanced
* to it; empty when `cand` does not extend `sent` or nothing new is whole yet. */
std::string grow(std::string& sent, const std::string& cand, bool is_final) {
if (!extends(sent, cand)) return std::string();
const size_t safe = is_final ? cand.size() : utf8_cut(cand);
if (safe <= sent.size()) return std::string();
std::string d = cand.substr(sent.size(), safe - sent.size());
sent = cand.substr(0, safe);
return d;
}
/* A delta carrying call `i`'s function fields. */
std::string call_chunk(size_t i, const nlohmann::ordered_json& function) {
nlohmann::ordered_json e;
e["index"] = (int64_t)i;
e["function"] = function;
nlohmann::ordered_json d;
d["tool_calls"] = nlohmann::ordered_json::array({ e });
return chunk(d);
}
} /* namespace */
size_t LegacyDeltaStream::push(const std::string& full_text, bool is_final) {
Answer p = legacy_parse(tp_, full_text, !is_final, want_calls_, terms_);
size_t out = 0;
if (p.reasoning.size() > reasoning_.size() && extends(reasoning_, p.reasoning)) {
const size_t safe = is_final ? p.reasoning.size() : utf8_cut(p.reasoning);
if (safe > reasoning_.size()) {
nlohmann::ordered_json d;
d["reasoning_content"] = p.reasoning.substr(reasoning_.size(), safe - reasoning_.size());
out += chunk(d).size();
reasoning_ = p.reasoning.substr(0, safe);
}
const std::string r = grow(reasoning_, p.reasoning, is_final);
if (!r.empty()) {
nlohmann::ordered_json d;
d["reasoning_content"] = r;
out += chunk(d).size();
}
if (p.content.size() > content_.size() && extends(content_, p.content)) {
const size_t safe = is_final ? p.content.size() : utf8_cut(p.content);
if (safe > content_.size()) {
nlohmann::ordered_json d;
d["content"] = p.content.substr(content_.size(), safe - content_.size());
out += chunk(d).size();
content_ = p.content.substr(0, safe);
}
const std::string c = grow(content_, p.content, is_final);
if (!c.empty()) {
nlohmann::ordered_json d;
d["content"] = c;
out += chunk(d).size();
}
for (size_t i = 0; i < p.calls.size(); ++i) {
const ToolCall& tc = p.calls[i];
@@ -350,25 +364,13 @@ size_t LegacyDeltaStream::push(const std::string& full_text, bool is_final) {
nlohmann::ordered_json f;
f["name"] = tc.name;
f["arguments"] = "";
nlohmann::ordered_json e;
e["index"] = (int64_t)i;
e["function"] = f;
nlohmann::ordered_json d;
d["tool_calls"] = nlohmann::ordered_json::array({ e });
out += chunk(d).size();
out += call_chunk(i, f).size();
}
if (!extends(args_[i], tc.arguments)) continue;
const size_t safe = is_final ? tc.arguments.size() : utf8_cut(tc.arguments);
if (safe <= args_[i].size()) continue;
const std::string a = grow(args_[i], tc.arguments, is_final);
if (a.empty()) continue;
nlohmann::ordered_json f;
f["arguments"] = tc.arguments.substr(args_[i].size(), safe - args_[i].size());
nlohmann::ordered_json e;
e["index"] = (int64_t)i;
e["function"] = f;
nlohmann::ordered_json d;
d["tool_calls"] = nlohmann::ordered_json::array({ e });
out += chunk(d).size();
args_[i] = tc.arguments.substr(0, safe);
f["arguments"] = a;
out += call_chunk(i, f).size();
}
return out;
}
+14 -17
View File
@@ -1,17 +1,14 @@
/* toolparse_legacy.h -- a whole-reply parser built on llama.cpp's PEG auto-parser, kept as the
* ORACLE the differential tests compare the streaming parser (core/text/chatparse.h) against. It
* is test code: it is built into the test binaries and the acceptance tool, never into the engine.
/* toolparse_legacy.h -- a whole-reply parser built on llama.cpp's PEG auto-parser, the oracle the
* differential tests compare the streaming parser (core/text/chatparse.h) against. Built into the
* test binaries and the acceptance tool, never into the engine.
*
* It is the whole legacy path, layer for layer, because its answer is what all of them produce
* together:
* It keeps every layer of the legacy path, since the answer is what they produce together:
*
* * ToolParser -- llama.cpp's PEG parser, generated per request by the vendored auto-parser from
* the chat template (vendor/llama/common/chat-auto-parser*.cpp) and run over the WHOLE reply;
* * legacy_parse -- the bridge's reading of that: a turn terminator trimmed off the content,
* and, when the strict parse produced no call but the content still carries call syntax,
* calls lifted out of the text by hand;
* * LegacyDeltaStream -- a streaming diff that re-parses the accumulated reply on every chunk and
* sends what has grown.
* * ToolParser -- llama.cpp's PEG parser, generated per request from the chat template by the
* vendored auto-parser (vendor/llama/common/chat-auto-parser*.cpp), run over the whole reply;
* * legacy_parse -- the bridge: trims a turn terminator off the content and, when the strict
* parse produced no call but the content still carries call syntax, lifts calls by hand;
* * LegacyDeltaStream -- re-parses the accumulated reply on every chunk and sends what grew.
*/
#pragma once
#include "rad_internal.h"
@@ -38,9 +35,9 @@ struct ParsedReply {
std::vector<ToolCall> tool_calls;
};
/* The by-hand lifter: `<function name="N"><param name="K">V</param></function>` and
* `<tool_call><function=N><parameter=K>V</parameter></function></tool_call>` spans read out of
* `text` whatever the model's format, appended to `out` and removed. */
/* The by-hand lifter: reads `<function name="N"><param name="K">V</param></function>` and
* `<tool_call><function=N><parameter=K>V</parameter></function></tool_call>` spans out of `text`
* regardless of the model's format, appends them to `out` and removes them. */
size_t toolparse_lift_xml_calls(std::string& text, std::vector<ToolCall>& out);
/* The earliest byte of `text` that could begin a call in either spelling, or npos. */
@@ -74,8 +71,8 @@ struct Answer {
Answer legacy_parse(const ToolParser& tp, const std::string& text, bool is_partial,
bool want_calls, const std::vector<std::string>& terminators);
/* The legacy streaming diff over the accumulated text: returns how many bytes of deltas it sends,
* and fills the concatenation of what it sent. */
/* The legacy streaming diff over the accumulated text. push() returns the bytes of deltas sent;
* the accessors hold the concatenation of what was sent. */
class LegacyDeltaStream {
public:
LegacyDeltaStream(const ToolParser& tp, bool want_calls, std::vector<std::string> terminators)