merge origin/main: the upstream LoRA-runtime refactor beneath the ref2va port

Merges upstream 1.10.0 (152 commits: the LoRA acquire/runtime refactor, the
form-1 LTX-2 scheduler family, guidance terms + negative prompts, decoder
selection, input_reference, new architectures) into the ref2va port branch.
Resolution rule throughout: keep BOTH feature sets; ABI numbering follows
upstream (RAD_ABI_VERSION 26, RAD_FORMAT_VER 2), with the port's video fields
unioned into RadVideoGenBatch/RadVideoGenDecl and abi_layout_table.h
regenerated from the live table.

Notable reconciliations:
  * videos.cpp: the task grammars are disjoint by capability -- keyframe tasks
    (i2va/l2va/flash-attn l2va/fl2va) are recognized only when decl.encodes,
    so upstream models keep refusing them as unknown tasks; input_reference,
    the LoRA tag/field pipeline, and the guidance/negative_prompt rendering
    coexist with refs/ref2va; the prompt put() helper hoisted to block scope
    for the media branch.
  * video_schedule(): upstream's (steps, video_tokens, refine) keeps its
    positional slots; the port's shift_video/shift_audio overrides move to the
    tail so upstream's schedule tests call unchanged.
  * r4d_selftest conv3d cases: the port's sp/st/causal/down/refl geometry and
    upstream's tpad/tpre fold into one reference (ft = causal ? 2 : tpad==2 ?
    2+tpre : 1); rms_mod rows keep the port's i8/fp8 quant modes alongside
    upstream's wadd/norm_once/norm parameters.
  * tests/oot_plugins.sh: the per-plugin cmake --install gains a --prefix
    staging dir -- plugin .so files still land in the absolute
    RAD_PLUGIN_INSTALL_HOME, but libr4d now also installs r4d_selftest to a
    relative bin/, which needs no root.

