Archived
LoRA for image and video generators: - civitai and Hugging Face adapter files as published: kohya, ComfyUI and diffusers/PEFT key names; LoRA, LoCon, LoHa, LoKr and full-weight diffs; DoRA, OFT and Tucker are refused by name - stacked per request with a strength each, through the `loras` field or <lora:name:strength> tags in the prompt; --lora-dir serves every file in a directory, GET /v1/loras lists them, and --max-loras / --max-lora-rank size the slots on the card (generators default to rank 64) - Krea 2, Qwen-Image 2.1, FLUX.3 [klein], MiniMax H3, LTX-2.5, Anima and SDXL New models: - Anima (base, aesthetic and turbo): Cosmos-Predict2 DiT with the Qwen3-0.6B text encoder and the Qwen-Image VAE, on one card - Stable Diffusion XL and its single-file finetunes (Illustrious, NoobAI including V-Pred, Pony), read as civitai ships them, with the Euler, Euler a and DPM++ 2M samplers Recipes: - q38-27b-mxfp4-df2: any bf16 Qwen3.8-27B or finetune at MXFP4 with the DFlash2 drafter - Krea 2 finetunes from civitai: scripts/krea2_native.py reads Krea's own key names, and krea-2-fp8-unscaled keeps a plain-fp8 file's codes exactly Changes: --max-num-batched-tokens defaults to 2048 (was 8192). Plugin ABI 25: out-of-tree plugins must be rebuilt.
116 lines
5.0 KiB
Python
116 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
||
"""Writes tests/precompiled_golden.h: expected outputs for precompiled_test.cpp.
|
||
|
||
- Unicode 16.0.0's GraphemeBreakTest.txt cases, each a codepoint sequence and the boundaries
|
||
UAX #29 puts in it (core/text/tokenizer_grapheme.h's grapheme_end);
|
||
- a small SentencePiece character map and what HuggingFace `tokenizers`' Precompiled normaliser
|
||
makes of a set of strings through it, clusters that map whole and clusters that do not among
|
||
them (PrecompiledMap::normalize).
|
||
|
||
The map below was built with sentencepiece 0.2 from the rules
|
||
A -> a, U+FF21 -> A, U+FF41 -> a, e U+0301 -> U+00E9, LF -> space, U+2160 -> I
|
||
and is kept as base64 so regenerating needs only `tokenizers` (0.23.3 produced the current file):
|
||
|
||
python3 tests/mk_precompiled_goldens.py GraphemeBreakTest.txt > tests/precompiled_golden.h
|
||
"""
|
||
import base64
|
||
import sys
|
||
|
||
import tokenizers
|
||
from tokenizers import normalizers
|
||
|
||
CHARSMAP = (
|
||
"AAQAAAAsAAAKDQAAAAAAgAYAAIDMAAIAgQ0AAAgAAICFvAIAoAUAAAQAAIC8nAIAvRACAKEFAAACAACAgTUAAA4AAAARAA"
|
||
"AAEAAAABMAAAASAAAAFQAAABQAAAAXAAAAFgAAABkAAAAYAAAAGwAAABoAAAAdAAAAHAAAAB8AAAAeAAAAIQAAACAAAAAj"
|
||
"AAAAIgAAACUAAAAkAAAAJwAAACYAAAApAAAAKAAAACsAAAAqAAAALQAAACwAAAAvAAAALgAAADEAAAAwAAAAMwAAADIAAA"
|
||
"A1AAAANAAAADcAAAA2AAAAOQAAADgAAAA7AAAAOgAAAD0AAAA8AAAAPwAAAD4AAABBAAAAQAAAAEMAAABCAAAARQAAAEQA"
|
||
"AABHAAAARgAAAEkAAABIAAAAQSUBAEoAAABNAAAATAAAAE8AAABOAAAAUQAAAFAAAABTAAAAUgAAAFUAAABUAAAAVwAAAF"
|
||
"YAAABZAAAAWAAAAFsAAABaAAAAXQAAAFwAAABfAAAAXgAAAGEAAABgAAAAYwAAAGIAAABlAAAAZAAAAGcAAABmAAAAaQAA"
|
||
"AGgAAABrAAAAagAAAG0AAABsAAAAZZgCAG4AAABxAAAAcAAAAHMAAAByAAAAdQAAAHQAAAB3AAAAdgAAAHkAAAB4AAAAew"
|
||
"AAAHoAAAB9AAAAfAAAAH8AAAB+AAAAgQAAAIAAAACDAAAAggAAAIUAAACEAAAAhwAAAIYAAACJAAAAiAAAAIsAAACKAAAA"
|
||
"jQAAAIwAAACPAAAAjgAAAJEAAACQAAAAkwAAAJIAAACVAAAAlAAAAJcAAACWAAAAmQAAAJgAAACbAAAAmgAAAJ0AAACcAA"
|
||
"AAnwAAAJ4AAAChAAAAoAAAAKMAAACiAAAApQAAAKQAAACnAAAApgAAAKkAAACoAAAAqwAAAKoAAACtAAAArAAAAK8AAACu"
|
||
"AAAAsQAAALAAAACzAAAAsgAAALUAAAC0AAAAtwAAALYAAAC5AAAAuAAAALsAAAC6AAAAvQAAALwAAAC/AAAAvgAAAMEAAA"
|
||
"DAAAAAwwAAAMIAAADFAAAAxAAAAMcAAADGAAAAyQAAAMgAAADLAAAAygAAAM0AAADMAAAAzwAAAM4AAADRAAAA0AAAANMA"
|
||
"AADSAAAA1QAAANQAAADXAAAA1gAAANkAAADYAAAA2wAAANoAAADdAAAA3AAAAN8AAADeAAAA4QAAAOAAAADjAAAA4gAAAO"
|
||
"9IAQDkAAAA5wAAAOYAAADpAAAA4qwBAOsAAADqAAAA7QAAAOwAAADvAAAA7gAAAPEAAADwAAAA8wAAAPIAAAD1AAAA9AAA"
|
||
"APcAAAD2AAAA+QAAAPgAAAD7AAAA+gAAAP0AAAD8AAAA/wAAAP4AAAAgAEEASQBhAMOpAA=="
|
||
)
|
||
|
||
INPUTS = [
|
||
"", "plain ascii", "A big Apple", "Abc a", "line one\nline two\n",
|
||
"café", "éé", "Áx", "Á", "Ⅰ Ⅰ́",
|
||
"é vs é", "1️⃣ keycap", "\U0001F469\U0001F4BB",
|
||
"\U0001F1EF\U0001F1F5\U0001F1FA", "각 jamo", "\r\nCRLF\r\n",
|
||
"क्ष conjunct", "ab", "tab\there", "กำ thai",
|
||
"ẍ̈̈̈", "Ä̈",
|
||
]
|
||
|
||
|
||
def cstr(s):
|
||
out = '"'
|
||
prev_hex = False
|
||
for b in s.encode("utf-8"):
|
||
c = chr(b)
|
||
if c == '"':
|
||
out += '\\"'; prev_hex = False
|
||
elif c == "\\":
|
||
out += "\\\\"; prev_hex = False
|
||
elif 0x20 <= b < 0x7F:
|
||
if prev_hex and c in "0123456789abcdefABCDEF":
|
||
out += '" "'
|
||
out += c; prev_hex = False
|
||
else:
|
||
out += "\\x%02x" % b; prev_hex = True
|
||
return out + '"'
|
||
|
||
|
||
def grapheme_cases(path):
|
||
"""(codepoints, bitmask of the positions a cluster starts at, beyond the first)."""
|
||
cases = []
|
||
for line in open(path, encoding="utf-8"):
|
||
line = line.split("#", 1)[0].strip()
|
||
if not line:
|
||
continue
|
||
toks = line.split()
|
||
cps, mask = [], 0
|
||
for t in toks[1:-1]:
|
||
if t in ("÷", "×"):
|
||
if t == "÷":
|
||
mask |= 1 << len(cps)
|
||
continue
|
||
cps.append(int(t, 16))
|
||
cases.append((cps, mask))
|
||
return cases
|
||
|
||
|
||
def main():
|
||
pc = normalizers.Precompiled(base64.b64decode(CHARSMAP))
|
||
w = sys.stdout.write
|
||
w("/* precompiled_golden.h -- GENERATED by mk_precompiled_goldens.py from tokenizers %s and "
|
||
"the\n * Unicode 16.0.0 GraphemeBreakTest.txt; do not edit. */\n" % tokenizers.__version__)
|
||
w("#pragma once\n#include <cstdint>\n\n")
|
||
w("static const char* kPcCharsmap =\n")
|
||
for i in range(0, len(CHARSMAP), 96):
|
||
w(" \"%s\"\n" % CHARSMAP[i:i + 96])
|
||
w(" ;\n\n")
|
||
w("struct PcCase { const char* in; const char* out; };\n")
|
||
w("static const PcCase kPcCases[] = {\n")
|
||
for s in INPUTS:
|
||
w(" { %s, %s },\n" % (cstr(s), cstr(pc.normalize_str(s))))
|
||
w("};\n\n")
|
||
cases = grapheme_cases(sys.argv[1])
|
||
w("/* A cluster starts at codepoint i (i > 0) where bit i of `starts` is set. */\n")
|
||
w("struct GbCase { uint32_t cp[8]; uint32_t n; uint32_t starts; };\n")
|
||
w("static const GbCase kGbCases[] = {\n")
|
||
for cps, mask in cases:
|
||
if len(cps) > 8:
|
||
continue
|
||
w(" { { %s }, %d, 0x%x },\n" % (", ".join("0x%X" % c for c in cps), len(cps),
|
||
mask & ~1))
|
||
w("};\n")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|