Files
Deadcode 3b13fd3266 radiance 2.3.0
New models. Thinking Machines' Inkling 2 Mini by gostar (#584-#586): its text backbone and loop, the
release's NVFP4 and MXFP8 checkpoint read by the converter, an int8 trunk, the vision tower, tensor
parallelism, tool calls (with Warzuponus) and an image processor that matches transformers bit for
bit (millaguie). Inkling's routed experts are served in IQR-V4's four-bit trellis (moe_gemm_iqr),
fitted by GPTQ against Hessians the plugin now records (`--calib-dir`), its token embedding in int8
(read in place by embed_lookup), and incoai's DFlash2 drafter in four bits in place of the release's
DSpark. That container, 14.4 GiB with the vision tower, decodes 190 / 427 / 658 tokens a second at 1
/ 4 / 8 streams at tp 2 on two R9700 with `draft-window: adaptive` (code 240 / 550 / 790,
step-by-step arithmetic 358 / 811 / 1116): 19-43% ahead of the same target with the release's DSpark
drafter and 45-83% ahead of the all-int8 container (26.1 GiB, 124 / 263 / 386), at a mean KL of
0.0066 against the release's weights (int8: 0.0042). DeepSeek-V4.1-Flash on 2.x by baKon (#583),
with its vision tower, its IQ1_S and IQ2_XXS containers and linears and experts served in
llama.cpp's own blocks; parts ported from mikoskinen/r9700-exact-serving by Dad_Vibes' fork.
GLM-5.3-Flash on 2.x with its IQR / IQ8R container, an int8 latent cache and four-card serving by
AnimusNull (#566). Gemma 4 dense on EXL3-V3 by keptn42 (#537), on the EXL3 dense rows and
qwen35_exl3 tensor parallelism by Hero422. NVIDIA's 2-bit Nemotron-3.5-Bolt-74B-A9B on one card by
keptn42 (#477). Wan 2.2 TI2V-5B text-to-video and first-frame video by rkcth (#535). LFM3-1.7B on
RDNA3 iGPUs by DokterSmol (#578). Qwen3.8-27B in bf16 with the DFlash2 drafter, and bf16x12, bf16
weights packed losslessly in 12.25 bits, by eddie168 (#577). Int8 experts for drama-3 by morevgalex
(#598).

Speculative decoding. Draft trees for Qwen3.8-27B's DFlash2 drafts by Kezi (#450, opt-in): one card,
+17% at one stream and +14% at two. --draft-max-lanes and --draft-min-accept, two gates on a block
drafter, and --draft-window-ckpt, its window KV kept in the checkpoint slots, by rkcth (#600-#602).
`draft-window: adaptive` verifies each sequence's drafts up to the first one unlikely to be kept. A
verify's rows share each K and V tile in Inkling's attention by gostar (#608): 93 to 118 tokens a
second at a 70k-token prompt on one card.

Generation. Krea 2 instruction edits with one or two references and registered outfill, LoRA on the
image generators with bias deltas and row-mixer adapters applied per request, and MiniMax-H3's
model-declared sparse attention profiles, by rkcth (#534, #542, #543, #605-#609). MiniMax-H3's audio
reference guide pinned from a frame by 1beb (#595). LTX-2's chunk ceiling raised to 40 by Itoash
(#570).

Fleets and memory. memory.queue-reserve, the hardware queues a card keeps ready, by kevinjd (#589).
memory.pinned-numa-node by Foundry (#580). memory.card-headroom-mib on single-model tensor-parallel
budgets by zihaomu (#624). Parked weights rebuilt on the CPU, memory ownership kept across a failed
handoff and quiescent callbacks serialised, by rkcth (#557-#561). A warm load may unload a parked
model (#592); the first card listed chooses the architecture (#458).

Kernels. libr3d's packed dense IQR GEMM and routed IQR expert rows on gfx1100, and libhalo's GEMV
decode for Qwen3.8-Flash-Next's MoE down, by zihaomu (#562, #620, #622). GGML IQ2_XXS and IQ3_XXS
packed on the card by baKon.

Dashboard. KV cache in tokens (in use, capacity now and with all flexible space), live figures
through long prefill steps, step / decode / prefill / acceptance lines without holes, and expert hit
rates only on tiered models. Seven tile and history defects fixed by Noblistic (#597), vision
encoder and per-card hardware figures by davetha (#574), per-LoRA attribution by dowjames (#552).

Fixed. return_tokens / return_token_ids on the OpenAI endpoints (#571). reasoning_effort "none" and
"minimal" reach a template that takes them as levels, by millaguie (#608). Misaligned loads in the
windowed paged attention over an int8 cache (#540). A retired 27B head refused by name (#541).
rad-convert's GPU trellis jobs kept fed, and --reuse-only, by gostar (#575). jinja's tojson takes
sort_keys by Warzuponus (#582). hfget measures file sizes with stat, by kepler_62f (#623). The
tested C++ compiler is stated in the build guide by lowell80 (#551). The codebase was cleaned up:
shared helpers instead of repeated blocks, and the int8 linear, activation and GEMM code no longer
named after the retired fp8 formats.

Inkling 2 Mini is served in one form: IQR-V4 experts with the DFlash2 drafter
(StillDeadcode/inkling-2-mini-iq4r-v4 on Hugging Face, or
data/recipes/inkling2-mini-iq4r-v4.recipe). A container with the release's DSpark drafter, or with
NVFP4, int8 or 4-bit experts, is refused by name and needs converting again.

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

Thanks to @gostar, @baKon, @Dad_Vibes, @AnimusNull, @keptn42, @Hero422, @rkcth, @DokterSmol,
@eddie168, @morevgalex, @Kezi, @1beb, @Itoash, @kevinjd, @Foundry, @zihaomu, @Noblistic, @davetha,
@dowjames, @Warzuponus, @millaguie, @kepler_62f, @lowell80 and @Code000.
2026-11-26 15:28:37 +01:00

218 lines
9.5 KiB
C++

/* lq_ggml.cpp -- the `ggml` quantiser: llama.cpp's formats, llama.cpp's codes, radiance's planes.
*
* A row is quantised by llama.cpp's own quantize_<type> (lq_ggml_port.h), with the imatrix's
* column importances as quant_weights, and the resulting GGUF blocks are unpacked into the affine
* planes of rad_encoding.h. A llama.cpp model and a radiance container quantised from the same
* weights and imatrix therefore hold the same numbers, but the container stores a generic encoding
* instead of a block layout tied to one kernel family.
*
*
* The planes each type writes, and the unpacking of a row's blocks into them, live in
* lq_ggml_planes.cpp, shared with the core's GGUF import.
*/
#include "lq_ggml.h"
#include "lq_ggml_planes.h"
#include "lq_ggml_port.h"
#include "lq_ggml_gpu.h"
#include "lq_quant.h"
#include "rad_plugin.h"
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
namespace lq {
namespace {
using namespace lq::ggml;
/* ================================================================== the types */
typedef size_t (*QuantizeFn)(const float*, void*, int64_t, int64_t, const float*);
struct Kind {
const char* name; /* as llama.cpp spells it */
ggml_type type;
int64_t block; /* values one GGUF block covers */
QuantizeFn quantize;
};
const Kind kKinds[] = {
{ "q4_0", GGML_TYPE_Q4_0, QK4_0, quantize_q4_0 },
{ "q4_1", GGML_TYPE_Q4_1, QK4_1, quantize_q4_1 },
{ "q5_0", GGML_TYPE_Q5_0, QK5_0, quantize_q5_0 },
{ "q5_1", GGML_TYPE_Q5_1, QK5_1, quantize_q5_1 },
{ "q8_0", GGML_TYPE_Q8_0, QK8_0, quantize_q8_0 },
{ "q2_K", GGML_TYPE_Q2_K, QK_K, quantize_q2_K },
{ "q3_K", GGML_TYPE_Q3_K, QK_K, quantize_q3_K },
{ "q4_K", GGML_TYPE_Q4_K, QK_K, quantize_q4_K },
{ "q5_K", GGML_TYPE_Q5_K, QK_K, quantize_q5_K },
{ "q6_K", GGML_TYPE_Q6_K, QK_K, quantize_q6_K },
{ "iq4_nl", GGML_TYPE_IQ4_NL, QK4_NL, quantize_iq4_nl },
{ "iq4_xs", GGML_TYPE_IQ4_XS, QK_K, quantize_iq4_xs },
{ "iq2_xxs", GGML_TYPE_IQ2_XXS, QK_K, quantize_iq2_xxs },
{ "iq2_xs", GGML_TYPE_IQ2_XS, QK_K, quantize_iq2_xs },
{ "iq2_s", GGML_TYPE_IQ2_S, QK_K, quantize_iq2_s },
{ "iq3_xxs", GGML_TYPE_IQ3_XXS, QK_K, quantize_iq3_xxs },
{ "iq3_s", GGML_TYPE_IQ3_S, QK_K, quantize_iq3_s },
{ "iq1_s", GGML_TYPE_IQ1_S, QK_K, quantize_iq1_s },
{ "iq1_m", GGML_TYPE_IQ1_M, QK_K, quantize_iq1_m },
};
/* ================================================================== the quantiser */
bool same_name(const char* a, const char* b) {
for (; *a && *b; ++a, ++b)
if (std::tolower((unsigned char)*a) != std::tolower((unsigned char)*b)) return false;
return *a == *b;
}
/* The type the options name, or RAD_E_INVAL with a message naming the weight. */
int kind_of(const RadParam* o, int n_o, const RadQuantWeight* w, const Kind** out) {
const char* t = rad_param_gets(o, n_o, "type", nullptr);
if (!t)
return refuse(w, "type= is required: the llama.cpp type to write, e.g. q4_K, q8_0, iq4_xs");
for (const Kind& k : kKinds)
if (same_name(t, k.name)) {
*out = &k;
return RAD_OK;
}
std::string all;
for (const Kind& k : kKinds) all += std::string(all.empty() ? "" : " ") + k.name;
return refuse(w, ("type=" + std::string(t) + " is not a llama.cpp type this quantiser writes (" +
all + ")").c_str());
}
/* A rank-1 weight, or one whose rows do not divide into the type's blocks, is declined so the next
* rule takes it (a norm, or a 2880-wide projection a q4_K pattern happened to match). */
int ggml_encoding(const RadParam* o, int n_o, const RadQuantWeight* w, RadEncoding* out) {
if (declines(w)) return RAD_E_UNSUPPORTED;
const Kind* k = nullptr;
const int st = kind_of(o, n_o, w, &k);
if (st != RAD_OK) return st;
if (w->cols <= 0 || w->rows <= 0) return RAD_E_SHAPE;
if (w->cols % k->block) return RAD_E_UNSUPPORTED;
*out = encoding_of(k->type);
return RAD_OK;
}
/* Rows are independent in every type: a block never spans rows, and the imatrix is per column. */
int64_t ggml_row_block(const RadParam*, int, const RadQuantWeight*) { return 1; }
/* Unpack a band of GGUF blocks the card wrote into the planes the host loop writes. */
static void unpack_gpu_blocks(const Kind* k, const RadEncoding& e, const int64_t* row_bytes,
const bool* per_row, const uint8_t* blocks, int64_t rsz,
int64_t rows, int64_t C, void* const* planes) {
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 1)
#endif
for (int64_t r = 0; r < rows; ++r) {
uint8_t* row[RAD_ENC_MAX_PLANES] = {};
for (int i = 0; i < e.n_planes; ++i)
if (per_row[i]) row[i] = (uint8_t*)planes[i] + r * row_bytes[i];
plane_kind((uint32_t)k->type)->unpack(blocks + r * rsz, C / k->block, row);
}
}
int ggml_quantize(const RadParam* o, int n_o, const RadQuantWeight* w, float* src, int64_t row0,
int64_t rows, void* const* planes) {
const Kind* k = nullptr;
const int st = kind_of(o, n_o, w, &k);
if (st != RAD_OK) return st;
if (!w || w->rank < 2 || w->cols <= 0 || w->rows <= 0 || w->cols % k->block || row0 < 0 ||
rows < 0 || row0 + rows > w->rows)
return RAD_E_SHAPE;
/* llama.cpp's iq2_xxs, iq2_xs and iq1_s require the imatrix and have no other path;
* substituting one would write, under llama.cpp's type name, data llama.cpp could not have
* produced. */
if (!w->importance && ggml_quantize_requires_imatrix(k->type))
return refuse(w, ("type=" + std::string(k->name) + " needs an imatrix, and the converter "
"has none for this weight (rad-convert --imatrix FILE)").c_str());
ggml_quantize_init(k->type);
const RadEncoding e = encoding_of(k->type);
const int64_t C = w->cols, nb = C / k->block;
int64_t row_bytes[RAD_ENC_MAX_PLANES] = {};
bool per_row[RAD_ENC_MAX_PLANES] = {};
for (int i = 0; i < e.n_planes; ++i) {
const RadEncPlane& p = e.plane[i];
int64_t pr = 0, pc = 0;
rad_enc_plane_dims(&p, w->rows, C, &pr, &pc);
row_bytes[i] = rad_enc_row_bytes(p.dtype, pc);
per_row[i] = p.kind == RAD_PLANE_TILED && p.block[0] == 1;
}
write_shared(k->type, e, planes);
const size_t rsz = ggml_row_size(k->type, C);
const float* imp = w->importance;
#if defined(LQ_CARD)
/* The card path is for the two GGML I types whose search is expensive and whose layouts this
* build has a tested kernel for. Small weights stay on the host: rad-convert already gives
* large weights a worker per card, and this keeps the many small-weight threads off the quiet
* cards. A card failure other than an unsupported shape is loud, so a broken kernel cannot
* silently become a different conversion. */
const bool gpu_rule = rad_param_geti(o, n_o, "gpu", 1) != 0;
const int64_t gpu_min = rad_param_geti(o, n_o, "gpu_min_bytes", (int64_t)32 << 20);
const bool gpu_big = w->rows * C * 4 >= gpu_min;
if (gpu_rule && gpu_big && (k->type == GGML_TYPE_IQ2_XXS || k->type == GGML_TYPE_IQ3_XXS) &&
ggml::gpu_available()) {
std::vector<uint8_t> gblocks((size_t)rows * rsz);
std::string why;
const int gs = ggml::quantize_gpu(k->type, src, gblocks.data(), rows, C, imp, &why);
if (gs == RAD_OK) {
unpack_gpu_blocks(k, e, row_bytes, per_row, gblocks.data(), (int64_t)rsz, rows, C,
planes);
return RAD_OK;
}
if (gs != RAD_E_UNSUPPORTED)
return refuse(w, why.empty() ? "the GGML card path failed" : why.c_str());
/* The card has no path for this shape or has no room: fall back to the host oracle. */
}
#endif
#ifdef _OPENMP
#pragma omp parallel
#endif
{
std::vector<uint8_t> blocks(rsz);
#ifdef _OPENMP
#pragma omp for schedule(dynamic, 1)
#endif
for (int64_t r = 0; r < rows; ++r) {
k->quantize(src + r * C, blocks.data(), 1, C, imp);
uint8_t* row[RAD_ENC_MAX_PLANES] = {};
for (int i = 0; i < e.n_planes; ++i)
if (per_row[i]) row[i] = (uint8_t*)planes[i] + r * row_bytes[i];
plane_kind((uint32_t)k->type)->unpack(blocks.data(), nb, row);
}
}
return RAD_OK;
}
const RadQuantOption kOptions[] = {
{ "type", RAD_P_STR, nullptr,
"the llama.cpp type, any case: q4_0 q4_1 q5_0 q5_1 q8_0 q2_K q3_K q4_K q5_K q6_K iq4_nl "
"iq4_xs iq2_xxs iq2_xs iq2_s iq3_xxs iq3_s iq1_s iq1_m. iq2_xxs, iq2_xs and iq1_s need an "
"imatrix" },
{ "gpu", RAD_P_INT, "1",
"0: keep this rule on the host even when --gpus names cards; 1: let large IQ2_XXS/IQ3_XXS "
"weights use one card. The host path remains the fallback for small or unsupported weights" },
{ "gpu_min_bytes", RAD_P_INT, "33554432",
"with gpu 1, the whole weight's f32 bytes from which it uses a card: the many small weights "
"stay on the host threads, the cards take the large ones. The same bytes either way" },
};
} /* namespace */
const RadQuantizerInfo ggml_quantizer = {
"ggml",
"llama.cpp's legacy, K- and I-quants, the codes and scales chosen by llama.cpp's own search "
"(with the imatrix when the converter has one) and stored as affine planes",
kOptions, (int)(sizeof kOptions / sizeof kOptions[0]),
ggml_encoding, ggml_row_block, ggml_quantize, nullptr,
};
} /* namespace lq */