Host ctest: 112/113 (mm_test's webp gap pre-exists this merge); r4d_selftest,
engine_e2e, oot_plugins, abi_layout, all LoRA tests green.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-22 18:38:04 -05:00
commit a1a75da7e9
415 files changed
+78837 -5310

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
"""gen_grapheme_ucd.py -- writes core/text/tokenizer_grapheme_ucd.cpp, the Unicode properties the
extended grapheme cluster rules (UAX #29) read.
HuggingFace tokenizers' `Precompiled` normaliser walks its text by extended grapheme clusters
(the unicode-segmentation crate, Unicode 16.0.0), so the cluster boundaries are part of what a
SentencePiece-derived tokenizer.json means. The tables come from the UCD files of that version:
https://www.unicode.org/Public/16.0.0/ucd/auxiliary/GraphemeBreakProperty.txt
https://www.unicode.org/Public/16.0.0/ucd/emoji/emoji-data.txt
https://www.unicode.org/Public/16.0.0/ucd/DerivedCoreProperties.txt
python3 tools/gen_grapheme_ucd.py <dir holding the three files> > core/text/tokenizer_grapheme_ucd.cpp
"""
import os
import sys
GCB = ["Other", "CR", "LF", "Control", "Extend", "ZWJ", "Regional_Indicator", "Prepend",
"SpacingMark", "L", "V", "T", "LV", "LVT"]
INCB = ["None", "Linker", "Consonant", "Extend"]
def ranges(path, want):
"""(first, last, value) for every line whose property is `want(prop)` (a value or None)."""
out = []
for line in open(path, encoding="utf-8"):
line = line.split("#", 1)[0].strip()
if not line:
continue
f = [x.strip() for x in line.split(";")]
v = want(f[1:])
if v is None:
continue
a = f[0].split("..")
lo = int(a[0], 16)
hi = int(a[1], 16) if len(a) > 1 else lo
out.append((lo, hi, v))
out.sort()
merged = []
for lo, hi, v in out:
if merged and merged[-1][2] == v and merged[-1][1] + 1 == lo:
merged[-1] = (merged[-1][0], hi, v)
else:
merged.append((lo, hi, v))
return merged
def main():
d = sys.argv[1]
gcb = ranges(os.path.join(d, "GraphemeBreakProperty.txt"),
lambda f: GCB.index(f[0]) if f[0] in GCB else None)
pict = ranges(os.path.join(d, "emoji-data.txt"),
lambda f: 1 if f[0] == "Extended_Pictographic" else None)
incb = ranges(os.path.join(d, "DerivedCoreProperties.txt"),
lambda f: INCB.index(f[1]) if f[0] == "InCB" and f[1] in INCB else None)
w = sys.stdout.write
w("/* tokenizer_grapheme_ucd.cpp -- GENERATED by tools/gen_grapheme_ucd.py from the Unicode "
"16.0.0 UCD;\n * do not edit. The properties UAX #29's extended grapheme cluster rules read "
"(tokenizer_grapheme.h). */\n")
w('#include "text/tokenizer_grapheme.h"\n\nnamespace rad {\nnamespace ucd {\n\n')
w("const GbRange k_gcb[] = {\n")
for lo, hi, v in gcb:
w(" { 0x%X, 0x%X, %d },\n" % (lo, hi, v))
w("};\nconst size_t k_gcb_n = sizeof k_gcb / sizeof k_gcb[0];\n\n")
w("const GbRange k_ext_pict[] = {\n")
for lo, hi, v in pict:
w(" { 0x%X, 0x%X, %d },\n" % (lo, hi, v))
w("};\nconst size_t k_ext_pict_n = sizeof k_ext_pict / sizeof k_ext_pict[0];\n\n")
w("const GbRange k_incb[] = {\n")
for lo, hi, v in incb:
w(" { 0x%X, 0x%X, %d },\n" % (lo, hi, v))
w("};\nconst size_t k_incb_n = sizeof k_incb / sizeof k_incb[0];\n\n")
w("} /* namespace ucd */\n} /* namespace rad */\n")
if __name__ == "__main__":
main()
+28
View File
@@ -122,6 +122,13 @@ void usage() {
" Declare checks the recipe against the kernels it resolves\n"
" --tokenizer F tokenizer.json; its declared chain is baked instead of being\n"
" reconstructed from a pre-tokenizer name\n"
" --tokenizer2 F a second tokenizer.json, baked as the container's second vocab:\n"
" a generator that reads its prompt through two tokenizers\n"
" --add FILE one more .safetensors file merged into the checkpoint, its tensor\n"
" names kept: a release shipped as separate single files (a\n"
" diffusion model, a text encoder and a VAE). Repeatable\n"
" --config DIR read config.json, generation_config.json and tokenizer.json from\n"
" DIR, for a single-file checkpoint that ships none of them\n"
" --imatrix F llama.cpp imatrix: the expert-popularity profile, the column\n"
" importances handed to each quantiser, and the weighting of the\n"
" error report\n"
@@ -195,6 +202,8 @@ int for_row_pieces(int64_t n, bool parallel, std::string* why, F fn) {
int main(int argc, char** argv) {
std::string in, out, arch_override, home = rad_home(), tokjson, imat_path, draft_dir;
std::string tokjson2, config_dir;
std::vector<std::string> add_files;
std::vector<std::string> hierarchy = rad_hierarchy_from_env();
std::vector<std::string> recipe_files, quant_flags;
int64_t max_tok = 8192;
@@ -232,6 +241,9 @@ int main(int argc, char** argv) {
else if (a == "--home") home = next("--home");
else if (a == "--kernels") hierarchy = rad_split_list(next("--kernels"));
else if (a == "--tokenizer") tokjson = next("--tokenizer");
else if (a == "--tokenizer2") tokjson2 = next("--tokenizer2");
else if (a == "--add") add_files.push_back(next("--add"));
else if (a == "--config") config_dir = next("--config");
else if (a == "--imatrix") imat_path = next("--imatrix");
else if (a == "--set") {
const std::string kv = next("--set");
@@ -371,7 +383,12 @@ int main(int argc, char** argv) {
/* ---------------------------------------------------------------- source */
Checkpoint ck;
if (!config_dir.empty()) ck.set_meta_dir(config_dir);
if (ck.open(in) < 0) return 1;
for (const std::string& f : add_files) {
if (ck.add_file(f) < 0) return 1;
RAD_INFO("added %s", f.c_str());
}
MetaOwn& meta = ck.meta();
/* Merge the drafter before declare: the architecture plugin declares a draft block only if
* `draft.architectures` is present. */
@@ -952,6 +969,17 @@ int main(int argc, char** argv) {
w.abort();
return 1;
}
if (!tokjson2.empty()) {
VocabBuild vb2;
RAD_INFO("vocab 2 %s", tokjson2.c_str());
if (parse_tokenizer_json(tokjson2.c_str(), vb2) < 0) { w.abort(); return 1; }
std::vector<uint8_t> blob2;
if (vocab_serialize(vb2, sink, 0, blob2) < 0 ||
w.set_aux_vocab_section(blob2.data(), (int64_t)blob2.size()) < 0) {
w.abort();
return 1;
}
}
/* ---------------------------------------------------------------- expert profile */
if (im.entries().size()) {
+2
View File
@@ -65,6 +65,8 @@ const char* step_name(uint32_t k) {
case RAD_PRE_PUNCTUATION: return "pre.Punctuation";
case RAD_PRE_DIGITS: return "pre.Digits";
case RAD_PRE_BYTE_FALLBACK: return "pre.ByteFallback";
case RAD_PRE_END_OF_WORD: return "pre.EndOfWordSuffix";
case RAD_PRE_ADDED_NORMALIZED: return "pre.AddedNormalized";
case RAD_DEC_BYTELEVEL: return "dec.ByteLevel";
case RAD_DEC_METASPACE: return "dec.Metaspace";
case RAD_DEC_REPLACE: return "dec.Replace";
+4 -2
View File
@@ -94,9 +94,11 @@ bool report_diff(const Tokenizer& tok, const char* what, const std::vector<int32
};
show("tokenizer", a);
show(what, b);
const size_t t0 = byte > 60 ? byte - 60 : 0;
/* The pieces' bytes overshoot the text where a piece spells more than it covers (an
* end-of-word suffix), so the window is clamped to the text. */
const size_t t0 = std::min(text.size(), byte > 60 ? byte - 60 : 0);
std::printf(" text '%s'\n",
printable(text.substr(t0, std::min<size_t>(120, text.size() - std::min(t0, text.size())))).c_str());
printable(text.substr(t0, std::min<size_t>(120, text.size() - t0))).c_str());
return true;
}
+5 -1
View File
@@ -146,7 +146,11 @@ void apply_norm(std::string& text, const VocabStep& s) {
std::vector<uint32_t> cpts = unicode_cpts_from_utf8(text);
std::string out;
out.reserve(text.size());
for (uint32_t c : cpts) out += unicode_cpt_to_utf8(unicode_tolower(c));
/* Rust's char::to_lowercase, as HuggingFace runs it: U+0130 is "i" U+0307. */
for (uint32_t c : cpts) {
if (c == 0x130) out += "i\xcc\x87";
else out += unicode_cpt_to_utf8(unicode_tolower(c));
}
text.swap(out);
break;
}