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
+29
-30
@@ -16,11 +16,11 @@ namespace lq {
|
||||
|
||||
namespace {
|
||||
|
||||
/* H is damped, inverted and re-factorised into the upper triangle U with U^T U = H^-1, the form
|
||||
* the sequential loop wants: column i's error is divided by U[i][i] and spread over columns j > i
|
||||
* with weight U[i][j]. Frantar's formulation, followed rather than re-derived. DOUBLE throughout:
|
||||
* a Cholesky is K^3/6 accumulations deep, and f32 there costs real conditioning on a matrix that
|
||||
* is near-singular in the directions a rotation flattened. */
|
||||
/* H is damped, inverted and re-factorised into upper U with U^T U = H^-1, the form the sequential
|
||||
* loop wants: column i's error is divided by U[i][i] and spread over columns j > i with weight
|
||||
* U[i][j] (Frantar et al.'s formulation). Double throughout: a Cholesky is K^3/6 accumulations
|
||||
* deep, and f32 loses real conditioning on a matrix near-singular in the directions a rotation
|
||||
* flattened. */
|
||||
bool chol_lower(std::vector<double>& a, int64_t k) {
|
||||
for (int64_t i = 0; i < k; ++i) {
|
||||
for (int64_t j = 0; j <= i; ++j) {
|
||||
@@ -98,9 +98,8 @@ std::vector<int32_t> gptq_act_order(const char* dir, const char* name, int64_t K
|
||||
if (!dir || !*dir || !name || !*name || K <= 0) return perm;
|
||||
std::vector<double> acc;
|
||||
if (!calib_sum(dir, calib_resolve(dir, name, K), K, domain, &acc)) return perm;
|
||||
/* THE COLUMNS OF LARGEST INPUT ENERGY FIRST, a tie in the order the columns sit: the
|
||||
* recursion has the most freedom to absorb error early, so the columns that cost most to get
|
||||
* wrong are quantised while every later column is still there to take it. */
|
||||
/* Largest input energy first, ties in column order. The recursion absorbs error best early,
|
||||
* so the costliest columns are quantised while every later column can still take it. */
|
||||
std::stable_sort(perm.begin(), perm.end(), [&](int32_t x, int32_t y) {
|
||||
return acc[(size_t)x * (size_t)K + (size_t)x] > acc[(size_t)y * (size_t)K + (size_t)y];
|
||||
});
|
||||
@@ -117,9 +116,8 @@ Gram gptq_factor(const char* dir, const char* name, int64_t K, int64_t domain, d
|
||||
const std::string key = std::string(dir) + "|" + stem + "|" + std::to_string(K) + "|" +
|
||||
std::to_string(domain) + "|" + dk + (perm ? "|act" : "");
|
||||
|
||||
/* A LAYER'S FACTOR IS SHARED by every expert that reads it, so it is made once under the
|
||||
* lock and kept; an expert's own is made for its one call, outside it, so experts quantised
|
||||
* side by side factor side by side. */
|
||||
/* A layer's factor is shared by its experts, so it is built once under the lock and cached.
|
||||
* An expert's own is built for its one call outside the lock, so experts factor in parallel. */
|
||||
Cache& c = cache();
|
||||
std::unique_lock<std::mutex> lk(c.mu, std::defer_lock);
|
||||
if (layer) {
|
||||
@@ -139,8 +137,8 @@ Gram gptq_factor(const char* dir, const char* name, int64_t K, int64_t domain, d
|
||||
"rounding it to nearest\n", name, dir, stem.c_str());
|
||||
return keep(nullptr);
|
||||
}
|
||||
/* Under act order the Hessian is the PERMUTED one, P H P^T: the recursion runs over the
|
||||
* columns in the order they are quantised, and that is the order the factor has to be in. */
|
||||
/* Under act order the factor is of P H P^T, since the recursion runs over columns in
|
||||
* quantisation order. */
|
||||
if (perm) {
|
||||
std::vector<double> p((size_t)(K * K));
|
||||
for (int64_t i = 0; i < K; ++i)
|
||||
@@ -155,9 +153,9 @@ Gram gptq_factor(const char* dir, const char* name, int64_t K, int64_t domain, d
|
||||
if (!(acc[(size_t)(i * K + i)] > 0.0)) ++dead;
|
||||
tr += acc[(size_t)(i * K + i)];
|
||||
}
|
||||
/* A DEAD COLUMN IS A CHANNEL THE CORPUS NEVER EXERCISED: its diagonal is zero, the Cholesky
|
||||
* would fail on it, and the calibration says nothing about it -- so it gets the mean diagonal,
|
||||
* which makes the recursion leave it alone rather than spend other columns' error on it. */
|
||||
/* A dead column is a channel the corpus never exercised: its diagonal is zero, the Cholesky
|
||||
* would fail on it, and the calibration says nothing about it. It gets the mean diagonal, so
|
||||
* the recursion does not spend other columns' error on it. */
|
||||
const double mean = tr / (double)K;
|
||||
const double lam = damp * mean;
|
||||
for (int64_t i = 0; i < K; ++i) {
|
||||
@@ -206,10 +204,9 @@ void gptq_quantise(const Grid& g, float* w, int32_t* codes, const Scales& scales
|
||||
return;
|
||||
}
|
||||
|
||||
/* COLUMN BLOCKS OUTSIDE, ROWS INSIDE. The recursion is independent per row, so rows are the
|
||||
* parallelism; but a row that ran the full K alone would stream all K^2 of `u` for itself.
|
||||
* With the block outside, every row is at the same columns at the same time and the slice of
|
||||
* `u` they share -- 128 x K -- stays in cache. */
|
||||
/* Column blocks outside, rows inside. Rows are independent and are the parallelism, but a row
|
||||
* running all of K alone would stream all K^2 of `u`. With the block loop outside, all rows
|
||||
* work on the same columns together and the shared 128 x K slice of `u` stays in cache. */
|
||||
const int64_t B = 128;
|
||||
std::vector<float> err((size_t)(N * B));
|
||||
for (int64_t b0 = 0; b0 < K; b0 += B) {
|
||||
@@ -226,7 +223,7 @@ void gptq_quantise(const Grid& g, float* w, int32_t* codes, const Scales& scales
|
||||
const float v = wr[i];
|
||||
const float dq = one(n, i, v);
|
||||
wr[i] = dq;
|
||||
/* d is U[i][i], strictly positive by construction -- chol_upper refuses otherwise */
|
||||
/* d is U[i][i], strictly positive: chol_upper refuses otherwise. */
|
||||
const float e = (v - dq) / d;
|
||||
er[i - b0] = e;
|
||||
for (int64_t j = i + 1; j < b1; ++j) wr[j] -= e * ur[j];
|
||||
@@ -243,19 +240,21 @@ void gptq_quantise(const Grid& g, float* w, int32_t* codes, const Scales& scales
|
||||
void gptq_refine(const Grid& g, const float* x, float* w, int32_t* codes, const Scales& scales,
|
||||
int64_t N, int64_t K, const float* h, double damp, int passes) {
|
||||
if (!x || !w || !codes || !h || N <= 0 || K <= 0 || passes <= 0) return;
|
||||
/* THE DAMPING GPTQ'S FACTOR CARRIES, so the two minimise the same form: lambda is `damp` of
|
||||
* the mean diagonal, and a column the corpus never exercised takes the mean as its diagonal. */
|
||||
/* Same damping as gptq_factor, so both minimise the same form: lambda is `damp` times the mean
|
||||
* diagonal, and an unexercised column takes the mean as its diagonal. `ad` is what the form
|
||||
* adds to H's diagonal, `dg` the resulting diagonal. */
|
||||
double tr = 0.0;
|
||||
for (int64_t i = 0; i < K; ++i) tr += h[(size_t)(i * K + i)];
|
||||
const double mean = tr / (double)K;
|
||||
const float lam = (float)(damp * mean);
|
||||
std::vector<float> dg((size_t)K);
|
||||
std::vector<float> ad((size_t)K), dg((size_t)K);
|
||||
for (int64_t i = 0; i < K; ++i) {
|
||||
const float d = h[(size_t)(i * K + i)];
|
||||
ad[(size_t)i] = (d > 0.0f ? 0.0f : (float)mean) + lam;
|
||||
dg[(size_t)i] = (d > 0.0f ? d : (float)mean) + lam;
|
||||
}
|
||||
/* G = E H for every row at once, by the deterministic blocked product; each row then keeps
|
||||
* its own G current with one row of H per code that moves. */
|
||||
/* G = E (H + diag(ad)) for all rows by the deterministic blocked product; each row then keeps
|
||||
* its G current by adding one row of it per code that moves. */
|
||||
std::vector<float> e((size_t)(N * K)), gm((size_t)(N * K));
|
||||
for (size_t i = 0; i < e.size(); ++i) e[i] = w[i] - x[i];
|
||||
mat_hess(e.data(), N, K, h, gm.data());
|
||||
@@ -268,7 +267,7 @@ void gptq_refine(const Grid& g, const float* x, float* w, int32_t* codes, const
|
||||
const float* xr = x + (size_t)(n * K);
|
||||
float* wr = w + (size_t)(n * K);
|
||||
int32_t* cr = codes + (size_t)(n * K);
|
||||
for (int64_t j = 0; j < K; ++j) gr[j] += lam * er[j];
|
||||
for (int64_t j = 0; j < K; ++j) gr[j] += ad[(size_t)j] * er[j];
|
||||
for (int pass = 0; pass < passes; ++pass) {
|
||||
int64_t moved = 0;
|
||||
for (int64_t j = 0; j < K; ++j) {
|
||||
@@ -280,12 +279,12 @@ void gptq_refine(const Grid& g, const float* x, float* w, int32_t* codes, const
|
||||
if (c == cr[j]) continue;
|
||||
const float dq = grid_decode(g, b, c);
|
||||
const float d = (dq - xr[j]) - er[j];
|
||||
/* Only a strict improvement moves a code: the change in the form is
|
||||
* d (2 g_j + d hj), g_j the current gradient, and a tie keeps GPTQ's choice. */
|
||||
/* Only a strict improvement moves a code: the form changes by d (2 g_j + d hj),
|
||||
* g_j the current gradient; a tie keeps GPTQ's choice. */
|
||||
if (!(d * (2.0f * gr[j] + d * hj) < 0.0f)) continue;
|
||||
const float* hr = h + (size_t)(j * K);
|
||||
for (int64_t t2 = 0; t2 < K; ++t2) gr[t2] += d * hr[t2];
|
||||
gr[j] += lam * d;
|
||||
gr[j] += ad[(size_t)j] * d;
|
||||
er[j] += d;
|
||||
wr[j] = dq;
|
||||
cr[j] = c;
|
||||
|
||||
Reference in new issue
Block a user