Archived
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:
1 parent
b068190326
commit
1e968f6e1d
739 files changed
+128447
-84632
No files matched your search
+58
-37
@@ -1,31 +1,27 @@
|
||||
/* quant_fixture.h -- quantising a weight through a quantiser plugin exactly as rad-convert does.
|
||||
/* quant_fixture.h -- quantise a weight through a quantiser plugin exactly as rad-convert does.
|
||||
*
|
||||
* Shared by the tests that hold a quantiser's output to something: quant_test reads it back
|
||||
* through the core's decoder, relayout_parity_test hands it to the kernel libraries' relayouts.
|
||||
* Both have to quantise the way the converter will -- ask the encoding, size the planes, pass the
|
||||
* rows over in the quantiser's own blocks -- or what they check is a path no container is made by.
|
||||
* Shared by quant_test (reads the result back through the core's decoder) and
|
||||
* relayout_parity_test (hands it to the kernel libraries' relayouts). Both run the converter's own
|
||||
* loop (core/format/quantise.h) into memory, so they test the path every container is made by.
|
||||
*/
|
||||
#pragma once
|
||||
#include "rad_test.h"
|
||||
#include "rad_plugin.h"
|
||||
#include "rad_quant.h"
|
||||
#include "format/encoding.h"
|
||||
#include "format/quantise.h"
|
||||
#include "plugin/registry.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace qfix {
|
||||
|
||||
inline std::string home() {
|
||||
const char* h = std::getenv("RADIANCE_HOME");
|
||||
return h ? h : "radiance_home";
|
||||
}
|
||||
|
||||
inline rad::Registry& reg() {
|
||||
static rad::Registry r;
|
||||
static bool tried = false;
|
||||
@@ -44,7 +40,7 @@ inline const RadQuantizerInfo* quantizer(const char* name) {
|
||||
#define NEED_LIBQUANT() \
|
||||
do { \
|
||||
if (!::qfix::quantizer("rtn")) { \
|
||||
std::fprintf(stderr, " SKIP no libquant under %s\n", ::qfix::home().c_str()); \
|
||||
std::fprintf(stderr, " SKIP no libquant under %s\n", ::home().c_str()); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -109,13 +105,9 @@ struct Quantised {
|
||||
int status = RAD_OK;
|
||||
};
|
||||
|
||||
/* Quantise as rad-convert does: ask the encoding, size the planes, hand the rows over in the
|
||||
* quantiser's own blocks. `importance` is the imatrix's column importances the converter would
|
||||
* hand over, or null -- and null when the encoding is asked, as at declare. */
|
||||
inline Quantised quantise(const RadQuantizerInfo* q, Opts& o, const char* name, int64_t rows,
|
||||
int64_t cols, const std::vector<float>& w,
|
||||
const float* importance = nullptr) {
|
||||
Quantised out;
|
||||
/* A [rows, cols] weight outside any layer or expert, as the quantiser is handed one. */
|
||||
inline RadQuantWeight weight_of(const char* name, int64_t rows, int64_t cols,
|
||||
const float* importance = nullptr) {
|
||||
RadQuantWeight qw{};
|
||||
qw.name = name;
|
||||
qw.rank = 2;
|
||||
@@ -124,31 +116,54 @@ inline Quantised quantise(const RadQuantizerInfo* q, Opts& o, const char* name,
|
||||
qw.rows = rows;
|
||||
qw.cols = cols;
|
||||
qw.layer = qw.expert = -1;
|
||||
out.status = q->encoding(o.data(), o.n(), &qw, &out.enc);
|
||||
if (out.status != RAD_OK) return out;
|
||||
qw.importance = importance;
|
||||
return qw;
|
||||
}
|
||||
|
||||
/* Quantise as rad-convert does: ask the encoding with no importance (as at declare), size the
|
||||
* planes, then run the converter's loop with the importance. `blk` is the rows a call (rounded down
|
||||
* to a multiple of the quantiser's row block, as the converter rounds its band); 0 takes the
|
||||
* converter's own band, kQuantBandBytes of f32. `importance` is the imatrix column importance, or
|
||||
* null. */
|
||||
inline Quantised quantise(const RadQuantizerInfo* q, Opts& o, const char* name, int64_t rows,
|
||||
int64_t cols, const std::vector<float>& w,
|
||||
const float* importance = nullptr, int64_t blk = 0) {
|
||||
Quantised out;
|
||||
const RadQuantWeight declared = weight_of(name, rows, cols);
|
||||
const RadQuantWeight qw = weight_of(name, rows, cols, importance);
|
||||
out.status = q->encoding(o.data(), o.n(), &declared, &out.enc);
|
||||
if (out.status != RAD_OK) return out;
|
||||
for (int i = 0; i < out.enc.n_planes; ++i)
|
||||
out.planes.emplace_back((size_t)rad_enc_plane_bytes(&out.enc.plane[i], rows, cols), 0);
|
||||
int64_t rb = q->row_block(o.data(), o.n(), &qw);
|
||||
if (rb <= 0) rb = rows;
|
||||
for (int64_t r0 = 0; r0 < rows; r0 += rb) {
|
||||
const int64_t n = r0 + rb < rows ? rb : rows - r0;
|
||||
std::vector<float> blk(w.begin() + r0 * cols, w.begin() + (r0 + n) * cols);
|
||||
std::vector<void*> pp;
|
||||
for (int i = 0; i < out.enc.n_planes; ++i) {
|
||||
const RadEncPlane& p = out.enc.plane[i];
|
||||
int64_t pr = 0, pc = 0;
|
||||
rad_enc_plane_dims(&p, rows, cols, &pr, &pc);
|
||||
const bool banded = p.kind == RAD_PLANE_TILED && p.block[0] > 0;
|
||||
const int64_t prow = banded ? r0 / p.block[0] : 0;
|
||||
pp.push_back(out.planes[(size_t)i].data() + prow * rad_enc_row_bytes(p.dtype, pc));
|
||||
}
|
||||
out.status = q->quantize(o.data(), o.n(), &qw, blk.data(), r0, n, pp.data());
|
||||
if (out.status != RAD_OK) return out;
|
||||
}
|
||||
rad::QuantIo io;
|
||||
io.read = [&](int64_t r0, int64_t n, float* dst, std::string*) {
|
||||
std::memcpy(dst, w.data() + r0 * cols, (size_t)(n * cols) * sizeof(float));
|
||||
return (int)RAD_OK;
|
||||
};
|
||||
io.write = [&](int k, int64_t off, const void* data, int64_t bytes) {
|
||||
std::vector<uint8_t>& p = out.planes[(size_t)k];
|
||||
if (off < 0 || bytes < 0 || (size_t)(off + bytes) > p.size()) return (int)RAD_E_INVAL;
|
||||
std::memcpy(p.data() + off, data, (size_t)bytes);
|
||||
return (int)RAD_OK;
|
||||
};
|
||||
const int64_t band = blk > 0 ? blk * cols * (int64_t)sizeof(float) : rad::kQuantBandBytes;
|
||||
std::string why;
|
||||
out.status = rad::quantise_weight(*q, o.data(), o.n(), qw, out.enc, band, io, &why);
|
||||
if (out.status != RAD_OK) std::fprintf(stderr, " quantise: %s\n", why.c_str());
|
||||
return out;
|
||||
}
|
||||
|
||||
/* An empty directory of its own under the test's temporary directory, which the harness removes. */
|
||||
struct TempDir {
|
||||
std::string path;
|
||||
explicit TempDir(const char* stem) {
|
||||
std::string t = radtest::tmp_path(std::string(stem) + "_XXXXXX");
|
||||
path = mkdtemp(t.data()) ? t : std::string();
|
||||
}
|
||||
TempDir(const TempDir&) = delete;
|
||||
TempDir& operator=(const TempDir&) = delete;
|
||||
};
|
||||
|
||||
inline std::vector<float> decode(const Quantised& q, int64_t rows, int64_t cols) {
|
||||
std::vector<const void*> d;
|
||||
for (auto& p : q.planes) d.push_back(p.data());
|
||||
@@ -163,6 +178,12 @@ inline std::vector<float> decode(const Quantised& q, int64_t rows, int64_t cols)
|
||||
return out;
|
||||
}
|
||||
|
||||
/* FNV-1a over `b`, continuing from `h`. */
|
||||
inline uint64_t fnv(const std::vector<uint8_t>& b, uint64_t h = 0xcbf29ce484222325ull) {
|
||||
for (uint8_t c : b) h = (h ^ c) * 0x100000001b3ull;
|
||||
return h;
|
||||
}
|
||||
|
||||
inline double rel_err(const std::vector<float>& a, const std::vector<float>& b) {
|
||||
double num = 0, den = 0;
|
||||
for (size_t i = 0; i < a.size(); ++i) {
|
||||
|
||||
Reference in new issue
Block a user