Archived
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.
129 lines
5.8 KiB
C++
129 lines
5.8 KiB
C++
#include "text/tokenizer_nfc.h"
|
|
#include "text/unicode_norm.h"
|
|
#include "util/simd.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
namespace rad {
|
|
|
|
namespace {
|
|
|
|
/* NFC, applied only where it can change something.
|
|
*
|
|
* UAX #15 quick check: a codepoint with NFC_QC Yes and combining class 0 is a boundary. Nothing
|
|
* before it can compose with it or reorder across it, and nothing it becomes reaches back past
|
|
* it, so normalising the text between two boundaries alone gives the same bytes as normalising
|
|
* the whole text. The scan finds the non-boundary codepoints (NFC_QC No or Maybe, a mark out of
|
|
* canonical order, ill-formed UTF-8) and runs unorm_utf8 only from the boundary before each one
|
|
* to the boundary after it; the rest is copied. The properties are derived from the tables
|
|
* unorm_utf8 uses ("No": NFC changes the codepoint on its own; "Maybe": it can compose with what
|
|
* precedes it), so the scan agrees with that implementation. Invalid bytes are never boundaries,
|
|
* so their replacement happens inside a normalised stretch, exactly as for the whole text. */
|
|
class NfcQuick {
|
|
public:
|
|
NfcQuick() : not_yes_(kWords, 0), marked_(kWords, 0) {
|
|
for (size_t i = 0; i < k_decomp_rows_n; ++i) {
|
|
const DecompRow& r = k_decomp_rows[i];
|
|
if (r.len_c == 0) continue;
|
|
std::vector<uint32_t> v{ r.cpt };
|
|
unorm_decompose(v, false);
|
|
unorm_compose(v);
|
|
if (v != std::vector<uint32_t>{ r.cpt }) set(not_yes_, r.cpt);
|
|
}
|
|
for (size_t i = 0; i < k_compose_n; ++i) set(not_yes_, k_compose[i].b);
|
|
for (uint32_t c = 0x1161; c <= 0x1175; ++c) set(not_yes_, c); /* Hangul V, composes after L */
|
|
for (uint32_t c = 0x11A8; c <= 0x11C2; ++c) set(not_yes_, c); /* Hangul T, composes after LV */
|
|
for (size_t i = 0; i < k_ccc_n; ++i)
|
|
for (uint32_t c = k_ccc[i].first; c <= k_ccc[i].last; ++c) set(marked_, c);
|
|
}
|
|
|
|
/* Normalise `text` in place; false when it was already NFC and is untouched. */
|
|
bool apply(std::string& text) const {
|
|
const uint8_t* p = (const uint8_t*)text.data();
|
|
const size_t n = text.size();
|
|
std::string out;
|
|
size_t copied = 0; /* text[0, copied) is in `out` */
|
|
size_t boundary = 0; /* start of the last boundary codepoint seen */
|
|
uint32_t last = 0; /* combining class of the previous codepoint */
|
|
for (size_t i = 0; i < n; ) {
|
|
/* ASCII codepoints are all boundaries: skip a run at vector width. */
|
|
const size_t run = simd::first_non_ascii((const char*)p + i, n - i);
|
|
if (run) { last = 0; boundary = i + run - 1; i += run; continue; }
|
|
uint32_t len, ccc;
|
|
const int k = classify(p + i, n - i, &len, &ccc);
|
|
if (k == kBoundary) { last = 0; boundary = i; i += len; continue; }
|
|
if (k == kKeep && !(ccc != 0 && last > ccc)) { last = ccc; i += len; continue; }
|
|
/* Something NFC may change: normalise from the boundary before it to the next one. */
|
|
size_t end = i + len;
|
|
while (end < n) {
|
|
uint32_t l2, c2;
|
|
if (classify(p + end, n - end, &l2, &c2) == kBoundary) break;
|
|
end += l2;
|
|
}
|
|
const size_t start = std::max(boundary, copied);
|
|
out.append(text, copied, start - copied);
|
|
out += unorm_utf8(text.substr(start, end - start), false, true);
|
|
copied = end;
|
|
boundary = end;
|
|
last = 0;
|
|
i = end;
|
|
}
|
|
if (copied == 0) return false;
|
|
out.append(text, copied, std::string::npos);
|
|
text.swap(out);
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
enum { kBoundary, kKeep, kChange };
|
|
static constexpr uint32_t kInvalidLen = UINT32_MAX;
|
|
static constexpr size_t kWords = (0x110000 + 63) / 64;
|
|
static void set(std::vector<uint64_t>& b, uint32_t c) { b[c >> 6] |= 1ull << (c & 63); }
|
|
static bool get(const std::vector<uint64_t>& b, uint32_t c) { return (b[c >> 6] >> (c & 63)) & 1; }
|
|
|
|
/* kBoundary: a well-formed codepoint with class 0 and NFC_QC Yes. kKeep: well-formed, NFC_QC
|
|
* Yes, a nonzero class (in `ccc`) the caller checks for order. kChange: anything else; an
|
|
* invalid byte reports a length of 1 and kInvalidLen in `ccc`. */
|
|
int classify(const uint8_t* p, size_t n, uint32_t* len, uint32_t* ccc) const {
|
|
const uint32_t b = p[0];
|
|
*ccc = 0;
|
|
if (b < 0x80) { *len = 1; return kBoundary; }
|
|
uint32_t c;
|
|
auto cont = [&](size_t k) { return k < n && (p[k] & 0xC0) == 0x80; };
|
|
if (b >= 0xC2 && b < 0xE0 && cont(1)) {
|
|
c = ((b & 0x1F) << 6) | (p[1] & 0x3F);
|
|
*len = 2;
|
|
} else if (b >= 0xE0 && b < 0xF0 && cont(1) && cont(2)) {
|
|
c = ((b & 0x0F) << 12) | ((p[1] & 0x3F) << 6) | (p[2] & 0x3F);
|
|
*len = 3;
|
|
if (c < 0x800 || (c >= 0xD800 && c <= 0xDFFF)) { *len = 1; *ccc = kInvalidLen; return kChange; }
|
|
} else if (b >= 0xF0 && b < 0xF5 && cont(1) && cont(2) && cont(3)) {
|
|
c = ((b & 0x07) << 18) | ((p[1] & 0x3F) << 12) | ((p[2] & 0x3F) << 6) | (p[3] & 0x3F);
|
|
*len = 4;
|
|
if (c < 0x10000 || c > 0x10FFFF) { *len = 1; *ccc = kInvalidLen; return kChange; }
|
|
} else {
|
|
*len = 1;
|
|
*ccc = kInvalidLen;
|
|
return kChange;
|
|
}
|
|
if (get(not_yes_, c)) { *ccc = get(marked_, c) ? unorm_ccc(c) : 0; return kChange; }
|
|
if (!get(marked_, c)) return kBoundary;
|
|
*ccc = unorm_ccc(c);
|
|
return *ccc ? kKeep : kBoundary;
|
|
}
|
|
|
|
std::vector<uint64_t> not_yes_; /* NFC_QC is No or Maybe */
|
|
std::vector<uint64_t> marked_; /* canonical combining class is not 0 */
|
|
};
|
|
|
|
} /* namespace */
|
|
|
|
bool tok_nfc(std::string& text) {
|
|
static const NfcQuick q;
|
|
return q.apply(text);
|
|
}
|
|
|
|
} /* namespace rad */
|