Archived
Merge upstream main (v1.17.0 -> v2.1.0) into the SYCL port
102 upstream commits. Nine conflicts resolved. Fork side of the merge: - libxe2: declare the givens_dense_quant schema (upstream 2.0 dropped it from libavx and libref; the device libraries now each carry it). - plain_norm becomes an ABI 42 append to RadBuildCtx; abi layout table regenerated, kTableAbi = 42. Known before the PR: arch_test (MTP lint and pinned graph hashes for qwen35_fp8, qwen35moe_fp8, qwen4exp with MTP). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
4b70a96378
850 files changed
+157819
-58519
No files matched your search
+47
-5
@@ -99,6 +99,18 @@ const std::vector<NamedTable>& named_tables() {
|
||||
14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 30.0f,
|
||||
-0.8125f, -2.5f, -4.0f, -5.5f, -7.5f, -9.0f, -11.0f, -12.0f,
|
||||
-14.0f, -16.0f, -18.0f, -20.0f, -22.0f, -24.0f, -26.0f, -30.0f } },
|
||||
/* Candidate W6NL: 32 positive E4M3-exact magnitudes followed by their negatives. Fitted
|
||||
* to group-64 absmax-normalised FWHT-128 BF16 Flash-Next down-weight samples. This is a
|
||||
* weight-error pilot, not a claim of improved model quality. The high code bit is the
|
||||
* sign, and libr4d's layout verifies this complete table before serving it. */
|
||||
{ "w6nl", { 0.875f, 2.75f, 4.5f, 6.0f, 6.5f, 7.0f, 7.5f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
|
||||
18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, 30.0f, 32.0f,
|
||||
36.0f, 40.0f, 44.0f, 48.0f, 52.0f, 56.0f, 60.0f, 64.0f,
|
||||
-0.875f, -2.75f, -4.5f, -6.0f, -6.5f, -7.0f, -7.5f, -8.0f,
|
||||
-9.0f, -10.0f, -11.0f, -12.0f, -13.0f, -14.0f, -15.0f, -16.0f,
|
||||
-18.0f, -20.0f, -22.0f, -24.0f, -26.0f, -28.0f, -30.0f, -32.0f,
|
||||
-36.0f, -40.0f, -44.0f, -48.0f, -52.0f, -56.0f, -60.0f, -64.0f } },
|
||||
/* A one-bit weight: a sign and the block's scale. */
|
||||
{ "binary", { -1.0f, 1.0f } },
|
||||
/* BitNet's ternary weight, a two-bit code with one code unused. */
|
||||
@@ -117,7 +129,7 @@ bool parse_table(const char* s, std::vector<float>* out, std::string* why) {
|
||||
char* end = nullptr;
|
||||
const float v = std::strtof(p, &end);
|
||||
if (end == p || !std::isfinite(v)) {
|
||||
if (why) *why = fmt("table=%s is neither nf4, iq4nl, w4nl, w5nl, binary, ternary nor a "
|
||||
if (why) *why = fmt("table=%s is neither nf4, iq4nl, w4nl, w5nl, w6nl, binary, ternary nor a "
|
||||
"`;`-separated list of values", s);
|
||||
return false;
|
||||
}
|
||||
@@ -337,10 +349,15 @@ int grid_parse(const RadParam* o, int n_o, Grid* g, std::string* why) {
|
||||
}
|
||||
char line[4096];
|
||||
double unit = 0.0;
|
||||
int64_t rows = 0;
|
||||
while (std::fgets(line, sizeof line, f)) {
|
||||
if (line[0] == '#') {
|
||||
double u = 0.0;
|
||||
if (std::sscanf(line, "# unit %lf", &u) == 1) unit = u;
|
||||
/* %lf parses "inf", and the fallback guard below is `!(unit > 0.0)`, which an
|
||||
* infinite unit passes: an infinite scale unit would flow into quantisation
|
||||
* where a NaN already falls back. Only a finite positive names the unit. */
|
||||
if (std::sscanf(line, "# unit %lf", &u) == 1 && std::isfinite(u) && u > 0.0)
|
||||
unit = u;
|
||||
continue;
|
||||
}
|
||||
std::vector<float> row;
|
||||
@@ -353,6 +370,16 @@ int grid_parse(const RadParam* o, int n_o, Grid* g, std::string* why) {
|
||||
p = end;
|
||||
}
|
||||
if (row.empty()) continue;
|
||||
/* Capped while appending, as table= is: the widest code is u12, so more than 4096
|
||||
* codewords could not be indexed even with the memory read, and the file must be
|
||||
* refused without first growing a vector over every line of it. */
|
||||
if (++rows > 4096) {
|
||||
std::fclose(f);
|
||||
if (why)
|
||||
*why = fmt("vq=%s holds more than 4096 codewords; a codebook holds at most 4096",
|
||||
vf);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (g->vdim == 0) g->vdim = (int64_t)row.size();
|
||||
bool ok = (int64_t)row.size() == g->vdim;
|
||||
for (float v : row) ok = ok && v >= -127.0f && v <= 127.0f;
|
||||
@@ -453,7 +480,9 @@ int grid_parse(const RadParam* o, int n_o, Grid* g, std::string* why) {
|
||||
char rest[256] = {};
|
||||
if (!std::fgets(rest, sizeof rest, f)) break;
|
||||
double u = 0.0;
|
||||
if (std::sscanf(rest, " unit %lf", &u) == 1) lut_unit = u;
|
||||
if (std::sscanf(rest, " unit %lf", &u) == 1)
|
||||
lut_unit = (std::isfinite(u) && u > 0.0) ? u : 0.0; // like vq=: only a
|
||||
// finite positive names a unit; "inf"/"nan" fall back to the entries' rms
|
||||
continue;
|
||||
}
|
||||
v = std::strtol(tok, nullptr, 10);
|
||||
@@ -470,8 +499,16 @@ int grid_parse(const RadParam* o, int n_o, Grid* g, std::string* why) {
|
||||
}
|
||||
double ss = 0.0;
|
||||
for (float v2 : g->tcq_lut) ss += (double)v2 * v2;
|
||||
g->vq_unit = (lut_unit > 0.0 ? lut_unit : std::sqrt(ss / (double)S)) /
|
||||
rad_param_getf(o, n_o, "tcq_gain", 1.0);
|
||||
const double gain = rad_param_getf(o, n_o, "tcq_gain", 1.0);
|
||||
if (!(gain > 0.0) || !std::isfinite(gain)) {
|
||||
if (why) *why = "tcq_gain must be a positive finite number";
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
g->vq_unit = (lut_unit > 0.0 ? lut_unit : std::sqrt(ss / (double)S)) / gain;
|
||||
if (!std::isfinite(g->vq_unit)) {
|
||||
if (why) *why = "the tcq unit is not finite; check tcq_lut's values";
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (rad_param_geti(o, n_o, "tcq_peak", 0))
|
||||
for (float v2 : g->tcq_lut) g->tcq_peak = std::max(g->tcq_peak, std::fabs(v2));
|
||||
g->tcq_rb = rad_param_geti(o, n_o, "tcq_rb", 0);
|
||||
@@ -1387,6 +1424,11 @@ Scales grid_scales(const Grid& g, const float* w, int64_t rows, int64_t cols, co
|
||||
} else {
|
||||
s2r[k] = round_nz(g.scale2_dt, v);
|
||||
s.s2[k] = round_nz(g.scale2_dt, s2r[k] * resid);
|
||||
/* An integer first level cannot pass its top, so a second level that rounded down
|
||||
* takes the next value up: the largest scale under it then still fits. */
|
||||
if (g.l1_int)
|
||||
for (float up = 0x1p-12f; up < 0.5f && s.s2[k] / resid * g.l1max < peak[k]; up *= 2.0f)
|
||||
s.s2[k] = round_nz(g.scale2_dt, s2r[k] * resid * (1.0f + up));
|
||||
}
|
||||
/* As for a first level alone (store_first_level): the first level is taken relative to
|
||||
* what the reader multiplies by, which is N times the stored second level. */
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
* table=T a scalar codebook: each code indexes a table of values, which a block's scale
|
||||
* multiplies. nf4 (QLoRA's NormalFloat), iq4nl (llama.cpp's IQ4_NL values),
|
||||
* w4nl (the rotated expert grid libr4d's w4nla8h kernel decodes), w5nl (its
|
||||
* 32-level form, libr4d's w5nl64a8h),
|
||||
* 32-level form, libr4d's w5nl64a8h), w6nl (the 64-level candidate),
|
||||
* binary {-1, +1}, ternary {-1, 0, +1}, or the values themselves, `;`-separated.
|
||||
* The codes are the narrowest unsigned width that indexes it.
|
||||
* group=N one scale per N columns of a row -- block [1 x N]
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
"code dtype: i2..i8, i16, i32 (signed, symmetric), u1..u8, u16 with zero= (asymmetric), " \
|
||||
"fp8_e4m3, fp8_e5m2, fp6_e2m3, fp6_e3m2, fp4_e2m1" }, \
|
||||
{ "table", RAD_P_STR, nullptr, \
|
||||
"a codebook the codes index: nf4, iq4nl, w4nl, w5nl, binary, ternary, or values " \
|
||||
"a codebook the codes index: nf4, iq4nl, w4nl, w5nl, w6nl, binary, ternary, or values " \
|
||||
"separated by ;" }, \
|
||||
{ "vq", RAD_P_STR, nullptr, \
|
||||
"a vector codebook file: one codeword a line, its integers (-127..127) separated by " \
|
||||
|
||||
@@ -176,6 +176,11 @@ int gptq_quantize(const RadParam* o, int n_o, const RadQuantWeight* w, float* sr
|
||||
if (tord) uf = gptq_factor_ordered(dir, w->name, K, g.fwht, damp, &perm);
|
||||
else if (act) perm = gptq_act_order(dir, w->name, K, g.fwht);
|
||||
if (act || tord) {
|
||||
/* A weight with no recording has no order to take: its columns stay in their own. */
|
||||
if ((int64_t)perm.size() != K) {
|
||||
perm.resize((size_t)K);
|
||||
for (int64_t j = 0; j < K; ++j) perm[(size_t)j] = (int32_t)j;
|
||||
}
|
||||
permute(src, false);
|
||||
if (imp) {
|
||||
imp_p.resize((size_t)K);
|
||||
|
||||
Reference in new issue
Block a user