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/core/server/json_partial.cpp
T
Deadcode ddcb9c69bb radiance 2.0.0
Radiance becomes a multi-model engine: one process serves several models behind one port, loads
each when a request names it, parks it in host memory or restores it from its container, and
shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the
command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP).

Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an
int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block
FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such
weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5,
Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B,
the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0
serves all of them.

Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new
Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill
reworked, and a reworked adaptive draft window.

Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its
configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool
in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server,
each accelerator's memory by model, model states over time.

Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by
AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests
keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410);
eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d
large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi
(#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon
(#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and
multi-model serving as asked for in #367 and #109.

Plugin ABI 39: out-of-tree plugins need to be rebuilt.

Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
2026-11-14 22:32:28 +01:00

241 lines
8.0 KiB
C++

#include "json_partial.h"
#include "util/simd.h"
namespace rad {
namespace server {
namespace {
struct Scanner {
std::string_view s;
size_t i = 0;
void ws() {
while (i < s.size() && (s[i] == ' ' || s[i] == '\t' || s[i] == '\n' || s[i] == '\r')) ++i;
}
bool eof() const { return i >= s.size(); }
char peek() const { return s[i]; }
bool lit(std::string_view w) {
if (s.size() - i < w.size()) return false;
if (s.compare(i, w.size(), w) != 0) return false;
i += w.size();
return true;
}
bool str() {
if (eof() || s[i] != '"') return false;
++i;
while (!eof()) {
char c = s[i];
if (c == '\\') {
if (i + 1 >= s.size()) return false;
char e = s[i + 1];
if (e == 'u') {
if (i + 5 >= s.size()) return false;
i += 6;
} else {
i += 2;
}
continue;
}
if (c == '"') { ++i; return true; }
++i;
}
return false; /* unterminated */
}
bool num() {
size_t start = i;
if (!eof() && s[i] == '-') ++i;
size_t d0 = i;
while (!eof() && s[i] >= '0' && s[i] <= '9') ++i;
if (i == d0) { i = start; return false; }
if (!eof() && s[i] == '.') {
++i;
size_t d1 = i;
while (!eof() && s[i] >= '0' && s[i] <= '9') ++i;
if (i == d1) { i = start; return false; }
}
if (!eof() && (s[i] == 'e' || s[i] == 'E')) {
++i;
if (!eof() && (s[i] == '+' || s[i] == '-')) ++i;
size_t d2 = i;
while (!eof() && s[i] >= '0' && s[i] <= '9') ++i;
if (i == d2) { i = start; return false; }
}
return true;
}
bool value(int depth) {
/* Depth cap: the input is model output, and a runaway "[[[[..." would otherwise recurse
* until the stack overflows. 256 is far past any real tool schema. */
if (depth > 256) return false;
ws();
if (eof()) return false;
char c = peek();
if (c == '"') return str();
if (c == '{') return obj(depth + 1);
if (c == '[') return arr(depth + 1);
if (c == 't') return lit("true");
if (c == 'f') return lit("false");
if (c == 'n') return lit("null");
return num();
}
bool obj(int depth) {
++i; /* '{' */
ws();
if (eof()) return false;
if (peek() == '}') { ++i; return true; }
for (;;) {
ws();
if (!str()) return false;
ws();
if (eof() || peek() != ':') return false;
++i;
if (!value(depth)) return false;
ws();
if (eof()) return false;
if (peek() == ',') { ++i; continue; }
if (peek() == '}') { ++i; return true; }
return false;
}
}
bool arr(int depth) {
++i; /* '[' */
ws();
if (eof()) return false;
if (peek() == ']') { ++i; return true; }
for (;;) {
if (!value(depth)) return false;
ws();
if (eof()) return false;
if (peek() == ',') { ++i; continue; }
if (peek() == ']') { ++i; return true; }
return false;
}
}
};
} /* namespace */
bool json_complete(std::string_view s) {
Scanner sc{s};
if (!sc.value(0)) return false;
sc.ws();
return sc.eof();
}
size_t utf8_trunc(std::string_view s) {
size_t n = s.size();
if (n == 0) return 0;
/* Walk back over at most three continuation bytes to find the lead byte, then decide whether
* the sequence it starts is complete. */
size_t k = n;
size_t back = 0;
while (k > 0 && back < 4) {
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;
else if ((c & 0xF0) == 0xE0) need = 3;
else if ((c & 0xF8) == 0xF0) need = 4;
else return n; /* not a lead byte: not our truncation to fix */
size_t have = n - (k - 1);
return have >= need ? n : k - 1;
}
return n;
}
size_t json_stable_prefix(std::string_view s) {
size_t n = utf8_trunc(s);
if (n == 0) return 0;
/* Back out of an unfinished escape. Count the run of backslashes immediately before the cut:
* an odd run means the last one is an opening escape whose payload has not arrived. */
size_t bs = 0;
while (bs < n && s[n - 1 - bs] == '\\') ++bs;
if (bs % 2 == 1) return n - 1;
/* Back out of an unfinished "\uXXXX". `k` counts the characters after the 'u'; the escape is
* complete at k == 4. At most six bytes are examined. */
for (size_t k = 0; k <= 4 && n >= k + 2; ++k) {
if (s[n - 1 - k] != 'u') continue;
if (s[n - 2 - k] != '\\') break;
size_t bs2 = 0, j = n - 2 - k;
while (j > 0 && s[j - 1] == '\\') { ++bs2; --j; }
if (bs2 % 2 == 1) break; /* the backslash was itself escaped */
if (k < 4) return n - 2 - k; /* fewer than four hex digits have arrived */
break;
}
return n;
}
bool json_quote_append(std::string& out, std::string_view s) {
static const char kHex[] = "0123456789abcdef";
const size_t mark = out.size();
out.reserve(mark + s.size() + 2);
out.push_back('"');
const unsigned char* p = (const unsigned char*)s.data();
const unsigned char* e = p + s.size();
const unsigned char* run = p; /* [run, p) is verified and goes out as it is */
while (p < e) {
/* Ordinary bytes go out as they are: jump over them a vector at a time to the next
* byte that needs an escape or UTF-8 validation. */
p += simd::first_json_special((const char*)p, (size_t)(e - p));
if (p >= e) break;
const unsigned char c = *p;
if (c >= 0x80) {
/* Sequence length and the allowed range of the second byte, which rejects overlong
* forms, surrogates and code points past U+10FFFF without decoding. */
size_t len;
unsigned char lo = 0x80, hi = 0xBF;
if (c >= 0xC2 && c <= 0xDF) len = 2;
else if (c == 0xE0) { len = 3; lo = 0xA0; }
else if (c >= 0xE1 && c <= 0xEC) len = 3;
else if (c == 0xED) { len = 3; hi = 0x9F; }
else if (c >= 0xEE && c <= 0xEF) len = 3;
else if (c == 0xF0) { len = 4; lo = 0x90; }
else if (c >= 0xF1 && c <= 0xF3) len = 4;
else if (c == 0xF4) { len = 4; hi = 0x8F; }
else len = 0;
bool ok = len != 0 && (size_t)(e - p) >= len && p[1] >= lo && p[1] <= hi;
for (size_t k = 2; ok && k < len; ++k) ok = p[k] >= 0x80 && p[k] <= 0xBF;
if (!ok) {
out.resize(mark);
return false;
}
p += len;
continue;
}
if (c >= 0x20 && c != '"' && c != '\\') {
++p;
continue;
}
out.append((const char*)run, (size_t)(p - run));
switch (c) {
case '"': out += "\\\""; break;
case '\\': out += "\\\\"; break;
case '\b': out += "\\b"; break;
case '\t': out += "\\t"; break;
case '\n': out += "\\n"; break;
case '\f': out += "\\f"; break;
case '\r': out += "\\r"; break;
default: {
const char u[6] = { '\\', 'u', '0', '0', kHex[c >> 4], kHex[c & 15] };
out.append(u, 6);
}
}
run = ++p;
}
out.append((const char*)run, (size_t)(p - run));
out.push_back('"');
return true;
}
} /* namespace server */
} /* namespace rad */