radiance 1.2.2

- Static YaRN for the Qwen rotary paths (#37): a container whose config names YaRN gets it in
  attention, the QSA index keys and a DFlash2 drafter; one reader for every rotary type, and a
  LLaMA container whose type is not served (llama3, longrope, dynamic) is refused by name.
- --rope-scaling yarn:FACTOR[:ORIG] (#38) writes YaRN over a container's own rotary keys at load,
  no reconvert; the persisted prefix cache's fingerprint carries the resolved rotary.
- An uneven world's cheaper rank (#36) pages the common token count and gives the rest of its
  VRAM to its experts; a plan and pool that disagree refuse to start.
- MoE prefill (#35): wide gather, parallel scan and run-map prefix, 256-column down tile, early
  weight loads -- by rule, bit-identical.
- MoE decode (#34): the sorted operand's own down kernel, its column tiles by routed rows.
- --draft-window fixed|adaptive (#24): a per-sequence draft window priced by measured step time,
  one head depth per step over the batch; fixed stays the default. New metric
  radiance:draft_position_accepted_total and Grafana panels.
- Out-of-tree plugin builds compile to the tree's device code from any build directory.
This commit is contained in:
Deadcode committed 2026-10-07 12:37:53 +02:00
1 parent 6fa7707dff
commit ac79f4dc8a
63 files changed
+2744 -8759

No files matched your search

+46 -2
View File
@@ -253,7 +253,10 @@ int meta_from_config_json(const std::string& dir, MetaOwn* out) {
m.n_expert_shared = gi("shared_expert_intermediate_size", 0) ? 1 : 0;
m.rms_eps = (float)gf("rms_norm_eps", 1e-6);
m.rope_theta = (float)gf("rope_parameters.rope_theta", gf("rope_theta", 10000.0));
m.rope_scale = (float)gf("rope_scaling.factor", 1.0);
/* The rotary's scaling stays in the free-form keys with its type beside it; the architecture
* reads both (arch/common/rad_arch.h, yarn_from). A factor copied here without its type would
* be a linear position divide for llama3, longrope or YaRN. */
m.rope_scale = 1.0f;
/* The quantisation descriptor, which with the architecture selects the plugin (spec §2.4).
* "fp8" plus its format, so qwen35_fp8 and qwen35_bf16 are told apart by the checkpoint
@@ -300,7 +303,48 @@ int meta_from_gguf(GgufFile& g, MetaOwn* out) {
m.n_expert_shared= gi("expert_shared_count", 0);
m.rms_eps = (float)gf("attention.layer_norm_rms_epsilon", 1e-6);
m.rope_theta = (float)gf("rope.freq_base", 10000.0);
m.rope_scale = (float)gf("rope.scaling.factor", 1.0);
m.rope_scale = 1.0f;
/* THE ROTARY'S SCALING, written as the config.json keys a safetensors release carries, because
* those are what the architecture reads (arch/common/rad_arch.h, yarn_from) -- one reader, so
* a type is refused or honoured by name whichever file it came from. llama.cpp's YaRN
* attn_factor, ext_factor and log multiplier modify the magnitude and ramp in ways config.json
* has no spelling for, so a file that sets one to anything but its neutral value is refused
* here rather than served as plain YaRN. */
{
/* llama.cpp's reading: the type defaults to linear, the factor is rope.scaling.factor or
* the older rope.scale_linear, and 0 or 1 is no scaling. */
std::string type = "linear";
g.get_str(a + ".rope.scaling.type", &type);
const double factor = gf("rope.scaling.factor", gf("rope.scale_linear", 0.0));
const bool none = type == "none" || (type == "linear" && (factor == 0.0 || factor == 1.0));
if (!none) {
const struct { const char* key; double neutral; } kOff[] = {
{ "rope.scaling.attn_factor", 1.0 }, { "rope.scaling.yarn_attn_factor", 1.0 },
{ "rope.scaling.yarn_log_multiplier", 0.0 } };
for (const auto& k : kOff)
if (gf(k.key, k.neutral) != k.neutral) {
RAD_ERR("the GGUF sets %s.%s = %g; that modifier of the rotary's scaling is "
"not implemented", a.c_str(), k.key, gf(k.key, k.neutral));
return RAD_E_UNSUPPORTED;
}
const double ext = gf("rope.scaling.yarn_ext_factor", -1.0);
if (ext >= 0.0 && ext != 1.0) {
RAD_ERR("the GGUF sets %s.rope.scaling.yarn_ext_factor = %g; YaRN is implemented "
"at extrapolation factor 1", a.c_str(), ext);
return RAD_E_UNSUPPORTED;
}
out->kv("rope_scaling.type", type);
if (factor != 0.0) out->kv("rope_scaling.factor", fmt("%.17g", factor));
const int64_t orig = gi("rope.scaling.original_context_length", 0);
if (orig > 0) out->kv("rope_scaling.original_max_position_embeddings",
fmt("%lld", (long long)orig));
for (const char* beta : { "beta_fast", "beta_slow" }) {
const double v = gf((std::string("rope.scaling.yarn_") + beta).c_str(), 0.0);
if (v != 0.0) out->kv(std::string("rope_scaling.") + beta, fmt("%.17g", v));
}
}
}
std::vector<std::string> toks;
if (g.get_strs("tokenizer.ggml.tokens", &toks)) m.n_vocab = (int64_t)toks.size();
+33 -1
View File
@@ -16,6 +16,7 @@
* (tests/yarn_test.cpp holds them to yarn_from). */
#pragma once
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
@@ -141,7 +142,8 @@ inline bool rope_override_group(std::vector<std::string>& k, std::vector<std::st
if (type == "yarn") kv.set(tk, "default");
return true;
}
if (!type.empty() && type != "default" && type != "yarn") {
/* `mrope` is the legacy Qwen2-VL spelling of default with sections. */
if (!type.empty() && type != "default" && type != "mrope" && type != "yarn") {
*why = "the " + std::string(*group ? "drafter's" : "model's") + " rotary is '" + type +
"' (" + tk + "); YaRN over it is not --rope-scaling's to decide";
return false;
@@ -174,4 +176,34 @@ inline bool rope_override_group(std::vector<std::string>& k, std::vector<std::st
return true;
}
/* THE ROTARY AS A CACHED KEY DEPENDS ON IT: every key with a path component naming `rope` or
* `rotary` -- rope_parameters.*, rope_scaling.*, rope_theta, partial_rotary_factor, their
* text_config. and draft. forms, a GGUF's <arch>.rope.* -- as key=value, sorted, after
* --rope-scaling has been applied. A persisted prefix store is fingerprinted with it: a container
* converted from the same checkpoint with YaRN has the same name and the same shapes, and its
* stock-rotated keys (and QSA block keys) read back under YaRN would be attended to at the wrong
* angles. Key order and unrelated keys do not change it. */
inline std::string rope_identity(const std::vector<std::string>& k,
const std::vector<std::string>& v) {
auto names_rotary = [](const std::string& key) {
size_t s = 0;
while (s <= key.size()) {
size_t e = key.find('.', s);
if (e == std::string::npos) e = key.size();
const std::string part = key.substr(s, e - s);
if (part.find("rope") != std::string::npos || part.find("rotary") != std::string::npos)
return true;
s = e + 1;
}
return false;
};
std::vector<std::string> rows;
for (size_t i = 0; i < k.size() && i < v.size(); ++i)
if (names_rotary(k[i])) rows.push_back(k[i] + "=" + v[i]);
std::sort(rows.begin(), rows.end());
std::string out;
for (const auto& r : rows) { out += r; out += ';'; }
return out;
}
} /* namespace rad */