Archived
radiance 1.13.0
New models: - Tencent Hy-Memory (HYV3) from its BF16, FP8 and GGUF checkpoints, with its native tool calls - M2XFP4: metadata-augmented MXFP4 weights for Qwen3.8-27B and its DFlash2 drafter (top-1 89.1% -> 92.4% against plain MXFP4), its quantiser and recipe, and ParoQuant's M2XFP4 checkpoints - Gemma 4 E2B/E4B audio input; NVIDIA-Nemotron-3.5-Bolt-E4B in int8 and 4-bit, on two cards by default; Ornith-1.5-122B compose files Speed: - Weight reads beside the decode all-reduces (qwen35_fp8, gemma3; --weight-prefetch, on by default): the 27B MXFP4 with DFlash2 61.2 -> 67.9 tok/s at c1, TranslateGemma 27B +13% - Head-256 split-KV decode attention at 256 workgroups and without bank conflicts (27B: +3-5% a step at 25-41K context), and the prefill KV split for small launches (a short turn over a long context decodes the other sequences 27% faster in that step) - MXFP4 decode gate_up, activation and fp8 quantiser in one launch (27B, Gemma 3 up to 64 rows: TranslateGemma +2-5% at 2-8 streams) - ParoQuant int4/int5 tiled GEMMs 6-9% faster - Speculation: a step's tokens are sent before the drafter's passes end, no step waits behind one that ends its requests, and the MTP head's first draft no longer collapses after short chats in the prefix cache Features: - --kv-resident N: KV streaming for a context bigger than VRAM (qwen4exp_fp8, GLM-5.3) - MiniMax-H3: reference media and keyframe conditioning with the VAE encoders - Krea 2 rebalance presets balanced, detail and subtle - The dashboard's request history; a stall watch that reports a frozen step's thread and stack - rad-tune at the served configuration, collectives measured as the exchange; Gemma 4 E2B/E4B's per-layer embeddings read ahead off the step path - A GPTQ calibration tap and recipe for Gemma 4 31B's w4a8 container Fixes: - The two-rank all-reduce checks that a peer's push has landed before reducing it - z-lab's DFlash drafter on Gemma 4 31B keeps drafting after a prefix-cache hit - MiniMax-H3's modulation rows Changes: Plugin ABI 31: out-of-tree plugins must be rebuilt. RADIANCE_PREFETCH_BESIDE is --weight-prefetch now; RADIANCE_NO_HUGE_PAGES, RADIANCE_IDS_EARLY, RADIANCE_ATTN_BAND_SPLIT, R4D_PREFILL_SPLITS, RAD_PLE_TIMING and RAD_PLE_CACHE_ROWS are gone.
This commit is contained in:
commit
6645337f69
198 files changed
+20904
-3240
No files matched your search
@@ -1639,6 +1639,281 @@ int Checkpoint::add_draft(const std::string& dir, const std::string& prefix) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* PEFT exports wrap HF module paths in the name of the net the adapter trained: ai-toolkit spells
|
||||
* a DiT module `diffusion_model.<path>`, diffusers' wrappers `transformer.` or `unet.`. */
|
||||
static const char* const kLoraPrefixes[] = { "diffusion_model.", "transformer.", "unet." };
|
||||
|
||||
/* One `modules` rule of the map: the module pattern split at its single `*`, and the target
|
||||
* patterns into which the matched run is substituted, in B-row order. */
|
||||
struct LoraRule {
|
||||
bool star = false;
|
||||
std::string pre, suf;
|
||||
std::vector<std::string> targets;
|
||||
bool match(const std::string& m, std::string* tok) const {
|
||||
if (!star) {
|
||||
if (m != pre) return false;
|
||||
tok->clear();
|
||||
return true;
|
||||
}
|
||||
if (m.size() < pre.size() + suf.size() || m.compare(0, pre.size(), pre) != 0) return false;
|
||||
if (m.compare(m.size() - suf.size(), suf.size(), suf) != 0) return false;
|
||||
*tok = m.substr(pre.size(), m.size() - pre.size() - suf.size());
|
||||
return !tok->empty();
|
||||
}
|
||||
};
|
||||
|
||||
/* Read the map file: {"strip": [...], "modules": {"<pat>": ["<t>", ...], ...}}. The module
|
||||
* order is preserved (an nlohmann object keeps insertion order), so the first rule whose
|
||||
* pattern matches a module wins. */
|
||||
static int lora_map_read(const std::string& file, std::vector<std::string>* strip,
|
||||
std::vector<LoraRule>* rules) {
|
||||
std::ifstream f(file);
|
||||
if (!f) { RAD_ERR("lora: --lora-map %s cannot be read", file.c_str()); return RAD_E_NOTFOUND; }
|
||||
nlohmann::ordered_json j;
|
||||
try {
|
||||
j = nlohmann::ordered_json::parse(f);
|
||||
} catch (const std::exception& e) {
|
||||
RAD_ERR("lora: --lora-map %s: %s", file.c_str(), e.what());
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
if (!j.is_object()) { RAD_ERR("lora: --lora-map %s is not a JSON object", file.c_str());
|
||||
return RAD_E_FORMAT; }
|
||||
if (j.contains("strip")) {
|
||||
if (!j["strip"].is_array()) { RAD_ERR("lora: --lora-map 'strip' is not a list");
|
||||
return RAD_E_FORMAT; }
|
||||
for (const auto& s : j["strip"]) {
|
||||
if (!s.is_string()) { RAD_ERR("lora: --lora-map 'strip' holds a non-string");
|
||||
return RAD_E_FORMAT; }
|
||||
strip->push_back(s.get<std::string>());
|
||||
}
|
||||
}
|
||||
if (!j.contains("modules") || !j["modules"].is_object()) {
|
||||
RAD_ERR("lora: --lora-map %s has no 'modules' object", file.c_str());
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
for (const auto& [pat, t] : j["modules"].items()) {
|
||||
if (!t.is_array() || t.empty()) {
|
||||
RAD_ERR("lora: --lora-map rule '%s' is not a non-empty list", pat.c_str());
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
const size_t star = pat.find('*');
|
||||
LoraRule r;
|
||||
r.star = star != std::string::npos;
|
||||
r.pre = r.star ? pat.substr(0, star) : pat;
|
||||
r.suf = r.star ? pat.substr(star + 1) : "";
|
||||
for (const auto& x : t) {
|
||||
if (!x.is_string()) {
|
||||
RAD_ERR("lora: --lora-map rule '%s' holds a non-string target", pat.c_str());
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
r.targets.push_back(x.get<std::string>());
|
||||
}
|
||||
rules->push_back(std::move(r));
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int Checkpoint::add_lora(const std::string& path, double strength,
|
||||
std::vector<std::string>* merged, const std::string* map_json) {
|
||||
if (kind_ != SafeT) {
|
||||
RAD_ERR("lora: an adapter merges into a safetensors source; %s is not one", path_.c_str());
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
if (import_ != Import::None) {
|
||||
RAD_ERR("lora: this checkpoint ships its weights packed by a quantiser; an adapter merges "
|
||||
"into the plain tensors its training saw, not into the codes");
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
std::vector<std::string> files;
|
||||
std::error_code ec;
|
||||
if (std::filesystem::is_directory(path, ec)) {
|
||||
for (const auto& e : std::filesystem::directory_iterator(path, ec))
|
||||
if (e.path().extension() == ".safetensors") files.push_back(e.path().string());
|
||||
std::sort(files.begin(), files.end());
|
||||
} else
|
||||
files.push_back(path);
|
||||
if (files.empty()) {
|
||||
RAD_ERR("lora: %s holds no .safetensors file", path.c_str());
|
||||
return RAD_E_NOTFOUND;
|
||||
}
|
||||
|
||||
/* The module lookup strips wrapper prefixes: the map's first, then the builtin ones. */
|
||||
std::vector<std::string> strips;
|
||||
std::vector<LoraRule> rules;
|
||||
if (map_json && lora_map_read(*map_json, &strips, &rules) < 0) return RAD_E_FORMAT;
|
||||
for (const char* pre : kLoraPrefixes) strips.push_back(pre);
|
||||
|
||||
/* One pair's A/B/alpha, by module; `module` keeps the wrapper prefix, so the lookup below
|
||||
* strips it. */
|
||||
struct Pair { std::string module; const StTensor *a = nullptr, *b = nullptr, *al = nullptr; };
|
||||
|
||||
int n_merged = 0;
|
||||
for (const std::string& f : files) {
|
||||
SafeTensorsFile st;
|
||||
if (st.open(f) != RAD_OK) return RAD_E_FORMAT;
|
||||
std::vector<Pair> pairs;
|
||||
std::map<std::string, size_t> by_module;
|
||||
for (const StTensor& t : st.tensors()) {
|
||||
if (t.name.size() > 12 && t.name.compare(t.name.size() - 12, 12, ".dora.scalar") == 0) {
|
||||
RAD_ERR("lora: '%s' is a DoRA adapter; only plain LoRA merges (a magnitude vector "
|
||||
"has no place in a weight merge)", t.name.c_str());
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
const char* suf = nullptr;
|
||||
if (t.name.size() > 14 && t.name.compare(t.name.size() - 14, 14, ".lora_A.weight") == 0)
|
||||
suf = ".lora_A.weight";
|
||||
else if (t.name.size() > 18 &&
|
||||
t.name.compare(t.name.size() - 18, 18, ".lora_down.weight") == 0)
|
||||
suf = ".lora_down.weight";
|
||||
if (suf) {
|
||||
Pair p;
|
||||
p.module = t.name.substr(0, t.name.size() - std::strlen(suf));
|
||||
p.a = &t;
|
||||
by_module[p.module] = pairs.size();
|
||||
pairs.push_back(std::move(p));
|
||||
} else if (t.name.size() > 14 &&
|
||||
t.name.compare(t.name.size() - 14, 14, ".lora_B.weight") == 0) {
|
||||
auto it = by_module.find(t.name.substr(0, t.name.size() - 14));
|
||||
if (it != by_module.end()) pairs[it->second].b = &t;
|
||||
} else if (t.name.size() > 6 &&
|
||||
t.name.compare(t.name.size() - 6, 6, ".alpha") == 0) {
|
||||
auto it = by_module.find(t.name.substr(0, t.name.size() - 6));
|
||||
if (it != by_module.end()) pairs[it->second].al = &t;
|
||||
}
|
||||
}
|
||||
if (pairs.empty()) {
|
||||
RAD_ERR("lora: %s holds no .lora_A.weight / .lora_down.weight tensors", f.c_str());
|
||||
return RAD_E_NOTFOUND;
|
||||
}
|
||||
for (Pair& p : pairs) {
|
||||
if (!p.b) {
|
||||
RAD_ERR("lora: '%s' ships its A but no B", p.module.c_str());
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
/* The targets: `<module>.weight`, else the same with a wrapper prefix stripped, else
|
||||
* the tensors the first map rule the stripped module matches names. */
|
||||
std::string norm = p.module;
|
||||
for (const std::string& s : strips)
|
||||
if (norm.size() > s.size() && norm.compare(0, s.size(), s) == 0) {
|
||||
norm.erase(0, s.size());
|
||||
break;
|
||||
}
|
||||
std::vector<const SrcTensor*> tg;
|
||||
if (const SrcTensor* W = find(p.module + ".weight")) tg.push_back(W);
|
||||
if (tg.empty() && norm != p.module)
|
||||
if (const SrcTensor* W = find(norm + ".weight")) tg.push_back(W);
|
||||
for (const LoraRule& ru : rules) {
|
||||
std::string tok;
|
||||
if (!ru.match(norm, &tok)) continue;
|
||||
for (const std::string& pat : ru.targets) {
|
||||
std::string nm = pat;
|
||||
const size_t star = nm.find('*');
|
||||
if (star != std::string::npos) nm.replace(star, 1, tok);
|
||||
const SrcTensor* W = find(nm);
|
||||
if (!W) {
|
||||
RAD_ERR("lora: the map maps '%s' onto '%s', which this checkpoint does "
|
||||
"not ship", p.module.c_str(), nm.c_str());
|
||||
return RAD_E_NOTFOUND;
|
||||
}
|
||||
tg.push_back(W);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (tg.empty()) {
|
||||
RAD_ERR("lora: '%s' names a module this checkpoint does not ship as "
|
||||
"'<module>.weight' (nor stripped of a known wrapper prefix)%s",
|
||||
p.module.c_str(),
|
||||
map_json ? " and no --lora-map rule matches it" : "");
|
||||
return RAD_E_NOTFOUND;
|
||||
}
|
||||
const StTensor& A = *p.a;
|
||||
const StTensor& B = *p.b;
|
||||
if (A.shape.size() != 2 || B.shape.size() != 2 || A.shape[0] <= 0 ||
|
||||
A.shape[0] != B.shape[1]) {
|
||||
RAD_ERR("lora: '%s' is not a rank-%lld pair of matrices: [a %lld x %lld, "
|
||||
"b %lld x %lld]",
|
||||
p.module.c_str(), (long long)A.shape[0], (long long)A.shape[0],
|
||||
(long long)A.shape[1], (long long)B.shape[0], (long long)B.shape[1]);
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
const auto plain = [](uint32_t d) {
|
||||
return d == RAD_BF16 || d == RAD_F16 || d == RAD_F32;
|
||||
};
|
||||
if (!plain(A.dtype) || !plain(B.dtype)) {
|
||||
RAD_ERR("lora: '%s' ships A/B in dtypes the merge cannot read", p.module.c_str());
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
const int64_t K = A.shape[1], r = A.shape[0];
|
||||
int64_t rows = 0;
|
||||
for (const SrcTensor* W : tg) {
|
||||
if (W->gptq_bits || W->ct_group || W->rad_dtype == RAD_DT_INVALID ||
|
||||
!plain(W->rad_dtype)) {
|
||||
RAD_ERR("lora: '%s' is not a plain bf16/f16/f32 matrix, so an adapter cannot "
|
||||
"merge into it", W->name.c_str());
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
if (W->shape.size() != 2 || W->shape[1] != K) {
|
||||
RAD_ERR("lora: '%s' [a %lld x %lld, b %lld x %lld] does not fit '%s' "
|
||||
"[%lld x %lld]",
|
||||
p.module.c_str(), (long long)A.shape[0], (long long)A.shape[1],
|
||||
(long long)B.shape[0], (long long)B.shape[1], W->name.c_str(),
|
||||
(long long)W->shape[0], (long long)W->shape[1]);
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
rows += W->shape[0];
|
||||
}
|
||||
if (rows != B.shape[0]) {
|
||||
RAD_ERR("lora: '%s' merges into %zu target(s) whose rows sum to %lld, but its B "
|
||||
"has %lld", p.module.c_str(), tg.size(), (long long)rows,
|
||||
(long long)B.shape[0]);
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
float scale = (float)strength;
|
||||
if (p.al) {
|
||||
const int64_t n_el = p.al->shape.empty() ? 1 : p.al->numel();
|
||||
if (n_el != 1 || (p.al->dtype != RAD_F32 && p.al->dtype != RAD_BF16 &&
|
||||
p.al->dtype != RAD_F16)) {
|
||||
RAD_ERR("lora: '%s.alpha' is not a single number", p.module.c_str());
|
||||
return RAD_E_FORMAT;
|
||||
}
|
||||
scale *= rad_load_f32(p.al->data, p.al->dtype, 0) / (float)r;
|
||||
}
|
||||
/* The module is the targets' concatenation: target i takes B's rows [off, off + N_i).
|
||||
* A row at a time, rank-1 updates into an f32 row, with A taken to f32 once a pair so
|
||||
* the sweep reads plain f32 (a dtype switch an element is hours on a large adapter). */
|
||||
std::vector<float> Af((size_t)(r * K));
|
||||
for (int64_t i = 0; i < r * K; ++i) Af[(size_t)i] = rad_load_f32(A.data, A.dtype, i);
|
||||
std::vector<float> acc((size_t)K);
|
||||
int64_t off = 0;
|
||||
for (const SrcTensor* W : tg) {
|
||||
const int64_t N = W->shape[0];
|
||||
auto out = std::make_unique<uint8_t[]>((size_t)W->bytes);
|
||||
for (int64_t n = 0; n < N; ++n) {
|
||||
for (int64_t j = 0; j < r; ++j) {
|
||||
const float b = scale * rad_load_f32(B.data, B.dtype, (off + n) * r + j);
|
||||
if (b == 0.f) continue;
|
||||
const float* ar = Af.data() + (size_t)j * K;
|
||||
for (int64_t k = 0; k < K; ++k) acc[(size_t)k] += b * ar[k];
|
||||
}
|
||||
for (int64_t k = 0; k < K; ++k)
|
||||
rad_store_f32(out.get(), W->rad_dtype, n * K + k,
|
||||
rad_load_f32(W->data, W->rad_dtype, n * K + k) +
|
||||
acc[(size_t)k]);
|
||||
std::fill(acc.begin(), acc.end(), 0.f);
|
||||
}
|
||||
SrcTensor& t = tensors_[index_[W->name]];
|
||||
t.data = out.get();
|
||||
owned_.push_back(std::move(out));
|
||||
if (merged) merged->push_back(t.name);
|
||||
++n_merged;
|
||||
off += N;
|
||||
}
|
||||
}
|
||||
}
|
||||
RAD_INFO("lora %s: %d tensor(s) merged at strength %g", path.c_str(), n_merged, strength);
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int Checkpoint::add_file(const std::string& path) {
|
||||
if (kind_ != SafeT) {
|
||||
RAD_ERR("%s is merged into a safetensors checkpoint's namespace; %s is not one",
|
||||
|
||||
Reference in new issue
Block a user