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 -28
View File
@@ -1,14 +1,13 @@
# vendor/ -- llama.cpp lifts and third-party headers, tracked to an upstream commit and patched
# rather than edited (spec §12). See UPSTREAM for what came from where and patches/ for every
# local change. Nothing here is written by us; anything that had to be rewritten lives in core/.
# rather than edited (spec §12). UPSTREAM lists the sources and patches/ every local change;
# anything rewritten lives in core/.
#
# The public target is `rad_vendor`, an INTERFACE library. core/CMakeLists.txt links it if it
# exists, so this file is the only place that decides what the rest of the tree can include.
# The public target is the INTERFACE library `rad_vendor`, which core/CMakeLists.txt links. This
# file alone decides what the rest of the tree can include from here.
# ---------------------------------------------------------------- compiled lifts
# Vendored sources are compiled with warnings off. Not because the warnings are wrong, but
# because a warning we will never fix is noise in front of the warnings we will, and editing
# upstream to silence one is exactly what the patch-series rule exists to prevent.
# Vendored sources compile with warnings off: they will never be fixed here, and editing upstream to
# silence them would break the patch-series rule.
add_library(rad_vendor_llama STATIC
llama/src/unicode.cpp
llama/src/unicode-data.cpp
@@ -30,42 +29,41 @@ add_library(rad_vendor_llama STATIC
llama/common/regex-partial.cpp
shim/llama_shim.cpp)
target_compile_options(rad_vendor_llama PRIVATE -w)
# SYSTEM, so a warning in a vendored header is not a warning in OUR build. `-w` above covers the
# vendor's own translation units; these headers are included by ours too, and two -Wunused-function
# from jinja were the only things left in an otherwise clean build. A warning nobody intends to act
# on is a warning that stops the rest from being read.
# SYSTEM, so vendored headers included by our sources do not warn either (`-w` covers only the
# vendor's own translation units).
target_include_directories(rad_vendor_llama SYSTEM PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
# shim/ first: the lifted files say #include "common.h" / "log.h" / "ggml.h" / "llama.h" and
# every one of those is ours (see vendor/shim/*.h). Putting them on the path rather than
# editing the include line is what keeps the lifts byte-identical to upstream.
# shim/ first: the lifted files include "common.h", "log.h", "ggml.h" and "llama.h", which are
# ours (vendor/shim/*.h). The path, not an edit, redirects them, so lifts stay byte-identical.
${CMAKE_CURRENT_SOURCE_DIR}/shim
# And llama/common, because the lifted files include each other and the jinja engine by their
# own basenames. The cost of this one, named: `#include "unicode.h"` anywhere in core/ now
# resolves to llama/common/unicode.h (the streaming UTF-8 helper) and NOT to
# llama/src/unicode.h (the codepoint tables). core/ spells both in full from vendor/ for
# exactly that reason, and the tokeniser's include is "llama/src/unicode.h".
# llama/common, because the lifted files include each other and the jinja engine by basename.
# Side effect: a bare "unicode.h" resolves to llama/common/unicode.h (streaming UTF-8), not
# llama/src/unicode.h (codepoint tables), so core/ always spells the vendor path in full.
${CMAKE_CURRENT_SOURCE_DIR}/llama/common)
# cpp-httplib 0.46.1 is a split header/source library, not header-only, so it is compiled.
# TLS is deliberately off: the server serves plain HTTP and terminating TLS is the job of
# whatever sits in front of it. Turning it on is a target_compile_definitions line here plus a
# link against OpenSSL, and is the server component's call, not this file's.
# cpp-httplib 0.46.1 is a split header/source library, so it is compiled. TLS is off: the server
# speaks plain HTTP and TLS termination belongs to a proxy in front of it.
add_library(rad_vendor_httplib STATIC cpp-httplib/httplib.cpp)
target_compile_options(rad_vendor_httplib PRIVATE -w)
target_include_directories(rad_vendor_httplib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cpp-httplib)
target_link_libraries(rad_vendor_httplib PRIVATE Threads::Threads)
target_compile_definitions(rad_vendor_httplib PUBLIC
# llama.cpp's operational settings, carried because the reasons are ours too: a long prompt in
# a form body, many concurrent connections, a long prompt in a query string, and no Nagle delay
# on a streamed token.
# llama.cpp's settings: long prompts in a form body or query string, many concurrent
# connections, and no Nagle delay on streamed tokens.
CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH=1048576
CPPHTTPLIB_LISTEN_BACKLOG=512
CPPHTTPLIB_REQUEST_URI_MAX_LENGTH=32768
CPPHTTPLIB_TCP_NODELAY=1)
CPPHTTPLIB_TCP_NODELAY=1
# A WebSocket read waits this long for a frame. The server pings every 30 s, so a live peer --
# one that answers the ping -- is never cut off; one that stops answering holds its socket,
# and a server shutdown waiting on it, for a minute rather than httplib's five.
CPPHTTPLIB_WEBSOCKET_READ_TIMEOUT_SECOND=60
# The largest WebSocket message, its fragments together. A realtime client sends audio a few
# hundred milliseconds a message; a larger message closes the connection.
CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH=2097152)
# ---------------------------------------------------------------- the public face
# Header-only vendors need no compilation, only a path:
# Header-only vendors need only a path:
# <nlohmann/json.hpp> vendor/nlohmann/json.hpp
# <cpp-httplib/httplib.h> vendor/cpp-httplib/httplib.h (or plain "httplib.h")
# "llama/src/unicode.h" the tokeniser's codepoint tables
+31 -4
View File
@@ -63,7 +63,7 @@ vendor/llama/common/jinja/ <- llama.cpp common/jinja/
on nlohmann/json and common/unicode.h and on nothing else in llama.cpp -- no ggml, no
llama.h, no common.h -- which is why it lifts cleanly and chat.cpp did not.
LOCAL CHANGES: none.
LOCAL CHANGES: patches/0015-jinja-print-a-list-or-a-dict-as-its-repr.patch
vendor/llama/common/chat.{h,cpp}
vendor/llama/common/chat-auto-parser.h
@@ -100,6 +100,7 @@ vendor/llama/common/regex-partial.{h,cpp} <- llama.cpp common/*
patches/0012-json-schema-a-schema-no-value-satisfies.patch
patches/0013-json-schema-a-count-past-int-is-no-bound.patch
patches/0014-json-schema-a-not-of-every-type-is-never.patch
patches/0016-chat-analyse-a-template-once.patch
On 0003: a `pattern` in a `response_format` reaches _visit_pattern() as client data, and three
of its paths do not survive that. `front()`/`back()` run on an empty string; `seq.back()` runs
@@ -156,9 +157,8 @@ vendor/cpp-httplib/LICENSE <- llama.cpp vendor/cpp-httplib/cpp
REWRITTEN INTO core/ INSTEAD
----------------------------
spec §12 lists these as lifts. Each one turned out to be a file we would have had to modify
heavily, and a file you modify heavily is a file that belongs in core/ under our own name -- so
it is there, with a comment at the top naming what it was read from.
spec §12 marks these as rewritten. Each one would have needed heavy modification, so it lives in
core/ under our own name, with a comment at the top naming what it was read from.
src/llama-grammar.{h,cpp} -> core/sample/gbnf.{h,cpp}
MIT, same upstream commit. The GBNF parser and the stack machine, element for element; it
@@ -460,3 +460,30 @@ PATCH SERIES
not stand for `number`, so a `not` is only read as `never` when it is. Every other `not` is
refused as 0004 refuses it. The comment of 0012 above is_unsatisfiable, which 0013 had left
above _schema_count, is back beside the function it describes.
patches/0015-jinja-print-a-list-or-a-dict-as-its-repr.patch
`{{ value }}` with a list or a dict printed the list's strings run together and nothing at
all for a dict: statement results are gathered as an array and flattened, and an
expression's own list was flattened with them. jinja2 prints the repr. MiniCPM5's template
prints a tool call's arguments with a bare `{{ param_value }}`, so every list or object
argument in a replayed call reached the model as `<param name="edits"></param>`. Every block
statement returns a string, so a list or a dict among a block's results is now printed as
its repr. The repr of a string inside one is Python's: single quotes unless the text holds
one and no double quote, and backslash escapes for the backslash, the quote and the ASCII
controls; it was the bare text in single quotes, or JSON when it held a quote. Python also
escapes non-printable non-ASCII code points, which pass through. tests/chat_test.cpp
(every_shipped_template_renders_as_reference_jinja_does) compares every shipped template's
render with Python jinja2's.
patches/0016-chat-analyse-a-template-once.patch
common_chat_templates_apply ran autoparser::analyze_template on every request: many
renders of the template to find its reply delimiters, most of what a Qwen 3.x or MiniCPM5
render cost. The analysis reads nothing but the template, so it is now made on
first use and kept beside the template (one for template_default, one for
template_tool_use), under a mutex because requests render from several threads. An analysis
that throws is not kept, so the next request throws the same refusal. The parser generated
from it per request is unchanged: the prompt, grammar, triggers, preserved tokens, stops and
PEG parser of 32 requests through each shipped template hash the same with and without the
cache, and a render took 1.4-1.6 ms with it against 10-13 ms without (one loaded machine).
+29 -2
View File
@@ -20,6 +20,8 @@
#include <ctime>
#include <exception>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <sstream>
@@ -285,8 +287,33 @@ struct common_chat_templates {
bool has_explicit_template; // Model had builtin template or template overridden was specified.
std::unique_ptr<common_chat_template> template_default; // always set (defaults to chatml)
std::unique_ptr<common_chat_template> template_tool_use;
/* RADIANCE: the differential analysis of template_default ([0]) and template_tool_use ([1]),
* made on first use (template_analysis). */
mutable std::mutex analysis_lock;
mutable std::shared_ptr<const autoparser::autoparser> analysis[2];
};
/* RADIANCE: autoparser::analyze_template renders the template over synthetic messages and reads
* nothing but the template, so one analysis serves every request rendered through it. One that
* throws is not kept, and the next request analyses again and throws again. */
static std::shared_ptr<const autoparser::autoparser> template_analysis(
const common_chat_templates * tmpls, const common_chat_template & tmpl) {
const size_t slot = &tmpl == tmpls->template_default.get() ? 0 : 1;
{
std::lock_guard<std::mutex> lock(tmpls->analysis_lock);
if (tmpls->analysis[slot]) {
return tmpls->analysis[slot];
}
}
auto made = std::make_shared<autoparser::autoparser>();
made->analyze_template(tmpl);
std::lock_guard<std::mutex> lock(tmpls->analysis_lock);
if (!tmpls->analysis[slot]) {
tmpls->analysis[slot] = std::move(made);
}
return tmpls->analysis[slot];
}
common_chat_tool_choice common_chat_tool_choice_parse_oaicompat(const std::string & tool_choice) {
if (tool_choice == "auto") {
return COMMON_CHAT_TOOL_CHOICE_AUTO;
@@ -2465,8 +2492,8 @@ static common_chat_params common_chat_templates_apply_jinja(const struct common_
try {
LOG_DBG("%s: using differential autoparser\n", __func__);
struct autoparser::autoparser autoparser;
autoparser.analyze_template(tmpl);
const std::shared_ptr<const autoparser::autoparser> analysis = template_analysis(tmpls, tmpl);
const autoparser::autoparser & autoparser = *analysis;
auto auto_params = autoparser::peg_generator::generate_parser(tmpl, params, autoparser);
std::vector<common_chat_msg_delimiter> delimiters;
+9 -1
View File
@@ -606,7 +606,15 @@ static void gather_string_parts_recursive(const value & val, value_string & part
} else if (is_val<value_array>(val)) {
auto items = cast_val<value_array>(val)->as_array();
for (const auto & item : items) {
gather_string_parts_recursive(item, parts);
/* RADIANCE: `val` is a block's statement results, and every block statement returns
* a string, so a list or a dict among them is the value of an expression the template
* prints. jinja2 prints its repr; flattening it ran its strings together and printed
* nothing for a dict. */
if (is_val<value_array>(item) || is_val<value_object>(item)) {
parts->val_str.append(item->as_string().str());
} else {
gather_string_parts_recursive(item, parts);
}
}
}
}
+28 -6
View File
@@ -1496,13 +1496,35 @@ std::string value_to_json(const value & val, int indent, const std::string_view
// TODO: avoid circular references
std::string value_to_string_repr(const value & val) {
if (is_val<value_string>(val)) {
const std::string val_str = val->as_string().str();
if (val_str.find('\'') != std::string::npos) {
return value_to_json(val);
} else {
return "'" + val_str + "'";
/* RADIANCE: Python's str repr, which jinja2 prints for a string inside a list or a dict:
* single quotes unless the text holds one and no double quote, and backslash escapes for
* the backslash, the quote, \t \n \r and the other ASCII controls. Python also escapes
* non-printable non-ASCII code points; those pass through here. */
const std::string s = val->as_string().str();
const char q = s.find('\'') != std::string::npos && s.find('"') == std::string::npos ? '"' : '\'';
std::string out(1, q);
for (const char ch : s) {
const unsigned char c = (unsigned char) ch;
if (ch == q || ch == '\\') {
out += '\\';
out += ch;
} else if (ch == '\t') {
out += "\\t";
} else if (ch == '\n') {
out += "\\n";
} else if (ch == '\r') {
out += "\\r";
} else if (c < 0x20 || c == 0x7f) {
static const char hex[] = "0123456789abcdef";
out += "\\x";
out += hex[c >> 4];
out += hex[c & 15];
} else {
out += ch;
}
}
out += q;
return out;
} else {
return val->as_repr();
}
@@ -0,0 +1,67 @@
diff --git a/common/jinja/runtime.h b/common/jinja/runtime.h
index b6f4a6ab..af84c910 100644
--- a/common/jinja/runtime.h
+++ b/common/jinja/runtime.h
@@ -606,7 +606,15 @@ static void gather_string_parts_recursive(const value & val, value_string & part
} else if (is_val<value_array>(val)) {
auto items = cast_val<value_array>(val)->as_array();
for (const auto & item : items) {
- gather_string_parts_recursive(item, parts);
+ /* RADIANCE: `val` is a block's statement results, and every block statement returns
+ * a string, so a list or a dict among them is the value of an expression the template
+ * prints. jinja2 prints its repr; flattening it ran its strings together and printed
+ * nothing for a dict. */
+ if (is_val<value_array>(item) || is_val<value_object>(item)) {
+ parts->val_str.append(item->as_string().str());
+ } else {
+ gather_string_parts_recursive(item, parts);
+ }
}
}
}
diff --git a/common/jinja/value.cpp b/common/jinja/value.cpp
index 16b8bbf1..b7af1ae1 100644
--- a/common/jinja/value.cpp
+++ b/common/jinja/value.cpp
@@ -1496,13 +1496,35 @@ std::string value_to_json(const value & val, int indent, const std::string_view
// TODO: avoid circular references
std::string value_to_string_repr(const value & val) {
if (is_val<value_string>(val)) {
- const std::string val_str = val->as_string().str();
-
- if (val_str.find('\'') != std::string::npos) {
- return value_to_json(val);
- } else {
- return "'" + val_str + "'";
+ /* RADIANCE: Python's str repr, which jinja2 prints for a string inside a list or a dict:
+ * single quotes unless the text holds one and no double quote, and backslash escapes for
+ * the backslash, the quote, \t \n \r and the other ASCII controls. Python also escapes
+ * non-printable non-ASCII code points; those pass through here. */
+ const std::string s = val->as_string().str();
+ const char q = s.find('\'') != std::string::npos && s.find('"') == std::string::npos ? '"' : '\'';
+ std::string out(1, q);
+ for (const char ch : s) {
+ const unsigned char c = (unsigned char) ch;
+ if (ch == q || ch == '\\') {
+ out += '\\';
+ out += ch;
+ } else if (ch == '\t') {
+ out += "\\t";
+ } else if (ch == '\n') {
+ out += "\\n";
+ } else if (ch == '\r') {
+ out += "\\r";
+ } else if (c < 0x20 || c == 0x7f) {
+ static const char hex[] = "0123456789abcdef";
+ out += "\\x";
+ out += hex[c >> 4];
+ out += hex[c & 15];
+ } else {
+ out += ch;
+ }
}
+ out += q;
+ return out;
} else {
return val->as_repr();
}
+58
View File
@@ -0,0 +1,58 @@
diff --git a/common/chat.cpp b/common/chat.cpp
index 5bc91ebd..90172e9e 100644
--- a/common/chat.cpp
+++ b/common/chat.cpp
@@ -20,6 +20,8 @@
#include <ctime>
#include <exception>
#include <functional>
+#include <memory>
+#include <mutex>
#include <optional>
#include <sstream>
@@ -285,8 +287,33 @@ struct common_chat_templates {
bool has_explicit_template; // Model had builtin template or template overridden was specified.
std::unique_ptr<common_chat_template> template_default; // always set (defaults to chatml)
std::unique_ptr<common_chat_template> template_tool_use;
+ /* RADIANCE: the differential analysis of template_default ([0]) and template_tool_use ([1]),
+ * made on first use (template_analysis). */
+ mutable std::mutex analysis_lock;
+ mutable std::shared_ptr<const autoparser::autoparser> analysis[2];
};
+/* RADIANCE: autoparser::analyze_template renders the template over synthetic messages and reads
+ * nothing but the template, so one analysis serves every request rendered through it. One that
+ * throws is not kept, and the next request analyses again and throws again. */
+static std::shared_ptr<const autoparser::autoparser> template_analysis(
+ const common_chat_templates * tmpls, const common_chat_template & tmpl) {
+ const size_t slot = &tmpl == tmpls->template_default.get() ? 0 : 1;
+ {
+ std::lock_guard<std::mutex> lock(tmpls->analysis_lock);
+ if (tmpls->analysis[slot]) {
+ return tmpls->analysis[slot];
+ }
+ }
+ auto made = std::make_shared<autoparser::autoparser>();
+ made->analyze_template(tmpl);
+ std::lock_guard<std::mutex> lock(tmpls->analysis_lock);
+ if (!tmpls->analysis[slot]) {
+ tmpls->analysis[slot] = std::move(made);
+ }
+ return tmpls->analysis[slot];
+}
+
common_chat_tool_choice common_chat_tool_choice_parse_oaicompat(const std::string & tool_choice) {
if (tool_choice == "auto") {
return COMMON_CHAT_TOOL_CHOICE_AUTO;
@@ -2465,8 +2492,8 @@ static common_chat_params common_chat_templates_apply_jinja(const struct common_
try {
LOG_DBG("%s: using differential autoparser\n", __func__);
- struct autoparser::autoparser autoparser;
- autoparser.analyze_template(tmpl);
+ const std::shared_ptr<const autoparser::autoparser> analysis = template_analysis(tmpls, tmpl);
+ const autoparser::autoparser & autoparser = *analysis;
auto auto_params = autoparser::peg_generator::generate_parser(tmpl, params, autoparser);
std::vector<common_chat_msg_delimiter> delimiters;