core/format, tools: GGUF Q8_0, Q4_K and Q6_K tensors import as their planes -- rad-convert writes them without a recipe

A GGUF tensor of block type Q8_0, Q4_K or Q6_K could only be dequantised, so rad-convert reached it
through a recipe rule and re-quantised what was already quantised. ckpt_resolve now states the
planes libquant's ggml quantiser writes for the same blocks and marks the weight imported, and
ckpt_plane_rows splits each row's blocks into them bit for bit. The split is
core/format/ggml_planes.h, the reader's copy of lq_ggml's unpack functions, since the core cannot
call libquant; a type there is one table row, its planes and its split. Pieces of one block type
joined along rows import, an expert's slices of a stacked tensor included; mixed types and column
joins keep a GGUF reason.

The weight is not trivial, so the loader refuses it with the hint to serve the container
rad-convert writes, and ckpt_rows_f32 still dequantises it for a recipe. A rule that declines such
a weight is an error in rad-convert, since keeping its planes would hide that the rule did not
apply (spec.md §4.4).

Tests: quant_ggml_test holds every type of the reader's table to the quantiser's encoding,
checkpoint_test decodes the planes of Q8_0, Q4_K (one-block rows and a row join) and Q6_K against
the block definition and holds an expert's gate|up, two slices of stacked Q4_K tensors, to the same
blocks stored on their own, and convert_test runs a declining rule over a Q8_0 tensor, with the
GGUF writer moved to tests/gguf_writer.h for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-28 12:48:13 +01:00
1 parent 6f034d989f
commit 385318f81a
10 files changed
+602 -57

No files matched your search

+44
View File
@@ -6,6 +6,7 @@
* checkpoint holds them, so one conversion writes a quantised and a copied weight of every kind.
*/
#include "rad_test.h"
#include "gguf_writer.h"
#include "tiny_model.h"
#include "format/encoding.h"
@@ -756,6 +757,49 @@ TEST(a_recipe_or_flag_that_cannot_be_honoured_is_refused_before_writing) {
}
}
/* A rule that declines a GGUF block tensor stops the run rather than keep the tensor's planes: the
* tiny LLaMA as a GGUF with its first attn_norm in Q8_0, under an `rtn` rule, which declines a
* rank-1 tensor. */
TEST(a_rule_that_declines_a_gguf_block_tensor_is_an_error) {
World& w = world();
REQUIRE(w.ok);
tiny::TempDir d("convert_gguf");
const tiny::Llama s;
const std::vector<ggufw::GKv> kvs = {
{ "general.architecture", 8, 0, { "llama" } },
{ "llama.block_count", 4, (double)s.layers, {} },
{ "llama.embedding_length", 4, (double)s.hidden, {} },
{ "llama.attention.head_count", 4, (double)s.heads, {} },
{ "llama.attention.head_count_kv", 4, (double)s.kv_heads, {} },
{ "llama.attention.key_length", 4, (double)s.head_dim, {} },
{ "llama.feed_forward_length", 4, (double)s.ffn, {} },
{ "llama.context_length", 4, (double)s.ctx, {} },
{ "llama.vocab_size", 4, (double)s.vocab, {} },
};
std::vector<ggufw::GTensor> ts;
for (const auto& [name, t] : w.src) {
ggufw::GTensor g{ name, t.dtype == "F32" ? 0u : 30u, {}, t.bytes };
g.ne.assign(t.shape.rbegin(), t.shape.rend());
if (name == "model.layers.0.input_layernorm.weight") {
g.type = 8;
g.bytes.clear();
for (uint64_t b = 0; b < g.ne[0] / 32; ++b) {
g.bytes.insert(g.bytes.end(), { 0x00, 0x3C }); /* d = 1 in f16 */
g.bytes.insert(g.bytes.end(), 32, 1);
}
}
ts.push_back(std::move(g));
}
REQUIRE(ggufw::write_gguf(d / "llama.gguf", kvs, ts));
std::string log;
CHECK(convert(d / "llama.gguf",
{ "-o", d / "g.rad", "--recipe", w.recipe, "--quant",
"blk.0.attn_norm.weight=rtn:codes=i8,group=32,scale=bf16" },
&log) != 0);
CHECK(has(log, "(rtn) refuses it"));
CHECK(!exists(d / "g.rad"));
}
/* ================================================================== an int4 release */
namespace {