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

+31
View File
@@ -0,0 +1,31 @@
/* kernel_list.h -- how a kernel hierarchy is spelt in --kernels and $RADIANCE_KERNELS.
*
* The engine (core/config.cpp) and the tools (tools/iface.cpp) both read it here, so a list a
* plugin was validated with in rad-kbench loads the same libraries when the engine serves. Entries
* are separated by ',' or ':'; empty entries (a doubled or trailing separator) are dropped, since an
* entry of "" matches no library and would warn on every start.
*/
#pragma once
#include <string>
#include <string_view>
#include <vector>
namespace rad {
inline std::vector<std::string> rad_split_kernel_list(std::string_view s) {
std::vector<std::string> out;
std::string cur;
for (char c : s) {
if (c == ',' || c == ':') {
if (!cur.empty()) out.push_back(cur);
cur.clear();
} else {
cur.push_back(c);
}
}
if (!cur.empty()) out.push_back(cur);
return out;
}
} /* namespace rad */
+35 -64
View File
@@ -1,6 +1,4 @@
/* rad_util.cpp -- logging, error strings, dtype arithmetic and tensor helpers. The bedrock every
* other translation unit links against.
*/
/* rad_util.cpp -- logging, string formatting, Geometry and constraint matching. */
#include <atomic>
#include <chrono>
#include "../rad_internal.h"
@@ -10,20 +8,16 @@
#include <cstdlib>
#include <cinttypes>
#include <ctime>
#include <iterator>
#include <unistd.h>
namespace rad {
/* ------------------------------------------------------------------ logging */
/* THE LEVEL COMES FROM THE ENVIRONMENT, because nothing in the tree calls `log_set_level`. Without
* that, the level is Info for the life of every process and every RAD_DEBUG and RAD_TRACE site in
* the engine is unreachable code that reads like a diagnostic somebody could turn on -- the
* sampler's mask timing, the grammar's admissible-token count, the drafter's per-position trace,
* the step loop's batch dump. RADIANCE_LOG=error|warn|info|debug|trace reaches them.
*
* Read once, on first use, because this is called from the step path on every logged line. The
* setter stays: a host embedding the engine as a library has no environment to speak through. */
/* The initial level comes from RADIANCE_LOG=error|warn|info|debug|trace (default info), so
* RAD_DEBUG / RAD_TRACE sites are reachable in any process. Read once at startup; log_set_level
* overrides it (command-line -v, tests, embedding hosts). */
static Log level_from_env() {
const char* v = std::getenv("RADIANCE_LOG");
if (!v || !*v) return Log::Info;
@@ -32,8 +26,7 @@ static Log level_from_env() {
if (!std::strcmp(v, "info")) return Log::Info;
if (!std::strcmp(v, "debug")) return Log::Debug;
if (!std::strcmp(v, "trace")) return Log::Trace;
/* Not a level. Said at the level that is always on, rather than silently ignored -- a
* misspelt knob that changes nothing looks exactly like a knob that does not work. */
/* Report a misspelt level instead of silently ignoring it. */
std::fprintf(stderr, "E RADIANCE_LOG='%s' is not error|warn|info|debug|trace; using info\n", v);
return Log::Info;
}
@@ -52,8 +45,7 @@ static const char* level_tag(Log l) {
}
}
/* Colour only when stderr is a terminal. Piped or redirected it prints ordinary lines, which is
* the same rule the live view follows (spec §16). */
/* Colour only when stderr is a terminal, as the live view does (spec §16). */
static const char* level_colour(Log l) {
if (!isatty(2)) return "";
switch (l) {
@@ -65,8 +57,7 @@ static const char* level_colour(Log l) {
}
}
/* Thread-local because the ranks' declare threads run concurrently; a plain global would have
* whichever rank last entered a scope tagging every other rank's lines. */
/* Thread-local: the ranks' declare threads run concurrently and each tags its own lines. */
static thread_local int g_log_rank = -1;
static bool g_rank_tags = false;
@@ -93,8 +84,7 @@ void log_emit(Log l, const char* file, int line, const char* fmt, ...) {
char rank[16] = "";
if (g_rank_tags && g_log_rank >= 0) snprintf(rank, sizeof rank, "[%d]", g_log_rank);
/* Debug and Trace carry the source site; Info and above do not, because an operator reading
* a normal startup does not care which file said it. */
/* Debug and Trace carry the source site; Info and above do not. */
if ((int)l >= (int)Log::Debug)
fprintf(stderr, "%s%s%s%s %s:%d %s\n", col, level_tag(l), rank, rst, base, line, msg);
else
@@ -157,38 +147,26 @@ std::vector<std::string_view> split_ws(std::string_view s) {
}
/* ------------------------------------------------------------------ Geometry */
/* Small, linear-scanned, and that is correct: an op has a handful of parameters and the selector
* touches this at declare, not per step. A hash map here would be slower and less predictable. */
void Geometry::set_i(std::string_view k, long long v) {
for (size_t i = 0; i < keys_.size(); ++i)
if (keys_[i] == k) { kinds_[i] = RAD_P_INT; ivals_[i] = v; rebuild(); return; }
keys_.emplace_back(k);
svals_.emplace_back();
ivals_.push_back(v);
dvals_.push_back(0.0);
kinds_.push_back(RAD_P_INT);
rebuild();
}
void Geometry::set_f(std::string_view k, double v) {
for (size_t i = 0; i < keys_.size(); ++i)
if (keys_[i] == k) { kinds_[i] = RAD_P_F64; dvals_[i] = v; rebuild(); return; }
keys_.emplace_back(k);
svals_.emplace_back();
ivals_.push_back(0);
dvals_.push_back(v);
kinds_.push_back(RAD_P_F64);
rebuild();
/* Linear scan on purpose: an op has a handful of parameters and the selector reads this at
* declare, not per step. */
size_t Geometry::slot(std::string_view k, int kind) {
size_t i = 0;
while (i < keys_.size() && keys_[i] != k) ++i;
if (i == keys_.size()) {
keys_.emplace_back(k);
svals_.emplace_back();
ivals_.push_back(0);
dvals_.push_back(0.0);
kinds_.push_back(kind);
}
kinds_[i] = kind;
return i;
}
void Geometry::set_i(std::string_view k, long long v) { ivals_[slot(k, RAD_P_INT)] = v; rebuild(); }
void Geometry::set_f(std::string_view k, double v) { dvals_[slot(k, RAD_P_F64)] = v; rebuild(); }
void Geometry::set_s(std::string_view k, std::string_view v) {
for (size_t i = 0; i < keys_.size(); ++i)
if (keys_[i] == k) { kinds_[i] = RAD_P_STR; svals_[i] = std::string(v); rebuild(); return; }
keys_.emplace_back(k);
svals_.emplace_back(v);
ivals_.push_back(0);
dvals_.push_back(0.0);
kinds_.push_back(RAD_P_STR);
svals_[slot(k, RAD_P_STR)] = std::string(v);
rebuild();
}
@@ -215,9 +193,8 @@ bool Geometry::has(std::string_view k) const {
return false;
}
/* Every key and every string value may have moved: an append can reallocate keys_ and svals_, and
* a short string lives inside its element. So the whole view is redone, which is the same handful
* of entries the setter's scan already walked. */
/* Rebuild the whole view: an append can reallocate keys_ and svals_, and short strings live
* inside their element, so every c_str() may have moved. */
void Geometry::rebuild() {
view_.clear();
view_.reserve(keys_.size());
@@ -246,10 +223,8 @@ std::string Geometry::str() const {
}
/* ------------------------------------------------------------------ constraint matching */
/* A constraint whose key the geometry does not carry does NOT hold. That is libr4d's rule: a row
* that constrains an optional parameter serves only a caller that states it, so the more
* constrained of two rows is reached only when it is asked for, and a caller that leaves the
* parameter out is handed the row that does not need it. */
/* A constraint on a key the geometry lacks does not hold (libr4d's rule): a row constraining an
* optional parameter serves only callers that state it, and others get a row without it. */
bool constraint_holds(const RadConstraint& c, const Geometry& g) {
if (c.op == RAD_C_IN) {
const char* v = g.get_s(c.key);
@@ -279,7 +254,7 @@ bool constraint_holds(const RadConstraint& c, const Geometry& g) {
std::string constraint_why(const RadConstraint& c, const Geometry& g) {
static const char* opname[] = { "==", "<=", ">=", "%", "in" };
const char* on = (c.op >= 0 && c.op <= 4) ? opname[c.op] : "?";
const char* on = (c.op >= 0 && c.op < (int)std::size(opname)) ? opname[c.op] : "?";
if (c.op == RAD_C_IN) {
const char* v = g.get_s(c.key);
@@ -299,11 +274,7 @@ std::string constraint_why(const RadConstraint& c, const Geometry& g) {
/* ------------------------------------------------------------------ the C surface
*
* EMPTY, AND THAT IS THE POINT. rad_strerror, the four dtype helpers, the three tensor helpers
* and rad_args_geti/gets are `static inline` in the ABI headers. Defined here instead -- declared
* in abi/, defined in rad_core -- they would be callable by everything EXCEPT the plugins that
* want them most; see the long note above rad_strerror in rad_types.h for the failure that
* motivates the arrangement and for what it costs.
*
* Nothing belongs here. A helper a plugin may need belongs in the header; a helper only the
* core needs belongs in namespace rad above, not behind extern "C". */
* Intentionally empty. rad_strerror, the dtype and tensor helpers and rad_args_geti/gets are
* `static inline` in the ABI headers; defined in rad_core they would be unreachable from plugins
* (see the note above rad_strerror in rad_types.h). A helper plugins need goes in the header; a
* core-only helper goes in namespace rad, not behind extern "C". */
+14 -17
View File
@@ -3,6 +3,7 @@
#include "rad_internal.h"
#include <algorithm>
#include <atomic>
#include <chrono>
#include <condition_variable>
@@ -31,8 +32,8 @@ std::string read_first_line(const std::string& path) {
return s;
}
/* The ioctl numbers of the KFD (type 'K'), as <linux/kfd_ioctl.h> assigns them. By number rather
* than by macro, because the header a build sees can be older than the driver it runs on. */
/* KFD ioctl numbers (type 'K') from <linux/kfd_ioctl.h>, listed by number because the build's
* header can be older than the running driver. */
const char* kfd_ioctl_name(unsigned nr) {
static const char* const k[] = {
nullptr, "GET_VERSION", "CREATE_QUEUE", "DESTROY_QUEUE", "SET_MEMORY_POLICY",
@@ -70,14 +71,7 @@ const char* syscall_name(long nr) {
#endif
}
bool is_ioctl(long nr) {
#if defined(__x86_64__)
return nr == 16;
#else
(void)nr;
return false;
#endif
}
bool is_ioctl(long nr) { return nr == SYS_ioctl; }
/* ---- the stack of a thread that waits in user space, taken by a signal it handles itself ---- */
@@ -133,10 +127,9 @@ std::string stack_of(pid_t tid) {
} /* namespace */
std::string stall_module_offset(uintptr_t addr) {
/* RELATIVE TO WHERE THE MODULE IS LOADED, which is what addr2line takes for a position-
* independent binary or library: the start of its first mapping, less that mapping's file
* offset. The offset into the file is not the same number wherever the linker puts a segment
* at a different address than its file position, as lld does. */
/* Relative to the module's load base (lowest mapping start minus its file offset), which is
* what addr2line takes for PIC code. The file offset differs where the linker places a
* segment at an address unlike its file position, as lld does. */
struct Map { unsigned long lo, hi, off; std::string path; };
std::vector<Map> maps;
{
@@ -212,8 +205,8 @@ std::string stall_describe_thread(pid_t tid, bool stack) {
s += ", " + stall_decode_syscall(sc);
long nr = -1;
std::sscanf(sc.c_str(), "%ld", &nr);
/* A thread in a driver call is not signalled: the call already says where it is, and a wait
* the signal interrupts may end the call early instead of restarting it. */
/* A thread in a driver call is not signalled: the call already says where it waits, and the
* signal could end the wait early instead of restarting it. */
if (stack && !is_ioctl(nr) && state != 'D') s += "\n stack: " + stack_of(tid);
return s;
}
@@ -221,6 +214,7 @@ std::string stall_describe_thread(pid_t tid, bool stack) {
struct StallWatch::Impl {
std::string phase;
uint64_t quiet_ns = 0;
uint64_t poll_ns = 0;
pid_t holder = 0;
std::mutex mu;
std::condition_variable cv;
@@ -256,7 +250,7 @@ struct StallWatch::Impl {
uint64_t own = 0; /* the time of this watch's own last report */
uint64_t next = quiet_ns; /* the silence that is reported next */
std::unique_lock<std::mutex> lk(mu);
while (!cv.wait_for(lk, std::chrono::seconds(1), [&] { return stop; })) {
while (!cv.wait_for(lk, std::chrono::nanoseconds(poll_ns), [&] { return stop; })) {
const uint64_t last = log_last_line_ns();
if (last > since && last != own) { since = last; next = quiet_ns; }
const uint64_t now = rad_mono_ns();
@@ -273,6 +267,9 @@ struct StallWatch::Impl {
StallWatch::StallWatch(const char* phase, uint64_t quiet_ms) : p_(std::make_unique<Impl>()) {
p_->phase = phase ? phase : "phase";
p_->quiet_ns = quiet_ms * 1000000ull;
/* A quarter of the quiet interval, so a report is at most that late, and at most a second. */
p_->poll_ns = std::max<uint64_t>(1000000ull, std::min<uint64_t>(1000000000ull,
p_->quiet_ns / 4));
p_->holder = (pid_t)syscall(SYS_gettid);
install_stack_handler();
p_->th = std::thread([this] { p_->run(); });
+7 -8
View File
@@ -1,13 +1,11 @@
/* stallwatch.h -- naming where a phase that has gone quiet is waiting.
*
* A startup that stops printing leaves the hardest report to act on: the log ends on the last line
* that was printed, and whatever came after it -- a driver call that never returned, a lock inside a
* runtime library -- leaves no trace. The machine it happens on is often one this project cannot
* run (a guest kernel, a card passed through to a VM), so where it waits has to come from the
* process itself.
* A hang (a driver call that never returns, a lock inside a runtime library) leaves no trace in
* the log, often on machines that cannot be reproduced locally (a guest kernel, a passed-through
* card), so the process reports where it waits.
*
* A StallWatch is held across a phase by the thread doing it. When nothing has been logged for the
* quiet interval it says what that thread is doing:
* quiet interval it reports what that thread is doing:
* - its scheduler state and kernel wait channel;
* - the system call it is in, an ioctl with its device and request, and the library that made
* the call;
@@ -17,8 +15,9 @@
* early;
* - the process's other threads that are inside an ioctl, since a lock in a runtime library is
* usually held by one of them.
* It says it again each time the silence doubles, so a later log shows whether the thread moved.
* The watch reads only its own process's /proc entries and costs one wake-up a second while held.
* It reports again each time the silence doubles, showing whether the thread moved. The watch
* reads only its own process's /proc entries and wakes every quarter of the quiet interval, at most
* once a second, while held.
*/
#pragma once