Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

gliner_decide: GLiNER2.5-Decide as a decision engine (fastino, DeBERTa-v3 + GLiNER2's classification head)

JustVugg2987361fcb79
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3c5604be..fefd7663 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -278,7 +278,7 @@ jobs:
run: |
cd c
rc=0
- ENGINES="colibri glm53 inkling kimi_k3 olmoe qwen36 qwen38 deepseek_v41 mimo qwenimage laya"
+ ENGINES="colibri glm53 inkling kimi_k3 olmoe qwen36 qwen38 deepseek_v41 mimo qwenimage laya gliner_decide"
if [ "${{ matrix.v4 }}" = "1" ]; then ENGINES="$ENGINES deepseek-v4"; fi
for t in $ENGINES; do
echo "::group::$t"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b2cf5e43..353ec731 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -67,7 +67,7 @@ jobs:
- name: Build engines
run: |
cd c
- for t in colibri glm53 inkling kimi_k3 olmoe qwen36 qwen38 deepseek_v41 mimo qwenimage laya; do
+ for t in colibri glm53 inkling kimi_k3 olmoe qwen36 qwen38 deepseek_v41 mimo qwenimage laya gliner_decide; do
make $t ${{ matrix.make_args }}
done
ls -lh colibri${{ matrix.ext }} glm53${{ matrix.ext }} inkling${{ matrix.ext }} kimi_k3${{ matrix.ext }} olmoe${{ matrix.ext }} qwen36${{ matrix.ext }} qwen38${{ matrix.ext }} deepseek_v41${{ matrix.ext }} mimo${{ matrix.ext }}
@@ -135,6 +135,7 @@ jobs:
cp c/deepseek_v41${{ matrix.ext }} dist/deepseek_v41${{ matrix.ext }}
cp c/mimo${{ matrix.ext }} dist/mimo${{ matrix.ext }}
cp c/laya${{ matrix.ext }} dist/laya${{ matrix.ext }}
+ cp c/gliner_decide${{ matrix.ext }} dist/gliner_decide${{ matrix.ext }}
# deepseek_v4 -- underscore, not the hyphen of the make target: engine_for()
# looks for "deepseek_v4" next to coli. Guarded, not unconditional, because
# the macos-arm64 archive has no such engine to ship (#858).
diff --git a/.gitignore b/.gitignore
index 58a352c7..c5acbaaa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,8 @@ c/qwen38
c/qwen38.exe
c/laya
c/laya.exe
+c/gliner_decide
+c/gliner_decide.exe
c/tools/jev-sdk/node_modules/
# deepseek_v4 and the per-unit objects its amalgamated Makefile leaves behind.
# The same omission as #858, one file over: every engine is listed here except
diff --git a/README.it.md b/README.it.md
index d6b5f973..77e1a8b1 100644
--- a/README.it.md
+++ b/README.it.md
@@ -526,6 +526,7 @@ altre nove famiglie di modelli linguistici, e un motore genera immagini. Ognuna
| **OLMoE** (AI2) | 7B / 1B | convertito con `c/tools/convert_olmoe_merged.py`: container **int8**, ~7 GB | `make -C c olmoe` | - |
| **Qwen-Image-2.1** (Alibaba) | modello di immagini | [`Qwen/Qwen-Image-2.1`](https://huggingface.co/Qwen/Qwen-Image-2.1) (~33 GB), checkpoint diffusers ufficiale, **nessuna conversione**: il text encoder e il diffusion transformer vengono quantizzati a int8 durante il caricamento. Immagini dentro `coli chat`, `POST /v1/images/generations` su `coli serve`. Qwen Research License: solo uso non commerciale | `make -C c qwenimage` | [qwen-image.md](docs/qwen-image.md) |
| **Laya** (Convai Innovations) | modello di decisione, 421M | [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya) (842 MB), checkpoint ufficiale, **nessuna conversione**: un encoder ModernBERT con una testa di decisione che risponde a domande tipizzate (choice, score, noul) con probabilità calibrate invece di generare. Servito su `POST /v1/systemone` da `coli serve`. Apache-2.0 | `make -C c laya` | [laya.md](docs/laya.md) |
+| **GLiNER2.5-Decide** (fastino) | modello di decisione, 340M | [`fastino/GLiNER2.5-Decide`](https://huggingface.co/fastino/GLiNER2.5-Decide) (1,9 GB), checkpoint ufficiale, **nessuna conversione**: un encoder DeBERTa-v3 con la testa di classificazione di GLiNER2; le domande di una richiesta e lo stato si leggono in un solo passaggio e ogni opzione riceve una probabilità. Servito su `POST /v1/systemone` da `coli serve`. Apache-2.0 | `make -C c gliner_decide` | [gliner_decide.md](docs/gliner_decide.md) |
Qwen3.6 offre tre container pre-convertiti: **int4-gs64** (consigliato: coseno
misurato rispetto all'ancora int8 da 0,98777 a 0,99313 e KL da 0,109 a 0,080
diff --git a/README.ja.md b/README.ja.md
index aa350624..be288329 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -486,6 +486,7 @@ GLM-5.2 がリファレンスモデルですが、同じストリーミング手
| **OLMoE**(AI2) | 7B / 1B | `c/tools/convert_olmoe_merged.py` で変換 — **int8** コンテナ、約 7 GB | `make -C c olmoe` | — |
| **Qwen-Image-2.1**(Alibaba) | 画像モデル | [`Qwen/Qwen-Image-2.1`](https://huggingface.co/Qwen/Qwen-Image-2.1)(約 33 GB)、公式 diffusers チェックポイント、**変換不要**: テキストエンコーダと拡散トランスフォーマーはロード時に int8 に量子化。`coli chat` では画像をインライン表示し、`coli serve` では `POST /v1/images/generations` で提供。Qwen Research License: 非商用利用のみ | `make -C c qwenimage` | [qwen-image.md](docs/qwen-image.md) |
| **Laya**(Convai Innovations) | 判定モデル、421M | [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya)(842 MB)、公式チェックポイント、**変換不要**: ModernBERT エンコーダと判定ヘッドで、型付きの質問(choice、score、noul)に生成ではなく較正済みの確率で答える。`coli serve` の `POST /v1/systemone` で提供。Apache-2.0 | `make -C c laya` | [laya.md](docs/laya.md) |
+| **GLiNER2.5-Decide**(fastino) | 判定モデル、340M | [`fastino/GLiNER2.5-Decide`](https://huggingface.co/fastino/GLiNER2.5-Decide)(1.9 GB)、公式チェックポイント、**変換不要**: DeBERTa-v3 エンコーダと GLiNER2 の分類ヘッド。リクエストの全質問と状態を一度に読み、各選択肢に確率を返す。`coli serve` の `POST /v1/systemone` で提供。Apache-2.0 | `make -C c gliner_decide` | [gliner_decide.md](docs/gliner_decide.md) |
Qwen3.6 には変換済みコンテナが 3 つあります: **int4-gs64**(推奨 — int8 のアンカーに対するコサイン類似度は
行単位と比べて 0.98777 → 0.99313、KL は 0.109 → 0.080 と計測されており、量子化誤差が約 44% 少ない)、
diff --git a/README.md b/README.md
index 4b973e4f..06eb9403 100644
--- a/README.md
+++ b/README.md
@@ -507,6 +507,7 @@ or from `model_index.json` for the image model):
| **OLMoE** (AI2) | 7B / 1B | converted with `c/tools/convert_olmoe_merged.py` — **int8** container, ~7 GB | `make -C c olmoe` | — |
| **Qwen-Image-2.1** (Alibaba) | image model | [`Qwen/Qwen-Image-2.1`](https://huggingface.co/Qwen/Qwen-Image-2.1) (~33 GB), official diffusers checkpoint, **no conversion**: the text encoder and the diffusion transformer are quantized to int8 while loading. Pictures inline in `coli chat`, `POST /v1/images/generations` on `coli serve`. Qwen Research License: non-commercial use only | `make -C c qwenimage` | [qwen-image.md](docs/qwen-image.md) |
| **Laya** (Convai Innovations) | decision model, 421M | [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya) (842 MB), official checkpoint, **no conversion**: a ModernBERT encoder with a decision head that answers typed questions (choice, score, noul) with calibrated probabilities instead of generating. Served on `POST /v1/systemone` by `coli serve`. Apache-2.0 | `make -C c laya` | [laya.md](docs/laya.md) |
+| **GLiNER2.5-Decide** (fastino) | decision model, 340M | [`fastino/GLiNER2.5-Decide`](https://huggingface.co/fastino/GLiNER2.5-Decide) (1.9 GB), official checkpoint, **no conversion**: a DeBERTa-v3 encoder with GLiNER2's classification head; the questions of a request and the state are read in one pass and every option gets a probability. Served on `POST /v1/systemone` by `coli serve`. Apache-2.0 | `make -C c gliner_decide` | [gliner_decide.md](docs/gliner_decide.md) |
Qwen3.6 ships three pre-converted containers: **int4-gs64** (recommended — measured
cosine to the int8 anchor 0.98777 → 0.99313 and KL 0.109 → 0.080 against per-row, i.e.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 73cbf490..2a97fc85 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -441,6 +441,7 @@ GLM-5.2 是参考模型,但同样的流式方法还能运行另外九个语言
| **OLMoE**(AI2) | 7B / 1B | 用 `c/tools/convert_olmoe_merged.py` 转换,**int8** 容器,约 7 GB | `make -C c olmoe` | 无 |
| **Qwen-Image-2.1**(Alibaba) | 图像模型 | [`Qwen/Qwen-Image-2.1`](https://huggingface.co/Qwen/Qwen-Image-2.1)(约 33 GB),官方 diffusers checkpoint,**无需转换**:文本编码器与扩散 transformer 在加载时量化为 int8。`coli chat` 中直接显示图片,`coli serve` 提供 `POST /v1/images/generations`。Qwen Research License:仅限非商业用途 | `make -C c qwenimage` | [qwen-image.md](docs/qwen-image.md) |
| **Laya**(Convai Innovations) | 决策模型,421M | [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya)(842 MB),官方 checkpoint,**无需转换**:ModernBERT 编码器加决策头,对类型化问题(choice、score、noul)给出校准后的概率,而不是生成文本。由 `coli serve` 在 `POST /v1/systemone` 上提供。Apache-2.0 | `make -C c laya` | [laya.md](docs/laya.md) |
+| **GLiNER2.5-Decide**(fastino) | 决策模型,340M | [`fastino/GLiNER2.5-Decide`](https://huggingface.co/fastino/GLiNER2.5-Decide)(1.9 GB),官方 checkpoint,**无需转换**:DeBERTa-v3 编码器加 GLiNER2 的分类头,一次读完请求中的所有问题和状态,为每个选项给出概率。由 `coli serve` 在 `POST /v1/systemone` 上提供。Apache-2.0 | `make -C c gliner_decide` | [gliner_decide.md](docs/gliner_decide.md) |
Qwen3.6 提供三个预转换容器:**int4-gs64**(推荐:与 per-row 相比,对 int8 基准的余弦相似度
实测从 0.98777 提升到 0.99313,KL 从 0.109 降到 0.080,即量化误差减少约 44%)、作为 A/B 基线的
diff --git a/README.zh-TW.md b/README.zh-TW.md
index 30635d83..9efd1fc8 100644
--- a/README.zh-TW.md
+++ b/README.zh-TW.md
@@ -442,6 +442,7 @@ GLM-5.2 是參考模型,但同樣的串流方法還能執行另外九個語言
| **OLMoE**(AI2) | 7B / 1B | 以 `c/tools/convert_olmoe_merged.py` 轉換,**int8** 容器,約 7 GB | `make -C c olmoe` | 無 |
| **Qwen-Image-2.1**(Alibaba) | 圖像模型 | [`Qwen/Qwen-Image-2.1`](https://huggingface.co/Qwen/Qwen-Image-2.1)(約 33 GB),官方 diffusers checkpoint,**無需轉換**:文字編碼器與擴散 transformer 在載入時量化為 int8。`coli chat` 中直接顯示圖片,`coli serve` 提供 `POST /v1/images/generations`。Qwen Research License:僅限非商業用途 | `make -C c qwenimage` | [qwen-image.md](docs/qwen-image.md) |
| **Laya**(Convai Innovations) | 決策模型,421M | [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya)(842 MB),官方 checkpoint,**無需轉換**:ModernBERT 編碼器加決策頭,對型別化問題(choice、score、noul)給出校準後的機率,而不是生成文字。由 `coli serve` 在 `POST /v1/systemone` 上提供。Apache-2.0 | `make -C c laya` | [laya.md](docs/laya.md) |
+| **GLiNER2.5-Decide**(fastino) | 決策模型,340M | [`fastino/GLiNER2.5-Decide`](https://huggingface.co/fastino/GLiNER2.5-Decide)(1.9 GB),官方 checkpoint,**無需轉換**:DeBERTa-v3 編碼器加 GLiNER2 的分類頭,一次讀完請求中的所有問題和狀態,為每個選項給出機率。由 `coli serve` 在 `POST /v1/systemone` 上提供。Apache-2.0 | `make -C c gliner_decide` | [gliner_decide.md](docs/gliner_decide.md) |
Qwen3.6 提供三個預先轉換的容器:**int4-gs64**(推薦:與 per-row 相比,對 int8 基準的餘弦相似度
實測從 0.98777 提升到 0.99313,KL 從 0.109 降到 0.080,即量化誤差減少約 44%)、作為 A/B 基準的
diff --git a/c/Makefile b/c/Makefile
index 23d039ff..65941aa0 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -1273,6 +1273,17 @@ endif
laya$(EXE): laya.c .build-config
$(CC) $(CFLAGS) laya.c -o laya$(EXE) $(LDFLAGS)
+# GLiNER2.5-Decide (fastino), a decision model: DeBERTa-v3 encoder + GLiNER2's
+# classification head, served on POST /v1/systemone through the DECIDE command
+# (docs/gliner_decide.md). Its gliner_unicode.h is generated by
+# tools/gen_gliner_unicode.py (Python's own \w, \s and str.lower()).
+ifneq ($(EXE),)
+.PHONY: gliner_decide
+gliner_decide: gliner_decide$(EXE)
+endif
+gliner_decide$(EXE): gliner_decide.c .build-config
+ $(CC) $(CFLAGS) gliner_decide.c -o gliner_decide$(EXE) $(LDFLAGS)
+
# Tiny Laya checkpoint + the laya package's own answers on it. The generator is
# numpy and deterministic; laya_tiny/ref.json is committed and comes from the
# `laya` package (tools/make_laya_ref.py, maintainer-run, fixture SHA-256
@@ -2675,7 +2686,7 @@ check:
$(MAKE) portable
$(MAKE) test
-install: colibri$(EXE) glm53$(EXE) inkling$(EXE) kimi_k3$(EXE) olmoe$(EXE) qwen36$(EXE) qwen38$(EXE) deepseek_v41$(EXE) mimo$(EXE) qwenimage$(EXE) laya$(EXE) \
+install: colibri$(EXE) glm53$(EXE) inkling$(EXE) kimi_k3$(EXE) olmoe$(EXE) qwen36$(EXE) qwen38$(EXE) deepseek_v41$(EXE) mimo$(EXE) qwenimage$(EXE) laya$(EXE) gliner_decide$(EXE) \
$(if $(filter 1,$(COLI_V4_SUPPORTED)),deepseek-v4,)
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -d $(DESTDIR)$(LIBEXECDIR)
@@ -2690,6 +2701,7 @@ install: colibri$(EXE) glm53$(EXE) inkling$(EXE) kimi_k3$(EXE) olmoe$(EXE) qwen3
$(INSTALL) -m 755 qwen38$(EXE) $(DESTDIR)$(LIBEXECDIR)/qwen38$(EXE)
$(INSTALL) -m 755 qwenimage$(EXE) $(DESTDIR)$(LIBEXECDIR)/qwenimage$(EXE)
$(INSTALL) -m 755 laya$(EXE) $(DESTDIR)$(LIBEXECDIR)/laya$(EXE)
+ $(INSTALL) -m 755 gliner_decide$(EXE) $(DESTDIR)$(LIBEXECDIR)/gliner_decide$(EXE)
$(INSTALL) -m 755 deepseek_v41$(EXE) $(DESTDIR)$(LIBEXECDIR)/deepseek_v41$(EXE)
$(INSTALL) -m 755 mimo$(EXE) $(DESTDIR)$(LIBEXECDIR)/mimo$(EXE)
@if [ -f deepseek_v4$(EXE) ]; then \
diff --git a/c/coli b/c/coli
index 2f52874b..37cbe2d0 100755
--- a/c/coli
+++ b/c/coli
@@ -263,17 +263,33 @@ def is_image_model(model):
return False
def is_decision_model(model):
- """A decision checkpoint (Laya: rl_agent_config.json, no root config.json):
- served by coli serve / coli web on POST /v1/systemone, never chatted with."""
+ """A decision checkpoint (Laya: rl_agent_config.json, no root config.json;
+ GLiNER2.5-Decide: a GLiNER2 extractor config.json): served by coli serve /
+ coli web on POST /v1/systemone, never chatted with."""
try:
return resolve_model(model).descriptor.modality == "decision"
except (FamilyConfigError, UnknownFamilyError, OSError, TypeError, ValueError):
return False
+# What bounds the tokens a decision engine reads, and the variable that moves it.
+DECISION_LENGTH = {
+ "laya": ("at most its checkpoint's max_len per question", "COLI_LAYA_MAX_LEN"),
+ "gliner_decide": ("every question and the state in one sequence of at most 4096 tokens",
+ "COLI_GLINER_MAX_LEN"),
+}
+
+def is_gliner_decide(model):
+ try:
+ return resolve_model(model).descriptor.id == "gliner_decide"
+ except (FamilyConfigError, UnknownFamilyError, OSError, TypeError, ValueError):
+ return False
+
def decision_refusal(family):
- """What every chatting command says about a decision model, and where to go."""
+ """What every chatting command says about a decision model, and where to go.
+ Laya ships a calibration; GLiNER2.5-Decide gives its classifier's softmax."""
+ answers = "calibrated probabilities" if family.id == "laya" else "a probability per option"
return (f"{C.yel}{family.display_name} is a decision model:{C.r} it answers typed questions "
- f"(choice, score, noul) with calibrated probabilities and does not chat.\n"
+ f"(choice, score, noul) with {answers} and does not chat.\n"
f" Start it with: coli serve --model <dir> (or coli web for the dashboard)\n"
f" then POST /v1/systemone (docs/systemone.md, \"Decision engines\")")
@@ -511,8 +527,9 @@ def env_for_engine(a, arch, plan=None):
sys.exit(f"{C.yel}--ctx does not apply to {family.display_name}:{C.r} an image model has "
f"no context window (the prompt goes through its text encoder once)")
if family.modality == "decision" and getattr(a, "ctx", None):
+ reads, knob = DECISION_LENGTH.get(family.id, ("what its engine allows", "its engine's own variable"))
sys.exit(f"{C.yel}--ctx does not apply to {family.display_name}:{C.r} a decision model reads "
- f"at most its checkpoint's max_len per question (COLI_LAYA_MAX_LEN overrides it)")
+ f"{reads} ({knob} overrides it)")
if getattr(a,"ram",0): explicit_env.add("RAM_GB")
# OMP_NUM_THREADS for the sister engines that do not size their own team.
#
@@ -1391,11 +1408,19 @@ def info_decision_model(a, resolved, row):
enc, cfg = resolved.family_config, resolved.config
name, scale = display_for(resolved)
row("model", a.model)
- row("type", f"{name}{' · ' + scale if scale else ''} · decision model · "
- f"{enc.get('model_type')} encoder, {enc.get('num_hidden_layers')} layer x "
- f"{enc.get('hidden_size')} · head {cfg.get('head_layers')} layer")
- row("budget", f"max_len {cfg.get('max_len')} tokens per question, "
- f"head_max_len {cfg.get('head_max_len')} for the options")
+ encoder = (f"{enc.get('model_type')} encoder, {enc.get('num_hidden_layers')} layer x "
+ f"{enc.get('hidden_size')}")
+ if family.id == "gliner_decide":
+ row("type", f"{name}{' · ' + scale if scale else ''} · decision model · {encoder} · "
+ f"GLiNER2 {cfg.get('architecture') or 'span'} classification head")
+ max_len = os.environ.get("COLI_GLINER_MAX_LEN") or "4096"
+ row("budget", f"max_len {max_len} tokens per request: every question and the state "
+ f"in one sequence (COLI_GLINER_MAX_LEN)")
+ else:
+ row("type", f"{name}{' · ' + scale if scale else ''} · decision model · {encoder} · "
+ f"head {cfg.get('head_layers')} layer")
+ row("budget", f"max_len {cfg.get('max_len')} tokens per question, "
+ f"head_max_len {cfg.get('head_max_len')} for the options")
try:
params, disk = decision_weights(a.model)
row("weights", f"{params/1e6:.0f}M params · {disk/1e6:.0f} MB on disk · "
@@ -1423,7 +1448,9 @@ def plan_decision_command(a):
print(json.dumps(plan, indent=2)); return
banner("plan · RAM for a decision model", model=a.model)
print(f" weights {params/1e6:.0f}M params, {disk/1e6:.0f} MB on disk")
- print(f" RAM about {params*4/1e9:.1f} GB (f32), plus activations of a few MB per question")
+ grows = ("activations that grow with the request's sequence (COLI_GLINER_MAX_LEN)"
+ if is_gliner_decide(a.model) else "activations of a few MB per question")
+ print(f" RAM about {params*4/1e9:.1f} GB (f32), plus {grows}")
print(f" nothing grows with use: no KV cache, no experts to stream")
print()
diff --git a/c/doctor.py b/c/doctor.py
index ce78fa0d..af7aeb79 100644
--- a/c/doctor.py
+++ b/c/doctor.py
@@ -840,9 +840,9 @@ def run_image_doctor(model, engine_path, available_memory=None):
def run_decision_doctor(model, engine_path, available_memory=None):
- """doctor for a decision model (Laya): no root config.json, no experts and
- no KV state. What can be wrong is a missing file of the checkpoint, an
- engine that is not built, or weights that do not fit in RAM as f32."""
+ """doctor for a decision model (Laya, GLiNER2.5-Decide): no experts and no
+ KV state. What can be wrong is a missing file of the checkpoint, an engine
+ that is not built, or weights that do not fit in RAM as f32."""
import json
import struct
model = Path(model).expanduser().resolve()
@@ -857,11 +857,11 @@ def run_decision_doctor(model, engine_path, available_memory=None):
f"{resolved.descriptor.display_name} decision model is registered",
family_id=resolved.descriptor.id, model_type=resolved.model_type,
descriptor=public_metadata(resolved.descriptor)))
- tokenizer_file = resolved.descriptor.tokenizer_file
+ files = (resolved.descriptor.tokenizer_file,) + resolved.descriptor.checkpoint_files
except (FamilyConfigError, UnknownFamilyError) as error:
checks.append(_check("model.family", "fail", str(error)))
- tokenizer_file = "tokenizer/tokenizer.json"
- for name in (tokenizer_file, "tokenizer/tokenizer_config.json", "encoder/config.json"):
+ files = ()
+ for name in files:
present = (model / name).is_file()
checks.append(_check("model.files", "pass" if present else "fail",
f"{name} found" if present else f"{name} is missing"))
diff --git a/c/family_registry.py b/c/family_registry.py
index 552db884..81d80b51 100644
--- a/c/family_registry.py
+++ b/c/family_registry.py
@@ -170,6 +170,10 @@ class FamilyDescriptor:
# Where the tokenizer lives, relative to the model directory. A diffusers
# pipeline keeps it in processor/, not at the root.
tokenizer_file: str = "tokenizer.json"
+ # The other files a decision checkpoint needs besides model.safetensors and
+ # the tokenizer, relative to the model directory: what `coli doctor`
+ # checks. Each decision family keeps its configuration in its own layout.
+ checkpoint_files: tuple = ()
@dataclass(frozen=True, slots=True)
@@ -1681,6 +1685,52 @@ FAMILIES = (
supports_accelerator=False,
modality="decision",
tokenizer_file="tokenizer/tokenizer.json",
+ checkpoint_files=("tokenizer/tokenizer_config.json", "encoder/config.json"),
+ ),
+ FamilyDescriptor(
+ id="gliner_decide",
+ # A GLiNER2 checkpoint's config.json says model_type "extractor" for
+ # every architecture and encoder: resolve_model reads its architecture
+ # and the encoder's own config (encoder_config/config.json) and names it
+ # gliner2_<architecture>_<encoder model_type>. The engine runs the
+ # classification head of the span architecture on a DeBERTa-v2/v3
+ # encoder; GLiNER2.5-Decide is DeBERTa-v3-large (24 layers x 1024).
+ model_types=("gliner2_span_deberta-v2",),
+ display_name="GLiNER2.5-Decide",
+ display_scale="340M",
+ display_variants=(
+ DisplayVariant((("hidden_size", 1024), ("num_hidden_layers", 24)),
+ "GLiNER2.5-Decide", "340M"),
+ ),
+ engine_artifact="gliner_decide",
+ engine_aliases=(),
+ engine_group="gliner_decide",
+ internal_arch="gliner_decide",
+ build_target="gliner_decide",
+ process_names=("gliner_decide",),
+ default_model_id="gliner2.5-decide",
+ cli_adapter="gliner_decide",
+ gateway_adapter="gliner_decide",
+ planner_id="gliner_decide",
+ planner_geometry=None,
+ planner_unsupported_reason=(
+ "a decision model has no KV cache and no experts: it keeps its encoder and "
+ "classification head resident in f32 and reads every question of a request and "
+ "the state in one sequence of at most COLI_GLINER_MAX_LEN tokens"),
+ expert_inventory=lambda _name, _size, _config, _dtype=None: (),
+ config_section="root",
+ # One sequence per request, cut at 4096 tokens by default
+ # (COLI_GLINER_MAX_LEN); the encoder's relative positions set no
+ # ceiling of their own. No generation, so the output budgets are the
+ # placeholders every descriptor carries, and no context variable.
+ limits=FamilyLimits(4096, 4096, 1, 1, 1, 0, ""),
+ capabilities=FamilyCapabilities(False, False, False, False, decision=True),
+ has_gateway_adapter=True,
+ has_cli_adapter=False,
+ supports_accelerator=False,
+ modality="decision",
+ tokenizer_file="tokenizer.json",
+ checkpoint_files=("config.json", "encoder_config/config.json"),
),
)
@@ -1707,7 +1757,9 @@ def _build_registry(families):
"{prompt}" not in family.tune_prompt_template or
family.modality not in ("text", "image", "decision") or
family.capabilities.decision != (family.modality == "decision") or
- not isinstance(family.tokenizer_file, str) or not family.tokenizer_file):
+ not isinstance(family.tokenizer_file, str) or not family.tokenizer_file or
+ not isinstance(family.checkpoint_files, tuple) or
+ any(not isinstance(name, str) or not name for name in family.checkpoint_files)):
raise RegistryError(f"incomplete family descriptor: {family.id}")
try:
family.tune_prompt_template.format(prompt="test", prompt_len=4)
@@ -1838,6 +1890,40 @@ def _resolve_decision_checkpoint(model):
return ResolvedFamily(family, model_type, config, encoder, str(model))
+# GLiNER2's config.json says model_type "extractor" whatever the architecture
+# and the encoder; the encoder's own config sits in encoder_config/.
+GLINER2_MODEL_TYPE = "extractor"
+GLINER2_ENCODER_CONFIG = "encoder_config/config.json"
+
+
+def _resolve_gliner2_checkpoint(model, config):
+ """A GLiNER2 checkpoint (gliner2's ExtractorConfig): the family is keyed on
+ the architecture and the encoder, gliner2_<architecture>_<encoder
+ model_type>, and the encoder config is the family config (its geometry
+ names the variant). A checkpoint without an architecture is "span", as
+ gliner2's AutoExtractor reads it."""
+ path = model / GLINER2_ENCODER_CONFIG
+ try:
+ encoder = json.loads(path.read_text(encoding="utf-8"))
+ except OSError as error:
+ raise FamilyConfigError(f"cannot read {GLINER2_ENCODER_CONFIG}: {model}") from error
+ except json.JSONDecodeError as error:
+ raise FamilyConfigError(f"invalid {GLINER2_ENCODER_CONFIG}: {error}") from error
+ if not isinstance(encoder, dict):
+ raise FamilyConfigError(f"{GLINER2_ENCODER_CONFIG} is not a JSON object")
+ architecture = config.get("architecture") or "span"
+ if not isinstance(architecture, str):
+ raise FamilyConfigError("config.json: architecture is not a string")
+ model_type = (f"gliner2_{_normalize_model_type(architecture)}_"
+ f"{_normalize_model_type(encoder.get('model_type'))}")
+ try:
+ family = _BY_TYPE[model_type]
+ except KeyError as error:
+ raise UnknownFamilyError(f"unsupported GLiNER2 checkpoint: the {architecture} architecture "
+ f"on an {encoder.get('model_type')} encoder") from error
+ return ResolvedFamily(family, model_type, config, encoder, str(model))
+
+
def resolve_model(model_dir):
model = Path(model_dir).expanduser().resolve()
path = model / "config.json"
@@ -1868,6 +1954,8 @@ def resolve_model(model_dir):
" carries model_index.json instead.") from error
except json.JSONDecodeError as error:
raise FamilyConfigError(f"invalid config.json: {error}") from error
+ if isinstance(config, dict) and config.get("model_type") == GLINER2_MODEL_TYPE:
+ return _resolve_gliner2_checkpoint(model, config)
family = family_for_config(config)
family_config = config
if family.config_section == "text_config":
diff --git a/c/gliner_decide.c b/c/gliner_decide.c
new file mode 100644
index 00000000..76929afd
--- /dev/null
+++ b/c/gliner_decide.c
@@ -0,0 +1,1443 @@
+/* gliner_decide.c -- GLiNER2.5-Decide (fastino/GLiNER2.5-Decide on Hugging Face,
+ * Apache-2.0) as a decision engine, in C.
+ *
+ * GLiNER2.5-Decide is a GLiNER2 "span" checkpoint: a DeBERTa-v3-large encoder
+ * and GLiNER2's heads. A decision uses one of them, the classification head:
+ * every question of a request becomes one classification task of a single
+ * classify_text() call, all tasks and the text are read in one sequence by the
+ * encoder, and an MLP scores each label at its [L] marker. The extraction
+ * heads (span_rep, count_pred, count_embed) are never run and never loaded.
+ *
+ * The specification is the model's own Python: the `gliner2` package (2.0.0)
+ * and the DeBERTa-v2 modeling code of transformers it builds on. Each step
+ * below names the function it follows:
+ *
+ * words processing/word_splitter.WhitespaceTokenSplitter: Python's
+ * regex (URLs, e-mails, @handles, \w+(?:[-_]\w+)*, \S), each
+ * word lower-cased with str.lower(); processor._collate_batch
+ * first appends "." to a text that does not end in . ! or ?
+ * schema inference/schema.Schema.classification and
+ * processor._transform_schema: per task
+ * ( [P] task[: prompt][ [DESCRIPTION] label: text ...] ( [L] label ... ) )
+ * tasks joined by [SEP_STRUCT], then [SEP_TEXT] and the words
+ * tokens processor._format_input_with_mapping: every element above is
+ * tokenized on its own (tokenizer.tokenize), no [CLS] / [SEP];
+ * a marker's embedding is its first sub-token
+ * tokenizer tokenizer.json (DebertaV2TokenizerFast): added tokens split
+ * out, Replace(\s{2,}|[\n\r\t] -> " "), NFC, right strip,
+ * Metaspace (prepend always, split), Unigram (Viterbi, unknown
+ * characters fused into one [UNK])
+ * encoder DebertaV2Model: word embeddings and LayerNorm (no absolute
+ * positions), 24 post-norm layers of disentangled attention
+ * (content-to-content + content-to-position + position-to-
+ * content, relative positions in log buckets, shared key and
+ * query projections, the relative embeddings LayerNorm'd), GELU
+ * FFN
+ * head runtime._extract_classification_result: classifier
+ * (Linear -> ReLU -> Linear) at each [L], temperature 1,
+ * softmax over the task's labels (a single-label task)
+ *
+ * A System One question becomes a task as docs/gliner_decide.md describes: the
+ * task name is the question id, the prompt its instructions, the labels a
+ * choice's labels, a score's levels "0".."n-1" or a noul's "yes" then "no",
+ * and the option texts become label descriptions.
+ *
+ * Weights are read as stored (F32 in the release) and kept in f32. The
+ * relative embeddings are the same for every request, so their projections
+ * through each layer's query and key are computed once at load.
+ *
+ * Ways to run it:
+ * SERVE=1 SNAP=<dir> gliner_decide the mux serve protocol, DECIDE only
+ * gliner_decide --model DIR --records F [--ids] a JSON array of DECIDE records;
+ * one DECISION object per line
+ * gliner_decide --model DIR --tokenize F a JSON array of strings; their ids
+ * gliner_decide --split F a JSON array of strings; their words
+ */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <math.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#ifdef _OPENMP
+#include <omp.h>
+#endif
+
+#include "compat.h"
+#include "json.h"
+#include "st.h"
+#include "qwen38_nfc.h"
+#include "qi_gemm.h"
+#include "matmul_f32.h"
+#include "serve_codec.h"
+#include "decide_serve.h"
+#include "omp_tune.h"
+#include "gliner_unicode.h"
+
+/* ------------------------------------------------------------------ utils */
+
+static void die(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ fprintf(stderr, "[gliner_decide] ");
+ vfprintf(stderr, fmt, args);
+ fputc('\n', stderr);
+ va_end(args);
+ exit(1);
+}
+
+static void *xmalloc(size_t size)
+{
+ void *p = malloc(size ? size : 1);
+ if (!p) die("out of memory (%zu bytes)", size);
+ return p;
+}
+
+static void *xcalloc(size_t count, size_t size)
+{
+ void *p = calloc(count ? count : 1, size ? size : 1);
+ if (!p) die("out of memory (%zu x %zu bytes)", count, size);
+ return p;
+}
+
+static void *xrealloc(void *p, size_t size)
+{
+ void *q = realloc(p, size ? size : 1);
+ if (!q) die("out of memory (%zu bytes)", size);
+ return q;
+}
+
+static char *read_text(const char *path)
+{
+ FILE *f = fopen(path, "rb");
+ if (!f) return NULL;
+ if (fseek(f, 0, SEEK_END) != 0) { fclose(f); return NULL; }
+ long n = ftell(f);
+ if (n < 0 || n > (1L << 30)) { fclose(f); return NULL; }
+ rewind(f);
+ char *b = (char *)xmalloc((size_t)n + 1);
+ if (fread(b, 1, (size_t)n, f) != (size_t)n) { fclose(f); free(b); return NULL; }
+ b[n] = 0;
+ fclose(f);
+ return b;
+}
+
+static jval *read_json(const char *dir, const char *name)
+{
+ char path[4096];
+ snprintf(path, sizeof(path), "%s/%s", dir, name);
+ char *text = read_text(path);
+ if (!text) die("cannot read %s", path);
+ jval *root = json_parse_checked(text);
+ free(text);
+ if (!root || root->t != J_OBJ) die("%s is not a JSON object", path);
+ return root;
+}
+
+static double num_or(jval *o, const char *key, double fallback)
+{
+ jval *v = json_get(o, key);
+ return v && v->t == J_NUM ? v->num : fallback;
+}
+
+static int bool_or(jval *o, const char *key, int fallback)
+{
+ jval *v = json_get(o, key);
+ return v && v->t == J_BOOL ? v->boolean : fallback;
+}
+
+static const char *str_or(jval *o, const char *key, const char *fallback)
+{
+ jval *v = json_get(o, key);
+ return v && v->t == J_STR ? v->str : fallback;
+}
+
+static double now_ms(void)
+{
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return t.tv_sec * 1e3 + t.tv_nsec / 1e6;
+}
+
+/* A growable byte string and a growable int array. */
+typedef struct { char *s; size_t n, cap; } Str;
+typedef struct { int *v; int n, cap; } IntVec;
+
+static void str_put(Str *b, const char *bytes, size_t count)
+{
+ if (b->n + count + 1 > b->cap) {
+ size_t cap = b->cap ? b->cap : 64;
+ while (cap < b->n + count + 1) cap *= 2;
+ b->s = (char *)xrealloc(b->s, cap);
+ b->cap = cap;
+ }
+ memcpy(b->s + b->n, bytes, count);
+ b->n += count;
+ b->s[b->n] = 0;
+}
+
+static void str_cp(Str *b, uint32_t cp)
+{
+ char u[4];
+ size_t n;
+ if (cp < 0x80) { u[0] = (char)cp; n = 1; }
+ else if (cp < 0x800) { u[0] = (char)(0xC0 | (cp >> 6)); u[1] = (char)(0x80 | (cp & 0x3F)); n = 2; }
+ else if (cp < 0x10000) {
+ u[0] = (char)(0xE0 | (cp >> 12)); u[1] = (char)(0x80 | ((cp >> 6) & 0x3F));
+ u[2] = (char)(0x80 | (cp & 0x3F)); n = 3;
+ } else {
+ u[0] = (char)(0xF0 | (cp >> 18)); u[1] = (char)(0x80 | ((cp >> 12) & 0x3F));
+ u[2] = (char)(0x80 | ((cp >> 6) & 0x3F)); u[3] = (char)(0x80 | (cp & 0x3F)); n = 4;
+ }
+ str_put(b, u, n);
+}
+
+static void ivec_push(IntVec *a, int x)
+{
+ if (a->n == a->cap) {
+ a->cap = a->cap ? a->cap * 2 : 64;
+ a->v = (int *)xrealloc(a->v, (size_t)a->cap * sizeof(int));
+ }
+ a->v[a->n++] = x;
+}
+
+/* One UTF-8 code point at s[*at] (< n). Bytes that are not valid UTF-8 come
+ * back one at a time as themselves; the gateway only ever sends valid UTF-8. */
+static uint32_t utf8_next(const unsigned char *s, size_t n, size_t *at)
+{
+ size_t i = *at;
+ unsigned char c = s[i];
+ uint32_t cp;
+ size_t w;
+ if (c < 0x80) { *at = i + 1; return c; }
+ if (c >= 0xC2 && c <= 0xDF) { cp = c & 0x1F; w = 2; }
+ else if (c >= 0xE0 && c <= 0xEF) { cp = c & 0x0F; w = 3; }
+ else if (c >= 0xF0 && c <= 0xF4) { cp = c & 0x07; w = 4; }
+ else { *at = i + 1; return c; }
+ if (i + w > n) { *at = i + 1; return c; }
+ for (size_t k = 1; k < w; k++) {
+ if ((s[i + k] & 0xC0) != 0x80) { *at = i + 1; return c; }
+ cp = (cp << 6) | (s[i + k] & 0x3F);
+ }
+ *at = i + w;
+ return cp;
+}
+
+/* ------------------------------------------------- Python's view of a text */
+
+static int in_ranges(const GlUniRange *r, int n, uint32_t cp)
+{
+ int lo = 0, hi = n - 1;
+ while (lo <= hi) {
+ int mid = (lo + hi) / 2;
+ if (cp < r[mid].lo) hi = mid - 1;
+ else if (cp > r[mid].hi) lo = mid + 1;
+ else return 1;
+ }
+ return 0;
+}
+
+#define NRANGES(t) ((int)(sizeof(t) / sizeof((t)[0])))
+
+static int py_word(uint32_t cp) /* \w of a str pattern */
+{
+ if (cp < 0x80) return (cp >= '0' && cp <= '9') || (cp >= 'a' && cp <= 'z') ||
+ (cp >= 'A' && cp <= 'Z') || cp == '_';
+ return in_ranges(gl_uni_word, NRANGES(gl_uni_word), cp);
+}
+
+static int py_space(uint32_t cp) /* \s of a str pattern: str.isspace() */
+{
+ return in_ranges(gl_uni_space, NRANGES(gl_uni_space), cp);
+}
+
+/* [a-z] under re.IGNORECASE: the ASCII letters plus the four code points whose
+ * case folding reaches them (U+0130, U+0131, U+017F, U+212A). */
+static int py_az(uint32_t cp)
+{
+ return (cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') ||
+ cp == 0x130 || cp == 0x131 || cp == 0x17F || cp == 0x212A;
+}
+
+static int py_digit_ascii(uint32_t cp) { return cp >= '0' && cp <= '9'; }
+
+/* A literal ASCII letter under re.IGNORECASE ('s' also matches U+017F). */
+static int py_lit(uint32_t cp, char want)
+{
+ if (cp == (uint32_t)want || (want >= 'a' && want <= 'z' && cp == (uint32_t)(want - 32))) return 1;
+ return want == 's' && cp == 0x17F;
+}
+
+static uint32_t py_lower1(uint32_t cp)
+{
+ if (cp < 0x80) return cp >= 'A' && cp <= 'Z' ? cp + 32 : cp;
+ int lo = 0, hi = NRANGES(gl_uni_lower) - 1;
+ while (lo <= hi) {
+ int mid = (lo + hi) / 2;
+ if (cp < gl_uni_lower[mid].cp) hi = mid - 1;
+ else if (cp > gl_uni_lower[mid].cp) lo = mid + 1;
+ else return gl_uni_lower[mid].lower;
+ }
+ return cp;
+}
+
+static int py_ignorable(uint32_t cp) { return in_ranges(gl_uni_ignorable, NRANGES(gl_uni_ignorable), cp); }
+static int py_cased(uint32_t cp) { return in_ranges(gl_uni_cased, NRANGES(gl_uni_cased), cp); }
+
+/* str.lower() of cps[0..n), appended to out as UTF-8. Capital sigma follows
+ * Python's handle_capital_sigma (the Final_Sigma context of Unicode 3.13). */
+static void py_lower(const uint32_t *cps, int n, Str *out)
+{
+ for (int i = 0; i < n; i++) {
+ uint32_t cp = cps[i];
+ if (cp == 0x130) { str_cp(out, 'i'); str_cp(out, 0x307); continue; }
+ if (cp == 0x3A3) {
+ int j = i - 1;
+ while (j >= 0 && py_ignorable(cps[j])) j--;
+ int final_sigma = j >= 0 && py_cased(cps[j]);
+ if (final_sigma && i + 1 < n) {
+ j = i + 1;
+ while (j < n && py_ignorable(cps[j])) j++;
+ final_sigma = j == n || !py_cased(cps[j]);
+ }
+ str_cp(out, final_sigma ? 0x3C2 : 0x3C3);
+ continue;
+ }
+ str_cp(out, py_lower1(cp));
+ }
+}
+
+/* ------------------------------------------- WhitespaceTokenSplitter */
+
+typedef struct { char **w; int n, cap; } Words;
+
+static void words_free(Words *w)
+{
+ for (int i = 0; i < w->n; i++) free(w->w[i]);
+ free(w->w);
+ memset(w, 0, sizeof(*w));
+}
+
+/* The pattern of processing/word_splitter.py, re.VERBOSE | re.IGNORECASE:
+ * (?:https?://[^\s]+|www\.[^\s]+)
+ * | [a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}
+ * | @[a-z0-9_]+
+ * | \w+(?:[-_]\w+)*
+ * | \S
+ * tried in that order at each position, as re.finditer does; returns the end
+ * of the match at p, or -1. */
+/* [^\s]+ from k: the end of the run, or -1 when it is empty */
+static int nonspace_run(const uint32_t *c, int n, int k)
+{
+ if (k >= n || py_space(c[k])) return -1;
+ while (k < n && !py_space(c[k])) k++;
+ return k;
+}
+
+/* "://" then [^\s]+ */
+static int url_rest(const uint32_t *c, int n, int k)
+{
+ if (k + 3 > n || c[k] != ':' || c[k + 1] != '/' || c[k + 2] != '/') return -1;
+ return nonspace_run(c, n, k + 3);
+}
+
+static int split_match(const uint32_t *c, int n, int p)
+{
+ /* https?://[^\s]+ (the 's' tried first, as the greedy ? does), www\.[^\s]+ */
+ if (p + 4 <= n && py_lit(c[p], 'h') && py_lit(c[p + 1], 't') && py_lit(c[p + 2], 't') &&
+ py_lit(c[p + 3], 'p')) {
+ int k = p + 4, e = -1;
+ if (k < n && py_lit(c[k], 's')) e = url_rest(c, n, k + 1);
+ if (e < 0) e = url_rest(c, n, k);
+ if (e >= 0) return e;
+ }
+ if (p + 4 <= n && py_lit(c[p], 'w') && py_lit(c[p + 1], 'w') && py_lit(c[p + 2], 'w') && c[p + 3] == '.') {
+ int e = nonspace_run(c, n, p + 4);
+ if (e >= 0) return e;
+ }
+ /* e-mail: the local part cannot contain '@', so only its longest run can be
+ * followed by one; the domain backtracks to the last ".xx" that fits */
+ {
+ int k = p;
+ while (k < n && (py_az(c[k]) || py_digit_ascii(c[k]) || c[k] == '.' || c[k] == '_' ||
+ c[k] == '%' || c[k] == '+' || c[k] == '-'))
+ k++;
+ if (k > p && k < n && c[k] == '@') {
+ int d0 = k + 1, d1 = d0;
+ while (d1 < n && (py_az(c[d1]) || py_digit_ascii(c[d1]) || c[d1] == '.' || c[d1] == '-')) d1++;
+ for (int split = d1 - 1; split >= d0 + 1; split--) {
+ if (c[split] != '.') continue;
+ int e = split + 1;
+ while (e < n && py_az(c[e])) e++;
+ if (e - (split + 1) >= 2) return e;
+ }
+ }
+ }
+ /* @handle */
+ if (c[p] == '@') {
+ int k = p + 1;
+ while (k < n && (py_az(c[k]) || py_digit_ascii(c[k]) || c[k] == '_')) k++;
+ if (k > p + 1) return k;
+ }
+ /* \w+(?:[-_]\w+)* */
+ if (py_word(c[p])) {
+ int k = p + 1;
+ for (;;) {
+ while (k < n && py_word(c[k])) k++;
+ if (k + 1 < n && (c[k] == '-' || c[k] == '_') && py_word(c[k + 1])) { k += 1; continue; }
+ break;
+ }
+ return k;
+ }
+ /* \S */
+ if (!py_space(c[p])) return p + 1;
+ return -1;
+}
+
+/* The words of `text`, lower-cased, as WhitespaceTokenSplitter yields them. */
+static void split_words(const char *text, size_t len, Words *out)
+{
+ memset(out, 0, sizeof(*out));
+ int n = 0, cap = 64;
+ uint32_t *c = (uint32_t *)xmalloc((size_t)cap * sizeof(uint32_t));
+ for (size_t at = 0; at < len;) {
+ uint32_t cp = utf8_next((const unsigned char *)text, len, &at);
+ if (n == cap) { cap *= 2; c = (uint32_t *)xrealloc(c, (size_t)cap * sizeof(uint32_t)); }
+ c[n++] = cp;
+ }
+ for (int p = 0; p < n;) {
+ int e = split_match(c, n, p);
+ if (e < 0) { p++; continue; }
+ Str w = {0};
+ py_lower(c + p, e - p, &w);
+ if (!w.s) str_put(&w, "", 0);
+ if (out->n == out->cap) {
+ out->cap = out->cap ? out->cap * 2 : 64;
+ out->w = (char **)xrealloc(out->w, (size_t)out->cap * sizeof(char *));
+ }
+ out->w[out->n++] = w.s;
+ p = e;
+ }
+ free(c);
+}
+
+/* -------------------------------------------------------------- tokenizer */
+
+typedef struct { char *s; int len, id, normalized; } AddedTok;
+
+typedef struct {
+ int n; /* Unigram pieces */
+ char **piece;
+ int *plen;
+ double *score;
+ int *slot; /* open addressing over the pieces, -1 empty */
+ uint64_t mask;
+ int max_piece; /* longest piece, in bytes */
+ double unk_score; /* min score - 10 (Unigram's K_UNK_PENALTY) */
+ int unk_id;
+ AddedTok *added;
+ int n_added;
+} GlTok;
+
+static uint64_t fnv1a(const char *s, int n)
+{
+ uint64_t h = 1469598103934665603ULL;
+ for (int i = 0; i < n; i++) { h ^= (unsigned char)s[i]; h *= 1099511628211ULL; }
+ return h;
+}
+
+static int piece_find(const GlTok *T, const char *s, int n)
+{
+ uint64_t h = fnv1a(s, n) & T->mask;
+ for (;;) {
+ int id = T->slot[h];
+ if (id < 0) return -1;
+ if (T->plen[id] == n && !memcmp(T->piece[id], s, (size_t)n)) return id;
+ h = (h + 1) & T->mask;
+ }
+}
+
+/* White_Space, which both the normalizer's \s (Oniguruma) and its Strip
+ * (Rust's char::is_whitespace) mean. */
+static int uni_white(uint32_t cp)
+{
+ return (cp >= 0x9 && cp <= 0xD) || cp == 0x20 || cp == 0x85 || cp == 0xA0 || cp == 0x1680 ||
+ (cp >= 0x2000 && cp <= 0x200A) || cp == 0x2028 || cp == 0x2029 || cp == 0x202F ||
+ cp == 0x205F || cp == 0x3000;
+}
+
+static void load_tokenizer(GlTok *T, const char *dir)
+{
+ memset(T, 0, sizeof(*T));
+ jval *tj = read_json(dir, "tokenizer.json");
+ jval *model = json_get(tj, "model");
+ if (!model || strcmp(str_or(model, "type", ""), "Unigram"))
+ die("tokenizer.json: only a Unigram model is supported (this is %s)",
+ model ? str_or(model, "type", "unknown") : "missing");
+ if (bool_or(model, "byte_fallback", 0)) die("tokenizer.json: byte_fallback is not supported");
+ /* the normalizer of the release: Replace(\s{2,}|[\n\r\t] -> " "), NFC, Strip(right) */
+ jval *norm = json_get(tj, "normalizer"), *seq = norm ? json_get(norm, "normalizers") : NULL;
+ int ok = norm && !strcmp(str_or(norm, "type", ""), "Sequence") && seq && seq->t == J_ARR && seq->len == 3;
+ if (ok) {
+ jval *rep = seq->kids[0], *pat = json_get(rep, "pattern");
+ ok = !strcmp(str_or(rep, "type", ""), "Replace") && pat &&
+ !strcmp(str_or(pat, "Regex", ""), "\\s{2,}|[\\n\\r\\t]") &&
+ !strcmp(str_or(rep, "content", ""), " ") &&
+ !strcmp(str_or(seq->kids[1], "type", ""), "NFC") &&
+ !strcmp(str_or(seq->kids[2], "type", ""), "Strip") &&
+ !bool_or(seq->kids[2], "strip_left", 1) && bool_or(seq->kids[2], "strip_right", 0);
+ }
+ if (!ok) die("tokenizer.json: expected the normalizer Sequence[Replace(\\s{2,}|[\\n\\r\\t] -> \" \"), "
+ "NFC, Strip(right)] of the DeBERTa-v3 tokenizer");
+ jval *pre = json_get(tj, "pre_tokenizer");
+ if (pre && !strcmp(str_or(pre, "type", ""), "Sequence")) {
+ jval *ps = json_get(pre, "pretokenizers");
+ pre = ps && ps->t == J_ARR && ps->len == 1 ? ps->kids[0] : NULL;
+ }
+ if (!pre || strcmp(str_or(pre, "type", ""), "Metaspace") || strcmp(str_or(pre, "replacement", ""), "\xE2\x96\x81") ||
+ strcmp(str_or(pre, "prepend_scheme", "always"), "always") || !bool_or(pre, "split", 1))
+ die("tokenizer.json: expected a Metaspace pre-tokenizer (replacement U+2581, prepend always, split)");
+ jval *vocab = json_get(model, "vocab");
+ if (!vocab || vocab->t != J_ARR || vocab->len < 1) die("tokenizer.json: Unigram vocab missing");
+ T->n = vocab->len;
+ T->piece = (char **)xcalloc((size_t)T->n, sizeof(char *));
+ T->plen = (int *)xcalloc((size_t)T->n, sizeof(int));
+ T->score = (double *)xcalloc((size_t)T->n, sizeof(double));
+ uint64_t size = 1;
+ while (size < (uint64_t)T->n * 2) size <<= 1;
+ T->mask = size - 1;
+ T->slot = (int *)xmalloc((size_t)size * sizeof(int));
+ for (uint64_t i = 0; i < size; i++) T->slot[i] = -1;
+ double min_score = INFINITY;
+ for (int i = 0; i < T->n; i++) {
+ jval *e = vocab->kids[i];
+ if (!e || e->t != J_ARR || e->len != 2 || e->kids[0]->t != J_STR || e->kids[1]->t != J_NUM)
+ die("tokenizer.json: vocab entry %d is not [piece, score]", i);
+ T->piece[i] = strdup(e->kids[0]->str);
+ T->plen[i] = (int)strlen(T->piece[i]);
+ T->score[i] = e->kids[1]->num;
+ if (T->score[i] < min_score) min_score = T->score[i];
+ if (T->plen[i] > T->max_piece) T->max_piece = T->plen[i];
+ /* a piece listed twice keeps its last id, as the reference's map does */
+ uint64_t h = fnv1a(T->piece[i], T->plen[i]) & T->mask;
+ for (;;) {
+ int id = T->slot[h];
+ if (id < 0 || (T->plen[id] == T->plen[i] && !memcmp(T->piece[id], T->piece[i], (size_t)T->plen[i]))) {
+ T->slot[h] = i;
+ break;
+ }
+ h = (h + 1) & T->mask;
+ }
+ }
+ T->unk_score = min_score - 10.0;
+ jval *unk = json_get(model, "unk_id");
+ T->unk_id = unk && unk->t == J_NUM ? (int)unk->num : -1;
+ if (T->unk_id < 0 || T->unk_id >= T->n) die("tokenizer.json: the Unigram model needs an unk_id");
+ jval *added = json_get(tj, "added_tokens");
+ T->added = (AddedTok *)xcalloc((size_t)(added && added->t == J_ARR ? added->len : 0) + 1, sizeof(AddedTok));
+ for (int i = 0; added && added->t == J_ARR && i < added->len; i++) {
+ jval *a = added->kids[i];
+ const char *content = str_or(a, "content", NULL);
+ jval *id = json_get(a, "id");
+ if (!content || !content[0] || !id || id->t != J_NUM) continue;
+ if (bool_or(a, "lstrip", 0) || bool_or(a, "rstrip", 0) || bool_or(a, "single_word", 0))
+ die("tokenizer.json: added token %s strips whitespace, which this engine does not implement", content);
+ AddedTok *t = &T->added[T->n_added++];
+ t->s = strdup(content);
+ t->len = (int)strlen(content);
+ t->id = (int)id->num;
+ t->normalized = bool_or(a, "normalized", 0);
+ }
+ json_free(tj);
+}
+
+/* The longest added token of the given kind starting at s[p], or -1. */
+static int added_at(const GlTok *T, const char *s, size_t n, size_t p, int normalized)
+{
+ int best = -1;
+ for (int k = 0; k < T->n_added; k++) {
+ const AddedTok *a = &T->added[k];
+ if (a->normalized != normalized || (size_t)a->len > n - p) continue;
+ if (!memcmp(s + p, a->s, (size_t)a->len) && (best < 0 || a->len > T->added[best].len)) best = k;
+ }
+ return best;
+}
+
+/* Unigram.encode_optimized on one pre-token: the best-scoring segmentation,
+ * ties kept by the first candidate (shorter piece, earlier start); a
+ * character no single piece covers costs unk_score, and adjacent unknowns
+ * come out as one [UNK]. */
+static void unigram(const GlTok *T, const char *s, int n, IntVec *out)
+{
+ if (n <= 0) return;
+ double *best = (double *)xmalloc((size_t)(n + 1) * sizeof(double));
+ int *from = (int *)xmalloc((size_t)(n + 1) * sizeof(int));
+ int *id = (int *)xmalloc((size_t)(n + 1) * sizeof(int));
+ for (int i = 0; i <= n; i++) { from[i] = -1; best[i] = 0; id[i] = -1; }
+ from[0] = 0;
+ for (int start = 0; start < n;) {
+ size_t at = (size_t)start;
+ utf8_next((const unsigned char *)s, (size_t)n, &at);
+ int mblen = (int)at - start;
+ double here = best[start];
+ int single = 0;
+ int limit = n - start < T->max_piece ? n - start : T->max_piece;
+ for (int len = 1; len <= limit; len++) {
+ int pid = piece_find(T, s + start, len);
+ if (pid < 0) continue;
+ int key = start + len;
+ double cand = here + T->score[pid];
+ if (from[key] < 0 || cand > best[key]) { best[key] = cand; from[key] = start; id[key] = pid; }
+ if (len == mblen) single = 1;
+ }
+ if (!single) {
+ int key = start + mblen;
+ double cand = here + T->unk_score;
+ if (from[key] < 0 || cand > best[key]) { best[key] = cand; from[key] = start; id[key] = T->unk_id; }
+ }
+ start += mblen;
+ }
+ /* backtrack, fusing runs of [UNK] */
+ int count = 0;
+ int *rev = (int *)xmalloc((size_t)(n + 1) * sizeof(int));
+ for (int end = n; end > 0;) {
+ int start = from[end];
+ if (start < 0 || start >= end) die("unigram: broken lattice");
+ if (id[end] == T->unk_id && count > 0 && rev[count - 1] == T->unk_id) { end = start; continue; }
+ rev[count++] = id[end];
+ end = start;
+ }
+ for (int i = count - 1; i >= 0; i--) ivec_push(out, rev[i]);
+ free(rev); free(best); free(from); free(id);
+}
+
+/* Metaspace (prepend always, split) and Unigram on one normalized text. */
+static void metaspace_unigram(const GlTok *T, const char *s, size_t n, IntVec *out)
+{
+ if (!n) return;
+ Str m = {0};
+ if (!(n >= 3 && (unsigned char)s[0] == 0xE2 && (unsigned char)s[1] == 0x96 && (unsigned char)s[2] == 0x81) &&
+ s[0] != ' ')
+ str_put(&m, "\xE2\x96\x81", 3);
+ for (size_t i = 0; i < n; i++) {
+ if (s[i] == ' ') str_put(&m, "\xE2\x96\x81", 3);
+ else str_put(&m, s + i, 1);
+ }
+ /* split before every U+2581, the delimiter kept with what follows it */
+ size_t start = 0;
+ for (size_t i = 3; i + 3 <= m.n; i++) {
+ if ((unsigned char)m.s[i] == 0xE2 && (unsigned char)m.s[i + 1] == 0x96 && (unsigned char)m.s[i + 2] == 0x81) {
+ unigram(T, m.s + start, (int)(i - start), out);
+ start = i;
+ i += 2;
+ }
+ }
+ unigram(T, m.s + start, (int)(m.n - start), out);
+ free(m.s);
+}
+
+/* Replace(\s{2,}|[\n\r\t] -> " "), NFC, Strip(right); then the normalized
+ * added tokens, then Metaspace + Unigram on what is left. */
+static void encode_segment(const GlTok *T, const char *s, size_t n, IntVec *out)
+{
+ Str r = {0};
+ int ascii = 1;
+ for (size_t at = 0; at < n;) {
+ size_t here = at;
+ uint32_t cp = utf8_next((const unsigned char *)s, n, &at);
+ if (cp >= 0x80) ascii = 0;
+ if (!uni_white(cp)) { str_put(&r, s + here, at - here); continue; }
+ size_t run_end = at;
+ int run = 1;
+ while (run_end < n) {
+ size_t peek = run_end;
+ uint32_t next = utf8_next((const unsigned char *)s, n, &peek);
+ if (!uni_white(next)) break;
+ run++;
+ run_end = peek;
+ }
+ if (run >= 2) { str_put(&r, " ", 1); at = run_end; }
+ else if (cp == '\n' || cp == '\r' || cp == '\t') str_put(&r, " ", 1);
+ else str_put(&r, s + here, at - here);
+ }
+ char *norm = r.s ? r.s : NULL;
+ size_t norm_len = r.n;
+ if (!ascii && norm_len) {
+ char *nfc = NULL;
+ size_t nfc_len = 0;
+ if (q38_nfc_normalize(r.s, r.n, &nfc, &nfc_len) != 0) die("NFC normalization failed");
+ free(r.s);
+ norm = nfc;
+ norm_len = nfc_len;
+ }
+ /* strip trailing White_Space */
+ while (norm_len > 0) {
+ size_t k = norm_len - 1;
+ while (k > 0 && ((unsigned char)norm[k] & 0xC0) == 0x80) k--;
+ size_t at = k;
+ uint32_t cp = utf8_next((const unsigned char *)norm, norm_len, &at);
+ if (at != norm_len || !uni_white(cp)) break;
+ norm_len = k;
+ }
+ size_t seg = 0;
+ for (size_t p = 0; p < norm_len;) {
+ int a = added_at(T, norm, norm_len, p, 1);
+ if (a < 0) { p++; continue; }
+ metaspace_unigram(T, norm + seg, p - seg, out);
+ ivec_push(out, T->added[a].id);
+ p += (size_t)T->added[a].len;
+ seg = p;
+ }
+ metaspace_unigram(T, norm + seg, norm_len - seg, out);
+ free(norm);
+}
+
+/* tokenizer.tokenize(text) as ids: the added tokens split out of the raw text
+ * (leftmost, longest), every other segment normalized and encoded. */
+static void gl_encode(const GlTok *T, const char *s, size_t n, IntVec *out)
+{
+ size_t seg = 0;
+ for (size_t p = 0; p < n;) {
+ int a = added_at(T, s, n, p, 0);
+ if (a < 0) { p++; continue; }
+ encode_segment(T, s + seg, p - seg, out);
+ ivec_push(out, T->added[a].id);
+ p += (size_t)T->added[a].len;
+ seg = p;
+ }
+ encode_segment(T, s + seg, n - seg, out);
+}
+
+static int added_id(const GlTok *T, const char *content)
+{
+ for (int k = 0; k < T->n_added; k++)
+ if (!strcmp(T->added[k].s, content)) return T->added[k].id;
+ return -1;
+}
+
+/* ------------------------------------------------------------------ model */
+
+typedef struct {
+ QiMat wqkv; float *bqkv; /* query_proj, key_proj, value_proj stacked: [3d][d] */
+ QiMat wo; float *bo; /* attention.output.dense */
+ float *ln1_w, *ln1_b; /* attention.output.LayerNorm */
+ QiMat wi; float *bi; /* intermediate.dense */
+ QiMat wo2; float *bo2; /* output.dense */
+ float *ln2_w, *ln2_b; /* output.LayerNorm */
+ float *pos_q, *pos_k; /* LayerNorm(rel_embeddings) through query_proj / key_proj: [2*span][d] */
+} GlLayer;
+
+typedef struct {
+ int d, layers, heads, hd, inter, vocab;
+ int span; /* pos_ebd_size: relative positions are clamped to [-span, span) */
+ int bucket_size, max_position; /* make_log_bucket_position's arguments */
+ int c2p, p2c; /* which disentangled terms pos_att_type enables */
+ float eps;
+ float *tok_emb, *emb_ln_w, *emb_ln_b;
+ GlLayer *L;
+ QiMat cls1; float *cls1_b; /* classifier.0: [2d][d] */
+ float *cls2_w; float cls2_b; /* classifier.2: [1][2d] */
+ int cls_hidden;
+ int max_len; /* tokens per request sequence (COLI_GLINER_MAX_LEN) */
+ GlTok tok;
+ int id_p, id_l, id_sep_struct, id_sep_text;
+ char model_name[256];
+} Gl;
+
+static float *load_f32(shards *S, const char *name, int64_t expect)
+{
+ st_tensor *t = st_find(S, name);
+ if (!t) die("model.safetensors has no tensor %s", name);
+ if (expect >= 0 && t->numel != expect)
+ die("%s has %lld elements, expected %lld", name, (long long)t->numel, (long long)expect);
+ float *out = (float *)xmalloc((size_t)t->numel * sizeof(float));
+ st_read_f32(S, name, out, 0);
+ return out;
+}
+
+static void layernorm(float *out, const float *x, const float *w, const float *b, int rows, int d, float eps)
+{
+ #pragma omp parallel for schedule(static)
+ for (int r = 0; r < rows; r++) {
+ const float *xr = x + (size_t)r * d;
+ float *o = out + (size_t)r * d;
+ double mean = 0, var = 0;
+ for (int i = 0; i < d; i++) mean += xr[i];
+ mean /= d;
+ for (int i = 0; i < d; i++) { double c = xr[i] - mean; var += c * c; }
+ var /= d;
+ float rstd = (float)(1.0 / sqrt(var + eps));
+ for (int i = 0; i < d; i++) {
+ float v = (float)(xr[i] - mean) * rstd * w[i];
+ o[i] = b ? v + b[i] : v;
+ }
+ }
+}
+
+static int pos_att_has(jval *types, const char *name)
+{
+ if (!types) return 0;
+ if (types->t == J_STR) return strstr(types->str, name) != NULL; /* "p2c|c2p" */
+ for (int i = 0; types->t == J_ARR && i < types->len; i++)
+ if (types->kids[i]->t == J_STR && !strcmp(types->kids[i]->str, name)) return 1;
+ return 0;
+}
+
+static void load_model(Gl *M, const char *dir)
+{
+ memset(M, 0, sizeof(*M));
+ /* config.json: the GLiNER2 extractor */
+ jval *cfg = read_json(dir, "config.json");
+ if (strcmp(str_or(cfg, "model_type", ""), "extractor"))
+ die("config.json: model_type must be extractor (a GLiNER2 checkpoint)");
+ const char *arch = str_or(cfg, "architecture", "span");
+ if (strcmp(arch, "span"))
+ die("config.json: architecture %s is not supported (only GLiNER2's span architecture)", arch);
+ const char *pooling = str_or(cfg, "token_pooling", "first");
+ if (strcmp(pooling, "first"))
+ die("config.json: token_pooling %s is not supported (only first)", pooling);
+ snprintf(M->model_name, sizeof(M->model_name), "%s", str_or(cfg, "model_name", "gliner2"));
+ json_free(cfg);
+
+ /* encoder_config/config.json: DeBERTa-v2/v3 */
+ jval *ec = read_json(dir, "encoder_config/config.json");
+ if (strcmp(str_or(ec, "model_type", ""), "deberta-v2"))
+ die("encoder_config/config.json: model_type must be deberta-v2");
+ M->d = (int)num_or(ec, "hidden_size", 0);
+ M->layers = (int)num_or(ec, "num_hidden_layers", 0);
+ M->heads = (int)num_or(ec, "num_attention_heads", 0);
+ M->inter = (int)num_or(ec, "intermediate_size", 0);
+ M->vocab = (int)num_or(ec, "vocab_size", 0);
+ M->eps = (float)num_or(ec, "layer_norm_eps", 1e-7);
+ if (M->d < 1 || M->layers < 1 || M->heads < 1 || M->d % M->heads || M->inter < 1 || M->vocab < 1 ||
+ M->d > 16384 || M->layers > 256 || M->inter > 1 << 18)
+ die("encoder_config/config.json: invalid geometry");
+ M->hd = M->d / M->heads;
+ if (json_get(ec, "attention_head_size") && (int)num_or(ec, "attention_head_size", 0) != M->hd)
+ die("encoder_config/config.json: attention_head_size other than hidden/heads is not supported");
+ if (strcmp(str_or(ec, "hidden_act", "gelu"), "gelu"))
+ die("encoder_config/config.json: hidden_act %s is not supported (only gelu)", str_or(ec, "hidden_act", ""));
+ if (bool_or(ec, "position_biased_input", 1))
+ die("encoder_config/config.json: absolute position embeddings (position_biased_input) are not supported");
+ if (num_or(ec, "type_vocab_size", 0) > 0) die("encoder_config/config.json: token type embeddings are not supported");
+ if (json_get(ec, "embedding_size") && (int)num_or(ec, "embedding_size", M->d) != M->d)
+ die("encoder_config/config.json: an embedding_size other than hidden_size is not supported");
+ if (num_or(ec, "conv_kernel_size", 0) > 0) die("encoder_config/config.json: the convolution layer is not supported");
+ if (!bool_or(ec, "relative_attention", 0)) die("encoder_config/config.json: relative_attention must be true");
+ if (!bool_or(ec, "share_att_key", 0)) die("encoder_config/config.json: share_att_key must be true");
+ jval *types = json_get(ec, "pos_att_type");
+ M->c2p = pos_att_has(types, "c2p");
+ M->p2c = pos_att_has(types, "p2c");
+ int max_rel = (int)num_or(ec, "max_relative_positions", -1);
+ if (max_rel < 1) max_rel = (int)num_or(ec, "max_position_embeddings", 512);
+ int buckets = (int)num_or(ec, "position_buckets", -1);
+ M->span = buckets > 0 ? buckets : max_rel;
+ M->bucket_size = buckets;
+ M->max_position = max_rel;
+ if (M->span < 1 || M->span > 1 << 16) die("encoder_config/config.json: invalid relative span");
+ const char *norm_rel = str_or(ec, "norm_rel_ebd", "none");
+ int rel_ln = strstr(norm_rel, "layer_norm") != NULL;
+ json_free(ec);
+
+ /* tokenizer */
+ load_tokenizer(&M->tok, dir);
+ M->id_p = added_id(&M->tok, "[P]");
+ M->id_l = added_id(&M->tok, "[L]");
+ M->id_sep_struct = added_id(&M->tok, "[SEP_STRUCT]");
+ M->id_sep_text = added_id(&M->tok, "[SEP_TEXT]");
+ if (M->id_p < 0 || M->id_l < 0 || M->id_sep_struct < 0 || M->id_sep_text < 0 || added_id(&M->tok, "[DESCRIPTION]") < 0)
+ die("tokenizer.json: GLiNER2's special tokens ([P], [L], [SEP_STRUCT], [SEP_TEXT], [DESCRIPTION]) "
+ "are not added tokens");
+
+ /* weights: the encoder and the classifier; span_rep, count_pred and
+ * count_embed serve extraction and are not read */
+ shards S;
+ st_init(&S, dir);
+ int d = M->d, I = M->inter;
+ st_tensor *emb = st_find(&S, "encoder.embeddings.word_embeddings.weight");
+ if (!emb || emb->rank != 2 || emb->shape[1] != d) die("encoder.embeddings.word_embeddings.weight: expected [vocab, %d]", d);
+ M->vocab = (int)emb->shape[0];
+ for (int k = 0; k < M->tok.n_added; k++)
+ if (M->tok.added[k].id < 0 || M->tok.added[k].id >= M->vocab) die("tokenizer.json: added token id outside the embeddings");
+ if (M->tok.n > M->vocab) die("tokenizer.json: %d pieces for %d embedding rows", M->tok.n, M->vocab);
+ M->tok_emb = load_f32(&S, "encoder.embeddings.word_embeddings.weight", (int64_t)M->vocab * d);
+ M->emb_ln_w = load_f32(&S, "encoder.embeddings.LayerNorm.weight", d);
+ M->emb_ln_b = load_f32(&S, "encoder.embeddings.LayerNorm.bias", d);
+ float *rel = load_f32(&S, "encoder.encoder.rel_embeddings.weight", (int64_t)2 * M->span * d);
+ if (rel_ln) {
+ float *w = load_f32(&S, "encoder.encoder.LayerNorm.weight", d);
+ float *b = load_f32(&S, "encoder.encoder.LayerNorm.bias", d);
+ layernorm(rel, rel, w, b, 2 * M->span, d, M->eps);
+ free(w); free(b);
+ }
+ M->L = (GlLayer *)xcalloc((size_t)M->layers, sizeof(GlLayer));
+ char n[256];
+ for (int l = 0; l < M->layers; l++) {
+ GlLayer *E = &M->L[l];
+#define NAME(fmt) (snprintf(n, sizeof(n), "encoder.encoder.layer.%d." fmt, l), n)
+ float *wqkv = (float *)xmalloc((size_t)3 * d * d * sizeof(float));
+ E->bqkv = (float *)xmalloc((size_t)3 * d * sizeof(float));
+ const char *parts[3] = {"query_proj", "key_proj", "value_proj"};
+ for (int part = 0; part < 3; part++) {
+ char wname[256], bname[256];
+ snprintf(wname, sizeof(wname), "encoder.encoder.layer.%d.attention.self.%s.weight", l, parts[part]);
+ snprintf(bname, sizeof(bname), "encoder.encoder.layer.%d.attention.self.%s.bias", l, parts[part]);
+ float *w = load_f32(&S, wname, (int64_t)d * d), *b = load_f32(&S, bname, d);
+ memcpy(wqkv + (size_t)part * d * d, w, (size_t)d * d * sizeof(float));
+ memcpy(E->bqkv + (size_t)part * d, b, (size_t)d * sizeof(float));
+ free(w); free(b);
+ }
+ E->wqkv = (QiMat){QI_F32, 3 * d, d, wqkv, NULL, 0};
+ E->wo = (QiMat){QI_F32, d, d, load_f32(&S, NAME("attention.output.dense.weight"), (int64_t)d * d), NULL, 0};
+ E->bo = load_f32(&S, NAME("attention.output.dense.bias"), d);
+ E->ln1_w = load_f32(&S, NAME("attention.output.LayerNorm.weight"), d);
+ E->ln1_b = load_f32(&S, NAME("attention.output.LayerNorm.bias"), d);
+ E->wi = (QiMat){QI_F32, I, d, load_f32(&S, NAME("intermediate.dense.weight"), (int64_t)I * d), NULL, 0};
+ E->bi = load_f32(&S, NAME("intermediate.dense.bias"), I);
+ E->wo2 = (QiMat){QI_F32, d, I, load_f32(&S, NAME("output.dense.weight"), (int64_t)d * I), NULL, 0};
+ E->bo2 = load_f32(&S, NAME("output.dense.bias"), d);
+ E->ln2_w = load_f32(&S, NAME("output.LayerNorm.weight"), d);
+ E->ln2_b = load_f32(&S, NAME("output.LayerNorm.bias"), d);
+#undef NAME
+ /* DisentangledSelfAttention.disentangled_attention_bias with
+ * share_att_key: pos_query_layer = query_proj(rel), pos_key_layer =
+ * key_proj(rel). The same for every request: computed here, once. */
+ QiMat wq = {QI_F32, d, d, wqkv, NULL, 0}, wk = {QI_F32, d, d, wqkv + (size_t)d * d, NULL, 0};
+ E->pos_q = (float *)xmalloc((size_t)2 * M->span * d * sizeof(float));
+ E->pos_k = (float *)xmalloc((size_t)2 * M->span * d * sizeof(float));
+ qi_gemm(E->pos_q, rel, 2 * M->span, &wq, E->bqkv);
+ qi_gemm(E->pos_k, rel, 2 * M->span, &wk, E->bqkv + d);
+ }
+ free(rel);
+ st_tensor *c0 = st_find(&S, "classifier.0.weight");
+ if (!c0 || c0->rank != 2 || c0->shape[1] != d) die("classifier.0.weight: expected [hidden, %d]", d);
+ M->cls_hidden = (int)c0->shape[0];
+ M->cls1 = (QiMat){QI_F32, M->cls_hidden, d, load_f32(&S, "classifier.0.weight", (int64_t)M->cls_hidden * d), NULL, 0};
+ M->cls1_b = load_f32(&S, "classifier.0.bias", M->cls_hidden);
+ M->cls2_w = load_f32(&S, "classifier.2.weight", M->cls_hidden);
+ float *b2 = load_f32(&S, "classifier.2.bias", 1);
+ M->cls2_b = b2[0];
+ free(b2);
+ st_destroy(&S);
+
+ M->max_len = 4096;
+ const char *env = getenv("COLI_GLINER_MAX_LEN");
+ if (env && atoi(env) > 0) M->max_len = atoi(env);
+}
+
+/* ------------------------------------------------------------- the forward */
+
+/* make_log_bucket_position, in float32 like the reference (checked against
+ * torch for every |relative position| up to 200000). */
+static int log_bucket(int rel, int bucket_size, int max_position)
+{
+ int mid = bucket_size / 2;
+ int a = rel < 0 ? -rel : rel;
+ if (a <= mid) return rel;
+ float lp = ceilf(logf((float)a / (float)mid) / logf((float)(max_position - 1) / (float)mid) *
+ (float)(mid - 1)) + (float)mid;
+ return rel < 0 ? -(int)lp : (int)lp;
+}
+
+static inline float gelu(float x) { return 0.5f * x * (1.0f + erff(x * 0.70710678118654752f)); }
+
+static void add_rows(float *x, const float *y, size_t n)
+{
+ #pragma omp parallel for schedule(static)
+ for (size_t i = 0; i < n; i++) x[i] += y[i];
+}
+
+/* DisentangledSelfAttention over one sequence of T rows. qkv rows are
+ * [q | k | v], heads side by side. With delta = i - j and
+ * r = clamp(bucket(delta) + span, 0, 2 span - 1), the score of key j for
+ * query i is
+ * (q_i . k_j + q_i . pos_k[r] + k_j . pos_q[r]) / sqrt(hd * (1 + c2p + p2c))
+ * (c2p is the second term, p2c the third: the reference gathers p2c at
+ * -bucket(j - i), which is the same r because the bucket is odd). */
+typedef struct {
+ float *p2c; /* [H][T][2 span]: k_j . pos_q[r], every head */
+ float *vt; /* [H][hd][T]: the values, transposed per head */
+ int *ridx; /* [2T - 1]: r for every delta = i - j */
+} AttnScratch;
+
+/* Query rows per task of the attention: a task is one head and ATT_BLOCK rows. */
+#define ATT_BLOCK 16
+
+/* DisentangledSelfAttention over one sequence of T rows. qkv rows are
+ * [q | k | v], heads side by side. With delta = i - j and
+ * r = clamp(bucket(delta) + span, 0, 2 span - 1), the score of key j for
+ * query i is
+ * (q_i . k_j + q_i . pos_k[r] + k_j . pos_q[r]) / sqrt(hd * (1 + c2p + p2c))
+ * c2p is the second term and p2c the third: the reference gathers p2c at
+ * -bucket(j - i), which is the same r because the bucket is odd.
+ *
+ * Two parallel loops per layer, whatever T: the first projects every key on
+ * pos_q and transposes the values, the second runs (head, block of query
+ * rows) tasks, each with its own products (qi_gemm on one thread). A loop of
+ * small parallel regions per head would be quicker on an idle machine and
+ * collapses on a busy one, where every region waits for its slowest thread. */
+static void attention(const Gl *M, const GlLayer *E, const float *qkv, float *out, int T, AttnScratch *A)
+{
+ int d = M->d, H = M->heads, hd = M->hd, R = 2 * M->span;
+ int sf = 1 + M->c2p + M->p2c;
+ const float inv = 1.0f / sqrtf((float)(hd * sf));
+ int *ridx = A->ridx;
+ for (int delta = -(T - 1); delta <= T - 1; delta++) {
+ int b = M->bucket_size > 0 && M->max_position > 0 ? log_bucket(delta, M->bucket_size, M->max_position) : delta;
+ int r = b + M->span;
+ ridx[delta + T - 1] = r < 0 ? 0 : r > R - 1 ? R - 1 : r;
+ }
+ int blocks = (T + ATT_BLOCK - 1) / ATT_BLOCK;
+ #pragma omp parallel for schedule(dynamic, 1)
+ for (int task = 0; task < H * blocks; task++) {
+ int h = task / blocks, j0 = (task % blocks) * ATT_BLOCK;
+ int n = T - j0 < ATT_BLOCK ? T - j0 : ATT_BLOCK;
+ if (M->p2c) {
+ QiMat Pq = {QI_F32, R, hd, E->pos_q + (size_t)h * hd, NULL, d};
+ qi_gemm_ld(A->p2c + ((size_t)h * T + j0) * R, R, qkv + (size_t)j0 * 3 * d + d + (size_t)h * hd,
+ 3 * d, n, &Pq, NULL);
+ }
+ float *vt = A->vt + (size_t)h * hd * T;
+ for (int j = j0; j < j0 + n; j++) {
+ const float *v = qkv + (size_t)j * 3 * d + 2 * d + (size_t)h * hd;
+ for (int t = 0; t < hd; t++) vt[(size_t)t * T + j] = v[t];
+ }
+ }
+ #pragma omp parallel
+ {
+ float *score = (float *)xmalloc((size_t)ATT_BLOCK * T * sizeof(float));
+ float *c2p = (float *)xmalloc((size_t)ATT_BLOCK * R * sizeof(float));
+ #pragma omp for schedule(dynamic, 1)
+ for (int task = 0; task < H * blocks; task++) {
+ int h = task / blocks, i0 = (task % blocks) * ATT_BLOCK;
+ int n = T - i0 < ATT_BLOCK ? T - i0 : ATT_BLOCK;
+ const float *q = qkv + (size_t)i0 * 3 * d + (size_t)h * hd;
+ QiMat Kh = {QI_F32, T, hd, qkv + d + (size_t)h * hd, NULL, 3 * d};
+ qi_gemm_ld(score, T, q, 3 * d, n, &Kh, NULL);
+ if (M->c2p) {
+ QiMat Pk = {QI_F32, R, hd, E->pos_k + (size_t)h * hd, NULL, d};
+ qi_gemm_ld(c2p, R, q, 3 * d, n, &Pk, NULL);
+ }
+ const float *p2c = A->p2c + (size_t)h * T * R;
+ for (int ii = 0; ii < n; ii++) {
+ int i = i0 + ii;
+ float *s = score + (size_t)ii * T;
+ const float *c = c2p + (size_t)ii * R;
+ const int *ri = ridx + i + T - 1; /* ri[-j] is r for (i, j) */
+ float mx = -INFINITY;
+ for (int j = 0; j < T; j++) {
+ int r = ri[-j];
+ float x = s[j];
+ if (M->c2p) x += c[r];
+ if (M->p2c) x += p2c[(size_t)j * R + r];
+ x *= inv;
+ s[j] = x;
+ if (x > mx) mx = x;
+ }
+ double sum = 0;
+ for (int j = 0; j < T; j++) { float e = expf(s[j] - mx); s[j] = e; sum += e; }
+ float norm = (float)(1.0 / sum);
+ for (int j = 0; j < T; j++) s[j] *= norm;
+ }
+ QiMat Vt = {QI_F32, hd, T, A->vt + (size_t)h * hd * T, NULL, 0};
+ qi_gemm_ld(out + (size_t)i0 * d + (size_t)h * hd, d, score, T, n, &Vt, NULL);
+ }
+ free(score); free(c2p);
+ }
+}
+
+/* DebertaV2Model.forward on ids[0..T), then the classifier at the rows in
+ * marks[0..nm): logits[nm]. */
+static void forward(const Gl *M, const int *ids, int T, const int *marks, int nm, double *logits)
+{
+ int d = M->d, I = M->inter;
+ float *x = (float *)xmalloc((size_t)T * d * sizeof(float));
+ float *h = (float *)xmalloc((size_t)T * d * sizeof(float));
+ float *att = (float *)xmalloc((size_t)T * d * sizeof(float));
+ float *big = (float *)xmalloc((size_t)T * (3 * d > I ? 3 * d : I) * sizeof(float));
+ AttnScratch A;
+ A.p2c = M->p2c ? (float *)xmalloc((size_t)M->heads * T * 2 * M->span * sizeof(float)) : NULL;
+ A.vt = (float *)xmalloc((size_t)d * T * sizeof(float));
+ A.ridx = (int *)xmalloc((size_t)(2 * T) * sizeof(int));
+ for (int r = 0; r < T; r++) {
+ int id = ids[r];
+ if (id < 0 || id >= M->vocab) id = 0;
+ memcpy(h + (size_t)r * d, M->tok_emb + (size_t)id * d, (size_t)d * sizeof(float));
+ }
+ layernorm(x, h, M->emb_ln_w, M->emb_ln_b, T, d, M->eps);
+ for (int l = 0; l < M->layers; l++) {
+ const GlLayer *E = &M->L[l];
+ qi_gemm(big, x, T, &E->wqkv, E->bqkv);
+ attention(M, E, big, att, T, &A);
+ qi_gemm(h, att, T, &E->wo, E->bo);
+ add_rows(h, x, (size_t)T * d);
+ layernorm(x, h, E->ln1_w, E->ln1_b, T, d, M->eps); /* x = attention_output */
+ qi_gemm(big, x, T, &E->wi, E->bi);
+ #pragma omp parallel for schedule(static)
+ for (size_t i = 0; i < (size_t)T * I; i++) big[i] = gelu(big[i]);
+ qi_gemm(h, big, T, &E->wo2, E->bo2);
+ add_rows(h, x, (size_t)T * d);
+ layernorm(x, h, E->ln2_w, E->ln2_b, T, d, M->eps);
+ }
+ /* classifier: Linear -> ReLU -> Linear(., 1) at each [L] */
+ float *m = (float *)xmalloc((size_t)(nm > 0 ? nm : 1) * d * sizeof(float));
+ float *m1 = (float *)xmalloc((size_t)(nm > 0 ? nm : 1) * M->cls_hidden * sizeof(float));
+ for (int k = 0; k < nm; k++) memcpy(m + (size_t)k * d, x + (size_t)marks[k] * d, (size_t)d * sizeof(float));
+ if (nm > 0) qi_gemm(m1, m, nm, &M->cls1, M->cls1_b);
+ for (int k = 0; k < nm; k++) {
+ float *row = m1 + (size_t)k * M->cls_hidden;
+ for (int j = 0; j < M->cls_hidden; j++) if (row[j] < 0.f) row[j] = 0.f;
+ logits[k] = (double)(dot_f32_lanes(row, M->cls2_w, M->cls_hidden) + M->cls2_b);
+ }
+ free(m); free(m1); free(x); free(h); free(att); free(big);
+ free(A.p2c); free(A.vt); free(A.ridx);
+}
+
+/* ------------------------------------------------------- the rendering */
+
+typedef struct {
+ IntVec ids;
+ int *label_marks; /* the [L] rows, every question's labels in turn */
+ int n_marks;
+ int *first_mark; /* [Q+1]: question q owns label_marks[first_mark[q] .. first_mark[q+1]) */
+ int schema_tokens; /* up to and including [SEP_TEXT] */
+ int state_tokens, state_used;
+ int words, words_used;
+} Rendered;
+
+static void rendered_free(Rendered *r)
+{
+ free(r->ids.v); free(r->label_marks); free(r->first_mark);
+ memset(r, 0, sizeof(*r));
+}
+
+/* A question's labels in the order the model reads them: a choice's labels, a
+ * score's levels; a noul is asked as "yes" then "no", the order the model
+ * card writes every yes/no question in. label_text[i] is option i's text in
+ * that order, NULL when it has none. */
+static int question_labels(const DecideQuestion *q, const char **label, const char **text)
+{
+ if (q->type == DECIDE_NOUL) {
+ label[0] = "yes"; text[0] = q->options[1].text;
+ label[1] = "no"; text[1] = q->options[0].text;
+ return 2;
+ }
+ for (int i = 0; i < q->n_options; i++) { label[i] = q->options[i].label; text[i] = q->options[i].text; }
+ return q->n_options;
+}
+
+static void push_encoded(const Gl *M, Rendered *r, const char *s)
+{
+ gl_encode(&M->tok, s, strlen(s), &r->ids);
+}
+
+/* processor._transform_record for one record: the schema of every question,
+ * [SEP_TEXT], then as many words of the state as fit in max_len tokens.
+ * Returns 1, or 0 with the reason when the questions alone do not fit. */
+static int render(const Gl *M, const DecideRecord *rec, Rendered *r, char *err, size_t cap)
+{
+ memset(r, 0, sizeof(*r));
+ int total_labels = 0;
+ for (int q = 0; q < rec->n_questions; q++) total_labels += rec->questions[q].n_options;
+ r->label_marks = (int *)xmalloc((size_t)(total_labels > 0 ? total_labels : 1) * sizeof(int));
+ r->first_mark = (int *)xmalloc((size_t)(rec->n_questions + 1) * sizeof(int));
+ const char *label[DECIDE_MAX_OPTIONS], *text[DECIDE_MAX_OPTIONS];
+ for (int q = 0; q < rec->n_questions; q++) {
+ const DecideQuestion *Q = &rec->questions[q];
+ int k = question_labels(Q, label, text);
+ if (q) ivec_push(&r->ids, M->id_sep_struct);
+ /* ( [P] prompt_str ( [L] label ... ) ) */
+ push_encoded(M, r, "(");
+ ivec_push(&r->ids, M->id_p);
+ Str prompt = {0};
+ str_put(&prompt, Q->id, strlen(Q->id));
+ if (Q->instructions[0]) { str_put(&prompt, ": ", 2); str_put(&prompt, Q->instructions, strlen(Q->instructions)); }
+ for (int i = 0; i < k; i++) {
+ if (!text[i] || !text[i][0]) continue;
+ str_put(&prompt, " [DESCRIPTION] ", 15);
+ str_put(&prompt, label[i], strlen(label[i]));
+ str_put(&prompt, ": ", 2);
+ str_put(&prompt, text[i], strlen(text[i]));
+ }
+ gl_encode(&M->tok, prompt.s, prompt.n, &r->ids);
+ free(prompt.s);
+ push_encoded(M, r, "(");
+ r->first_mark[q] = r->n_marks;
+ for (int i = 0; i < k; i++) {
+ r->label_marks[r->n_marks++] = r->ids.n;
+ ivec_push(&r->ids, M->id_l);
+ push_encoded(M, r, label[i]);
+ }
+ push_encoded(M, r, ")");
+ push_encoded(M, r, ")");
+ }
+ r->first_mark[rec->n_questions] = r->n_marks;
+ ivec_push(&r->ids, M->id_sep_text);
+ r->schema_tokens = r->ids.n;
+ if (r->schema_tokens > M->max_len) {
+ snprintf(err, cap, "questions: the questions and their options take %d tokens, more than "
+ "max_len=%d (COLI_GLINER_MAX_LEN); ask fewer questions or shorten the options",
+ r->schema_tokens, M->max_len);
+ return 0;
+ }
+ /* the state: "." appended unless it ends in . ! or ? (processor._collate_batch) */
+ size_t sl = strlen(rec->state);
+ char *state = (char *)xmalloc(sl + 2);
+ memcpy(state, rec->state, sl + 1);
+ if (!sl) { state[0] = '.'; state[1] = 0; sl = 1; }
+ else if (state[sl - 1] != '.' && state[sl - 1] != '!' && state[sl - 1] != '?') { state[sl] = '.'; state[sl + 1] = 0; sl++; }
+ Words w;
+ split_words(state, sl, &w);
+ free(state);
+ r->words = w.n;
+ int full = 1;
+ IntVec piece = {0};
+ for (int i = 0; i < w.n; i++) {
+ piece.n = 0;
+ gl_encode(&M->tok, w.w[i], strlen(w.w[i]), &piece);
+ r->state_tokens += piece.n;
+ if (full && r->ids.n + piece.n <= M->max_len) {
+ for (int t = 0; t < piece.n; t++) ivec_push(&r->ids, piece.v[t]);
+ r->state_used += piece.n;
+ r->words_used++;
+ } else {
+ full = 0; /* max_len counts whole words from the start */
+ }
+ }
+ free(piece.v);
+ words_free(&w);
+ return 1;
+}
+
+/* ------------------------------------------------------- the DECIDE call */
+
+typedef struct {
+ Gl *M;
+ int dump_ids;
+ Rendered last; /* the last record's sequence, for --records --ids */
+} GlCtx;
+
+static int gl_decide(void *opaque, const DecideRecord *rec, DecideAnswer *answers,
+ int *input_tokens, char *err, size_t cap)
+{
+ GlCtx *ctx = (GlCtx *)opaque;
+ Gl *M = ctx->M;
+ rendered_free(&ctx->last);
+ Rendered r;
+ if (!render(M, rec, &r, err, cap)) { rendered_free(&r); return 0; }
+ double *logits = (double *)xcalloc((size_t)(r.n_marks > 0 ? r.n_marks : 1), sizeof(double));
+ forward(M, r.ids.v, r.ids.n, r.label_marks, r.n_marks, logits);
+ for (int q = 0; q < rec->n_questions; q++) {
+ const DecideQuestion *Q = &rec->questions[q];
+ DecideAnswer *a = &answers[q];
+ int k = r.first_mark[q + 1] - r.first_mark[q];
+ const double *z = logits + r.first_mark[q];
+ a->n = k;
+ a->logits = (double *)xcalloc((size_t)k, sizeof(double));
+ a->probs = (double *)xcalloc((size_t)k, sizeof(double));
+ a->temperature = NAN; /* no calibration ships with the checkpoint */
+ /* softmax over the task's labels, as _extract_classification_result does
+ * for a single-label task (temperature 1) */
+ double mx = -INFINITY, sum = 0;
+ for (int i = 0; i < k; i++) if (z[i] > mx) mx = z[i];
+ double *p = (double *)xmalloc((size_t)k * sizeof(double));
+ for (int i = 0; i < k; i++) { p[i] = exp(z[i] - mx); sum += p[i]; }
+ for (int i = 0; i < k; i++) p[i] /= sum;
+ for (int i = 0; i < k; i++) {
+ /* back to the record's option order: a noul was read as yes, no */
+ int src = Q->type == DECIDE_NOUL ? 1 - i : i;
+ a->logits[i] = z[src];
+ a->probs[i] = p[src];
+ }
+ free(p);
+ a->n_actions = 0;
+ a->tokens = r.ids.n;
+ a->state_tokens = r.state_tokens;
+ a->state_dropped = r.state_tokens - r.state_used;
+ }
+ free(logits);
+ *input_tokens = r.ids.n;
+ if (ctx->dump_ids) ctx->last = r;
+ else rendered_free(&r);
+ return 1;
+}
+
+/* ------------------------------------------------------------------- main */
+
+static double rss_gb(void)
+{
+#ifdef __linux__
+ FILE *f = fopen("/proc/self/statm", "r");
+ long pages = 0, resident = 0;
+ if (f) { if (fscanf(f, "%ld %ld", &pages, &resident) != 2) resident = 0; fclose(f); }
+ return resident * (double)sysconf(_SC_PAGESIZE) / 1e9;
+#else
+ return 0.0;
+#endif
+}
+
+static void print_json_string(FILE *out, const char *s)
+{
+ DecideBuf b = {0};
+ decide_buf_string(&b, s);
+ fputs(b.data ? b.data : "\"\"", out);
+ free(b.data);
+}
+
+static jval *read_string_array(const char *path, char **text_out)
+{
+ char *text = read_text(path);
+ if (!text) die("cannot read %s", path);
+ jval *root = json_parse_checked(text);
+ if (!root || root->t != J_ARR) die("%s: expected a JSON array", path);
+ *text_out = text;
+ return root;
+}
+
+static int run_records(Gl *M, const char *path, int dump_ids)
+{
+ char *text;
+ jval *root = read_string_array(path, &text);
+ GlCtx ctx;
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.M = M;
+ ctx.dump_ids = dump_ids;
+ /* Each record is the text of a DECIDE payload and goes through
+ * decide_record_parse, the path the serve loop takes. */
+ for (int i = 0; i < root->len; i++) {
+ jval *payload = json_get(root->kids[i], "payload");
+ if (!payload || payload->t != J_STR) die("%s: record %d has no string \"payload\"", path, i);
+ DecideRecord rec;
+ char reason[1024];
+ if (!decide_record_parse(payload->str, &rec, reason, sizeof(reason))) {
+ printf("{\"error\":"); print_json_string(stdout, reason); printf("}\n");
+ continue;
+ }
+ DecideAnswer *answers = (DecideAnswer *)xcalloc((size_t)rec.n_questions, sizeof(DecideAnswer));
+ int tokens = 0;
+ double t0 = now_ms();
+ int ok = gl_decide(&ctx, &rec, answers, &tokens, reason, sizeof(reason));
+ double ms = now_ms() - t0;
+ if (!ok) {
+ printf("{\"error\":"); print_json_string(stdout, reason); printf("}\n");
+ } else {
+ size_t len = 0;
+ char *json = decide_answers_json(&rec, answers, tokens, ms, &len);
+ if (dump_ids && json && len > 1) {
+ json[len - 1] = 0; /* reopen the object */
+ fputs(json, stdout);
+ printf(",\"sequence\":{\"ids\":[");
+ for (int t = 0; t < ctx.last.ids.n; t++) printf("%s%d", t ? "," : "", ctx.last.ids.v[t]);
+ printf("],\"markers\":[");
+ for (int t = 0; t < ctx.last.n_marks; t++) printf("%s%d", t ? "," : "", ctx.last.label_marks[t]);
+ printf("],\"words\":%d,\"words_used\":%d}}\n", ctx.last.words, ctx.last.words_used);
+ } else if (json) {
+ fputs(json, stdout); fputc('\n', stdout);
+ }
+ free(json);
+ }
+ fflush(stdout);
+ decide_answers_free(answers, rec.n_questions);
+ free(answers);
+ decide_record_free(&rec);
+ }
+ rendered_free(&ctx.last);
+ json_free(root);
+ free(text);
+ return 0;
+}
+
+static int run_tokenize(Gl *M, const char *path)
+{
+ char *text;
+ jval *root = read_string_array(path, &text);
+ printf("[");
+ for (int i = 0; i < root->len; i++) {
+ jval *s = root->kids[i];
+ if (s->t != J_STR) die("%s: entry %d is not a string", path, i);
+ IntVec ids = {0};
+ gl_encode(&M->tok, s->str, strlen(s->str), &ids);
+ printf("%s[", i ? "," : "");
+ for (int t = 0; t < ids.n; t++) printf("%s%d", t ? "," : "", ids.v[t]);
+ printf("]");
+ free(ids.v);
+ }
+ printf("]\n");
+ json_free(root);
+ free(text);
+ return 0;
+}
+
+static int run_split(const char *path)
+{
+ char *text;
+ jval *root = read_string_array(path, &text);
+ printf("[");
+ for (int i = 0; i < root->len; i++) {
+ jval *s = root->kids[i];
+ if (s->t != J_STR) die("%s: entry %d is not a string", path, i);
+ Words w;
+ split_words(s->str, strlen(s->str), &w);
+ printf("%s[", i ? "," : "");
+ for (int t = 0; t < w.n; t++) { if (t) printf(","); print_json_string(stdout, w.w[t]); }
+ printf("]");
+ words_free(&w);
+ }
+ printf("]\n");
+ json_free(root);
+ free(text);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ const char *model = NULL, *records = NULL, *tokenize = NULL, *split = NULL;
+ int dump_ids = 0;
+ for (int i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--model") && i + 1 < argc) model = argv[++i];
+ else if (!strcmp(argv[i], "--records") && i + 1 < argc) records = argv[++i];
+ else if (!strcmp(argv[i], "--tokenize") && i + 1 < argc) tokenize = argv[++i];
+ else if (!strcmp(argv[i], "--split") && i + 1 < argc) split = argv[++i];
+ else if (!strcmp(argv[i], "--ids")) dump_ids = 1;
+ else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
+ printf("usage: SERVE=1 SNAP=<dir> gliner_decide serve DECIDE on stdin/stdout\n"
+ " gliner_decide --model DIR --records FILE [--ids]\n"
+ " gliner_decide --model DIR --tokenize FILE\n"
+ " gliner_decide --split FILE\n");
+ return 0;
+ }
+ /* a bare number is the gateway's cache-cap argument: nothing to cache here */
+ }
+ if (split) return run_split(split);
+ const char *serve = getenv("SERVE");
+ int serving = serve && !strcmp(serve, "1") && !records && !tokenize;
+ if (!model) model = getenv("SNAP");
+ if (!model) die("no model: pass --model DIR or set SNAP");
+ if (serving) coli_serve_stdio_init();
+ coli_omp_tune_threads("gliner_decide"); /* physical cores: SMT halves the GEMMs here too */
+#ifdef _OPENMP
+ omp_set_max_active_levels(1); /* the attention's qi_gemm calls run inside its tasks */
+#endif
+ double t0 = now_ms();
+ Gl *M = (Gl *)xcalloc(1, sizeof(Gl));
+ load_model(M, model);
+ fprintf(stderr, "[gliner_decide] %s: DeBERTa-v2 %d layers x %d, %d heads, relative span %d; "
+ "max_len %d; loaded in %.1f s\n", M->model_name, M->layers, M->d, M->heads, M->span,
+ M->max_len, (now_ms() - t0) / 1e3);
+ if (tokenize) return run_tokenize(M, tokenize);
+ if (records) return run_records(M, records, dump_ids);
+ if (!serving) die("nothing to do: set SERVE=1, or pass --records / --tokenize / --split");
+ int slots = getenv("KV_SLOTS") ? atoi(getenv("KV_SLOTS")) : 1;
+ if (slots < 1) slots = 1;
+ char caps[256];
+ snprintf(caps, sizeof(caps), "decide=1 chat=0 max_len=%d", M->max_len);
+ GlCtx ctx;
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.M = M;
+ return decide_serve(stdin, stdout, gl_decide, &ctx, caps, rss_gb(), slots);
+}
diff --git a/c/gliner_unicode.h b/c/gliner_unicode.h
new file mode 100644
index 00000000..33a807b9
--- /dev/null
+++ b/c/gliner_unicode.h
@@ -0,0 +1,484 @@
+/* GENERATED by tools/gen_gliner_unicode.py -- do not edit by hand.
+ * Python 3.12.3, Unicode Character Database 15.0.0.
+ * Python's \w and \s, str.lower() and the classes of its final-sigma rule,
+ * as the gliner2 word splitter reads text (gliner_decide.c). */
+#ifndef COLI_GLINER_UNICODE_H
+#define COLI_GLINER_UNICODE_H
+#include <stdint.h>
+typedef struct { uint32_t lo, hi; } GlUniRange;
+typedef struct { uint32_t cp, lower; } GlUniLower;
+static const GlUniRange gl_uni_word[748] = {
+ {0x30, 0x39}, {0x41, 0x5a}, {0x5f, 0x5f}, {0x61, 0x7a}, {0xaa, 0xaa}, {0xb2, 0xb3},
+ {0xb5, 0xb5}, {0xb9, 0xba}, {0xbc, 0xbe}, {0xc0, 0xd6}, {0xd8, 0xf6}, {0xf8, 0x2c1},
+ {0x2c6, 0x2d1}, {0x2e0, 0x2e4}, {0x2ec, 0x2ec}, {0x2ee, 0x2ee}, {0x370, 0x374}, {0x376, 0x377},
+ {0x37a, 0x37d}, {0x37f, 0x37f}, {0x386, 0x386}, {0x388, 0x38a}, {0x38c, 0x38c}, {0x38e, 0x3a1},
+ {0x3a3, 0x3f5}, {0x3f7, 0x481}, {0x48a, 0x52f}, {0x531, 0x556}, {0x559, 0x559}, {0x560, 0x588},
+ {0x5d0, 0x5ea}, {0x5ef, 0x5f2}, {0x620, 0x64a}, {0x660, 0x669}, {0x66e, 0x66f}, {0x671, 0x6d3},
+ {0x6d5, 0x6d5}, {0x6e5, 0x6e6}, {0x6ee, 0x6fc}, {0x6ff, 0x6ff}, {0x710, 0x710}, {0x712, 0x72f},
+ {0x74d, 0x7a5}, {0x7b1, 0x7b1}, {0x7c0, 0x7ea}, {0x7f4, 0x7f5}, {0x7fa, 0x7fa}, {0x800, 0x815},
+ {0x81a, 0x81a}, {0x824, 0x824}, {0x828, 0x828}, {0x840, 0x858}, {0x860, 0x86a}, {0x870, 0x887},
+ {0x889, 0x88e}, {0x8a0, 0x8c9}, {0x904, 0x939}, {0x93d, 0x93d}, {0x950, 0x950}, {0x958, 0x961},
+ {0x966, 0x96f}, {0x971, 0x980}, {0x985, 0x98c}, {0x98f, 0x990}, {0x993, 0x9a8}, {0x9aa, 0x9b0},
+ {0x9b2, 0x9b2}, {0x9b6, 0x9b9}, {0x9bd, 0x9bd}, {0x9ce, 0x9ce}, {0x9dc, 0x9dd}, {0x9df, 0x9e1},
+ {0x9e6, 0x9f1}, {0x9f4, 0x9f9}, {0x9fc, 0x9fc}, {0xa05, 0xa0a}, {0xa0f, 0xa10}, {0xa13, 0xa28},
+ {0xa2a, 0xa30}, {0xa32, 0xa33}, {0xa35, 0xa36}, {0xa38, 0xa39}, {0xa59, 0xa5c}, {0xa5e, 0xa5e},
+ {0xa66, 0xa6f}, {0xa72, 0xa74}, {0xa85, 0xa8d}, {0xa8f, 0xa91}, {0xa93, 0xaa8}, {0xaaa, 0xab0},
+ {0xab2, 0xab3}, {0xab5, 0xab9}, {0xabd, 0xabd}, {0xad0, 0xad0}, {0xae0, 0xae1}, {0xae6, 0xaef},
+ {0xaf9, 0xaf9}, {0xb05, 0xb0c}, {0xb0f, 0xb10}, {0xb13, 0xb28}, {0xb2a, 0xb30}, {0xb32, 0xb33},
+ {0xb35, 0xb39}, {0xb3d, 0xb3d}, {0xb5c, 0xb5d}, {0xb5f, 0xb61}, {0xb66, 0xb6f}, {0xb71, 0xb77},
+ {0xb83, 0xb83}, {0xb85, 0xb8a}, {0xb8e, 0xb90}, {0xb92, 0xb95}, {0xb99, 0xb9a}, {0xb9c, 0xb9c},
+ {0xb9e, 0xb9f}, {0xba3, 0xba4}, {0xba8, 0xbaa}, {0xbae, 0xbb9}, {0xbd0, 0xbd0}, {0xbe6, 0xbf2},
+ {0xc05, 0xc0c}, {0xc0e, 0xc10}, {0xc12, 0xc28}, {0xc2a, 0xc39}, {0xc3d, 0xc3d}, {0xc58, 0xc5a},
+ {0xc5d, 0xc5d}, {0xc60, 0xc61}, {0xc66, 0xc6f}, {0xc78, 0xc7e}, {0xc80, 0xc80}, {0xc85, 0xc8c},
+ {0xc8e, 0xc90}, {0xc92, 0xca8}, {0xcaa, 0xcb3}, {0xcb5, 0xcb9}, {0xcbd, 0xcbd}, {0xcdd, 0xcde},
+ {0xce0, 0xce1}, {0xce6, 0xcef}, {0xcf1, 0xcf2}, {0xd04, 0xd0c}, {0xd0e, 0xd10}, {0xd12, 0xd3a},
+ {0xd3d, 0xd3d}, {0xd4e, 0xd4e}, {0xd54, 0xd56}, {0xd58, 0xd61}, {0xd66, 0xd78}, {0xd7a, 0xd7f},
+ {0xd85, 0xd96}, {0xd9a, 0xdb1}, {0xdb3, 0xdbb}, {0xdbd, 0xdbd}, {0xdc0, 0xdc6}, {0xde6, 0xdef},
+ {0xe01, 0xe30}, {0xe32, 0xe33}, {0xe40, 0xe46}, {0xe50, 0xe59}, {0xe81, 0xe82}, {0xe84, 0xe84},
+ {0xe86, 0xe8a}, {0xe8c, 0xea3}, {0xea5, 0xea5}, {0xea7, 0xeb0}, {0xeb2, 0xeb3}, {0xebd, 0xebd},
+ {0xec0, 0xec4}, {0xec6, 0xec6}, {0xed0, 0xed9}, {0xedc, 0xedf}, {0xf00, 0xf00}, {0xf20, 0xf33},
+ {0xf40, 0xf47}, {0xf49, 0xf6c}, {0xf88, 0xf8c}, {0x1000, 0x102a}, {0x103f, 0x1049}, {0x1050, 0x1055},
+ {0x105a, 0x105d}, {0x1061, 0x1061}, {0x1065, 0x1066}, {0x106e, 0x1070}, {0x1075, 0x1081}, {0x108e, 0x108e},
+ {0x1090, 0x1099}, {0x10a0, 0x10c5}, {0x10c7, 0x10c7}, {0x10cd, 0x10cd}, {0x10d0, 0x10fa}, {0x10fc, 0x1248},
+ {0x124a, 0x124d}, {0x1250, 0x1256}, {0x1258, 0x1258}, {0x125a, 0x125d}, {0x1260, 0x1288}, {0x128a, 0x128d},
+ {0x1290, 0x12b0}, {0x12b2, 0x12b5}, {0x12b8, 0x12be}, {0x12c0, 0x12c0}, {0x12c2, 0x12c5}, {0x12c8, 0x12d6},
+ {0x12d8, 0x1310}, {0x1312, 0x1315}, {0x1318, 0x135a}, {0x1369, 0x137c}, {0x1380, 0x138f}, {0x13a0, 0x13f5},
+ {0x13f8, 0x13fd}, {0x1401, 0x166c}, {0x166f, 0x167f}, {0x1681, 0x169a}, {0x16a0, 0x16ea}, {0x16ee, 0x16f8},
+ {0x1700, 0x1711}, {0x171f, 0x1731}, {0x1740, 0x1751}, {0x1760, 0x176c}, {0x176e, 0x1770}, {0x1780, 0x17b3},
+ {0x17d7, 0x17d7}, {0x17dc, 0x17dc}, {0x17e0, 0x17e9}, {0x17f0, 0x17f9}, {0x1810, 0x1819}, {0x1820, 0x1878},
+ {0x1880, 0x1884}, {0x1887, 0x18a8}, {0x18aa, 0x18aa}, {0x18b0, 0x18f5}, {0x1900, 0x191e}, {0x1946, 0x196d},
+ {0x1970, 0x1974}, {0x1980, 0x19ab}, {0x19b0, 0x19c9}, {0x19d0, 0x19da}, {0x1a00, 0x1a16}, {0x1a20, 0x1a54},
+ {0x1a80, 0x1a89}, {0x1a90, 0x1a99}, {0x1aa7, 0x1aa7}, {0x1b05, 0x1b33}, {0x1b45, 0x1b4c}, {0x1b50, 0x1b59},
+ {0x1b83, 0x1ba0}, {0x1bae, 0x1be5}, {0x1c00, 0x1c23}, {0x1c40, 0x1c49}, {0x1c4d, 0x1c7d}, {0x1c80, 0x1c88},
+ {0x1c90, 0x1cba}, {0x1cbd, 0x1cbf}, {0x1ce9, 0x1cec}, {0x1cee, 0x1cf3}, {0x1cf5, 0x1cf6}, {0x1cfa, 0x1cfa},
+ {0x1d00, 0x1dbf}, {0x1e00, 0x1f15}, {0x1f18, 0x1f1d}, {0x1f20, 0x1f45}, {0x1f48, 0x1f4d}, {0x1f50, 0x1f57},
+ {0x1f59, 0x1f59}, {0x1f5b, 0x1f5b}, {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f7d}, {0x1f80, 0x1fb4}, {0x1fb6, 0x1fbc},
+ {0x1fbe, 0x1fbe}, {0x1fc2, 0x1fc4}, {0x1fc6, 0x1fcc}, {0x1fd0, 0x1fd3}, {0x1fd6, 0x1fdb}, {0x1fe0, 0x1fec},
+ {0x1ff2, 0x1ff4}, {0x1ff6, 0x1ffc}, {0x2070, 0x2071}, {0x2074, 0x2079}, {0x207f, 0x2089}, {0x2090, 0x209c},
+ {0x2102, 0x2102}, {0x2107, 0x2107}, {0x210a, 0x2113}, {0x2115, 0x2115}, {0x2119, 0x211d}, {0x2124, 0x2124},
+ {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212a, 0x212d}, {0x212f, 0x2139}, {0x213c, 0x213f}, {0x2145, 0x2149},
+ {0x214e, 0x214e}, {0x2150, 0x2189}, {0x2460, 0x249b}, {0x24ea, 0x24ff}, {0x2776, 0x2793}, {0x2c00, 0x2ce4},
+ {0x2ceb, 0x2cee}, {0x2cf2, 0x2cf3}, {0x2cfd, 0x2cfd}, {0x2d00, 0x2d25}, {0x2d27, 0x2d27}, {0x2d2d, 0x2d2d},
+ {0x2d30, 0x2d67}, {0x2d6f, 0x2d6f}, {0x2d80, 0x2d96}, {0x2da0, 0x2da6}, {0x2da8, 0x2dae}, {0x2db0, 0x2db6},
+ {0x2db8, 0x2dbe}, {0x2dc0, 0x2dc6}, {0x2dc8, 0x2dce}, {0x2dd0, 0x2dd6}, {0x2dd8, 0x2dde}, {0x2e2f, 0x2e2f},
+ {0x3005, 0x3007}, {0x3021, 0x3029}, {0x3031, 0x3035}, {0x3038, 0x303c}, {0x3041, 0x3096}, {0x309d, 0x309f},
+ {0x30a1, 0x30fa}, {0x30fc, 0x30ff}, {0x3105, 0x312f}, {0x3131, 0x318e}, {0x3192, 0x3195}, {0x31a0, 0x31bf},
+ {0x31f0, 0x31ff}, {0x3220, 0x3229}, {0x3248, 0x324f}, {0x3251, 0x325f}, {0x3280, 0x3289}, {0x32b1, 0x32bf},
+ {0x3400, 0x4dbf}, {0x4e00, 0xa48c}, {0xa4d0, 0xa4fd}, {0xa500, 0xa60c}, {0xa610, 0xa62b}, {0xa640, 0xa66e},
+ {0xa67f, 0xa69d}, {0xa6a0, 0xa6ef}, {0xa717, 0xa71f}, {0xa722, 0xa788}, {0xa78b, 0xa7ca}, {0xa7d0, 0xa7d1},
+ {0xa7d3, 0xa7d3}, {0xa7d5, 0xa7d9}, {0xa7f2, 0xa801}, {0xa803, 0xa805}, {0xa807, 0xa80a}, {0xa80c, 0xa822},
+ {0xa830, 0xa835}, {0xa840, 0xa873}, {0xa882, 0xa8b3}, {0xa8d0, 0xa8d9}, {0xa8f2, 0xa8f7}, {0xa8fb, 0xa8fb},
+ {0xa8fd, 0xa8fe}, {0xa900, 0xa925}, {0xa930, 0xa946}, {0xa960, 0xa97c}, {0xa984, 0xa9b2}, {0xa9cf, 0xa9d9},
+ {0xa9e0, 0xa9e4}, {0xa9e6, 0xa9fe}, {0xaa00, 0xaa28}, {0xaa40, 0xaa42}, {0xaa44, 0xaa4b}, {0xaa50, 0xaa59},
+ {0xaa60, 0xaa76}, {0xaa7a, 0xaa7a}, {0xaa7e, 0xaaaf}, {0xaab1, 0xaab1}, {0xaab5, 0xaab6}, {0xaab9, 0xaabd},
+ {0xaac0, 0xaac0}, {0xaac2, 0xaac2}, {0xaadb, 0xaadd}, {0xaae0, 0xaaea}, {0xaaf2, 0xaaf4}, {0xab01, 0xab06},
+ {0xab09, 0xab0e}, {0xab11, 0xab16}, {0xab20, 0xab26}, {0xab28, 0xab2e}, {0xab30, 0xab5a}, {0xab5c, 0xab69},
+ {0xab70, 0xabe2}, {0xabf0, 0xabf9}, {0xac00, 0xd7a3}, {0xd7b0, 0xd7c6}, {0xd7cb, 0xd7fb}, {0xf900, 0xfa6d},
+ {0xfa70, 0xfad9}, {0xfb00, 0xfb06}, {0xfb13, 0xfb17}, {0xfb1d, 0xfb1d}, {0xfb1f, 0xfb28}, {0xfb2a, 0xfb36},
+ {0xfb38, 0xfb3c}, {0xfb3e, 0xfb3e}, {0xfb40, 0xfb41}, {0xfb43, 0xfb44}, {0xfb46, 0xfbb1}, {0xfbd3, 0xfd3d},
+ {0xfd50, 0xfd8f}, {0xfd92, 0xfdc7}, {0xfdf0, 0xfdfb}, {0xfe70, 0xfe74}, {0xfe76, 0xfefc}, {0xff10, 0xff19},
+ {0xff21, 0xff3a}, {0xff41, 0xff5a}, {0xff66, 0xffbe}, {0xffc2, 0xffc7}, {0xffca, 0xffcf}, {0xffd2, 0xffd7},
+ {0xffda, 0xffdc}, {0x10000, 0x1000b}, {0x1000d, 0x10026}, {0x10028, 0x1003a}, {0x1003c, 0x1003d}, {0x1003f, 0x1004d},
+ {0x10050, 0x1005d}, {0x10080, 0x100fa}, {0x10107, 0x10133}, {0x10140, 0x10178}, {0x1018a, 0x1018b}, {0x10280, 0x1029c},
+ {0x102a0, 0x102d0}, {0x102e1, 0x102fb}, {0x10300, 0x10323}, {0x1032d, 0x1034a}, {0x10350, 0x10375}, {0x10380, 0x1039d},
+ {0x103a0, 0x103c3}, {0x103c8, 0x103cf}, {0x103d1, 0x103d5}, {0x10400, 0x1049d}, {0x104a0, 0x104a9}, {0x104b0, 0x104d3},
+ {0x104d8, 0x104fb}, {0x10500, 0x10527}, {0x10530, 0x10563}, {0x10570, 0x1057a}, {0x1057c, 0x1058a}, {0x1058c, 0x10592},
+ {0x10594, 0x10595}, {0x10597, 0x105a1}, {0x105a3, 0x105b1}, {0x105b3, 0x105b9}, {0x105bb, 0x105bc}, {0x10600, 0x10736},
+ {0x10740, 0x10755}, {0x10760, 0x10767}, {0x10780, 0x10785}, {0x10787, 0x107b0}, {0x107b2, 0x107ba}, {0x10800, 0x10805},
+ {0x10808, 0x10808}, {0x1080a, 0x10835}, {0x10837, 0x10838}, {0x1083c, 0x1083c}, {0x1083f, 0x10855}, {0x10858, 0x10876},
+ {0x10879, 0x1089e}, {0x108a7, 0x108af}, {0x108e0, 0x108f2}, {0x108f4, 0x108f5}, {0x108fb, 0x1091b}, {0x10920, 0x10939},
+ {0x10980, 0x109b7}, {0x109bc, 0x109cf}, {0x109d2, 0x10a00}, {0x10a10, 0x10a13}, {0x10a15, 0x10a17}, {0x10a19, 0x10a35},
+ {0x10a40, 0x10a48}, {0x10a60, 0x10a7e}, {0x10a80, 0x10a9f}, {0x10ac0, 0x10ac7}, {0x10ac9, 0x10ae4}, {0x10aeb, 0x10aef},
+ {0x10b00, 0x10b35}, {0x10b40, 0x10b55}, {0x10b58, 0x10b72}, {0x10b78, 0x10b91}, {0x10ba9, 0x10baf}, {0x10c00, 0x10c48},
+ {0x10c80, 0x10cb2}, {0x10cc0, 0x10cf2}, {0x10cfa, 0x10d23}, {0x10d30, 0x10d39}, {0x10e60, 0x10e7e}, {0x10e80, 0x10ea9},
+ {0x10eb0, 0x10eb1}, {0x10f00, 0x10f27}, {0x10f30, 0x10f45}, {0x10f51, 0x10f54}, {0x10f70, 0x10f81}, {0x10fb0, 0x10fcb},
+ {0x10fe0, 0x10ff6}, {0x11003, 0x11037}, {0x11052, 0x1106f}, {0x11071, 0x11072}, {0x11075, 0x11075}, {0x11083, 0x110af},
+ {0x110d0, 0x110e8}, {0x110f0, 0x110f9}, {0x11103, 0x11126}, {0x11136, 0x1113f}, {0x11144, 0x11144}, {0x11147, 0x11147},
+ {0x11150, 0x11172}, {0x11176, 0x11176}, {0x11183, 0x111b2}, {0x111c1, 0x111c4}, {0x111d0, 0x111da}, {0x111dc, 0x111dc},
+ {0x111e1, 0x111f4}, {0x11200, 0x11211}, {0x11213, 0x1122b}, {0x1123f, 0x11240}, {0x11280, 0x11286}, {0x11288, 0x11288},
+ {0x1128a, 0x1128d}, {0x1128f, 0x1129d}, {0x1129f, 0x112a8}, {0x112b0, 0x112de}, {0x112f0, 0x112f9}, {0x11305, 0x1130c},
+ {0x1130f, 0x11310}, {0x11313, 0x11328}, {0x1132a, 0x11330}, {0x11332, 0x11333}, {0x11335, 0x11339}, {0x1133d, 0x1133d},
+ {0x11350, 0x11350}, {0x1135d, 0x11361}, {0x11400, 0x11434}, {0x11447, 0x1144a}, {0x11450, 0x11459}, {0x1145f, 0x11461},
+ {0x11480, 0x114af}, {0x114c4, 0x114c5}, {0x114c7, 0x114c7}, {0x114d0, 0x114d9}, {0x11580, 0x115ae}, {0x115d8, 0x115db},
+ {0x11600, 0x1162f}, {0x11644, 0x11644}, {0x11650, 0x11659}, {0x11680, 0x116aa}, {0x116b8, 0x116b8}, {0x116c0, 0x116c9},
+ {0x11700, 0x1171a}, {0x11730, 0x1173b}, {0x11740, 0x11746}, {0x11800, 0x1182b}, {0x118a0, 0x118f2}, {0x118ff, 0x11906},
+ {0x11909, 0x11909}, {0x1190c, 0x11913}, {0x11915, 0x11916}, {0x11918, 0x1192f}, {0x1193f, 0x1193f}, {0x11941, 0x11941},
+ {0x11950, 0x11959}, {0x119a0, 0x119a7}, {0x119aa, 0x119d0}, {0x119e1, 0x119e1}, {0x119e3, 0x119e3}, {0x11a00, 0x11a00},
+ {0x11a0b, 0x11a32}, {0x11a3a, 0x11a3a}, {0x11a50, 0x11a50}, {0x11a5c, 0x11a89}, {0x11a9d, 0x11a9d}, {0x11ab0, 0x11af8},
+ {0x11c00, 0x11c08}, {0x11c0a, 0x11c2e}, {0x11c40, 0x11c40}, {0x11c50, 0x11c6c}, {0x11c72, 0x11c8f}, {0x11d00, 0x11d06},
+ {0x11d08, 0x11d09}, {0x11d0b, 0x11d30}, {0x11d46, 0x11d46}, {0x11d50, 0x11d59}, {0x11d60, 0x11d65}, {0x11d67, 0x11d68},
+ {0x11d6a, 0x11d89}, {0x11d98, 0x11d98}, {0x11da0, 0x11da9}, {0x11ee0, 0x11ef2}, {0x11f02, 0x11f02}, {0x11f04, 0x11f10},
+ {0x11f12, 0x11f33}, {0x11f50, 0x11f59}, {0x11fb0, 0x11fb0}, {0x11fc0, 0x11fd4}, {0x12000, 0x12399}, {0x12400, 0x1246e},
+ {0x12480, 0x12543}, {0x12f90, 0x12ff0}, {0x13000, 0x1342f}, {0x13441, 0x13446}, {0x14400, 0x14646}, {0x16800, 0x16a38},
+ {0x16a40, 0x16a5e}, {0x16a60, 0x16a69}, {0x16a70, 0x16abe}, {0x16ac0, 0x16ac9}, {0x16ad0, 0x16aed}, {0x16b00, 0x16b2f},
+ {0x16b40, 0x16b43}, {0x16b50, 0x16b59}, {0x16b5b, 0x16b61}, {0x16b63, 0x16b77}, {0x16b7d, 0x16b8f}, {0x16e40, 0x16e96},
+ {0x16f00, 0x16f4a}, {0x16f50, 0x16f50}, {0x16f93, 0x16f9f}, {0x16fe0, 0x16fe1}, {0x16fe3, 0x16fe3}, {0x17000, 0x187f7},
+ {0x18800, 0x18cd5}, {0x18d00, 0x18d08}, {0x1aff0, 0x1aff3}, {0x1aff5, 0x1affb}, {0x1affd, 0x1affe}, {0x1b000, 0x1b122},
+ {0x1b132, 0x1b132}, {0x1b150, 0x1b152}, {0x1b155, 0x1b155}, {0x1b164, 0x1b167}, {0x1b170, 0x1b2fb}, {0x1bc00, 0x1bc6a},
+ {0x1bc70, 0x1bc7c}, {0x1bc80, 0x1bc88}, {0x1bc90, 0x1bc99}, {0x1d2c0, 0x1d2d3}, {0x1d2e0, 0x1d2f3}, {0x1d360, 0x1d378},
+ {0x1d400, 0x1d454}, {0x1d456, 0x1d49c}, {0x1d49e, 0x1d49f}, {0x1d4a2, 0x1d4a2}, {0x1d4a5, 0x1d4a6}, {0x1d4a9, 0x1d4ac},
+ {0x1d4ae, 0x1d4b9}, {0x1d4bb, 0x1d4bb}, {0x1d4bd, 0x1d4c3}, {0x1d4c5, 0x1d505}, {0x1d507, 0x1d50a}, {0x1d50d, 0x1d514},
+ {0x1d516, 0x1d51c}, {0x1d51e, 0x1d539}, {0x1d53b, 0x1d53e}, {0x1d540, 0x1d544}, {0x1d546, 0x1d546}, {0x1d54a, 0x1d550},
+ {0x1d552, 0x1d6a5}, {0x1d6a8, 0x1d6c0}, {0x1d6c2, 0x1d6da}, {0x1d6dc, 0x1d6fa}, {0x1d6fc, 0x1d714}, {0x1d716, 0x1d734},
+ {0x1d736, 0x1d74e}, {0x1d750, 0x1d76e}, {0x1d770, 0x1d788}, {0x1d78a, 0x1d7a8}, {0x1d7aa, 0x1d7c2}, {0x1d7c4, 0x1d7cb},
+ {0x1d7ce, 0x1d7ff}, {0x1df00, 0x1df1e}, {0x1df25, 0x1df2a}, {0x1e030, 0x1e06d}, {0x1e100, 0x1e12c}, {0x1e137, 0x1e13d},
+ {0x1e140, 0x1e149}, {0x1e14e, 0x1e14e}, {0x1e290, 0x1e2ad}, {0x1e2c0, 0x1e2eb}, {0x1e2f0, 0x1e2f9}, {0x1e4d0, 0x1e4eb},
+ {0x1e4f0, 0x1e4f9}, {0x1e7e0, 0x1e7e6}, {0x1e7e8, 0x1e7eb}, {0x1e7ed, 0x1e7ee}, {0x1e7f0, 0x1e7fe}, {0x1e800, 0x1e8c4},
+ {0x1e8c7, 0x1e8cf}, {0x1e900, 0x1e943}, {0x1e94b, 0x1e94b}, {0x1e950, 0x1e959}, {0x1ec71, 0x1ecab}, {0x1ecad, 0x1ecaf},
+ {0x1ecb1, 0x1ecb4}, {0x1ed01, 0x1ed2d}, {0x1ed2f, 0x1ed3d}, {0x1ee00, 0x1ee03}, {0x1ee05, 0x1ee1f}, {0x1ee21, 0x1ee22},
+ {0x1ee24, 0x1ee24}, {0x1ee27, 0x1ee27}, {0x1ee29, 0x1ee32}, {0x1ee34, 0x1ee37}, {0x1ee39, 0x1ee39}, {0x1ee3b, 0x1ee3b},
+ {0x1ee42, 0x1ee42}, {0x1ee47, 0x1ee47}, {0x1ee49, 0x1ee49}, {0x1ee4b, 0x1ee4b}, {0x1ee4d, 0x1ee4f}, {0x1ee51, 0x1ee52},
+ {0x1ee54, 0x1ee54}, {0x1ee57, 0x1ee57}, {0x1ee59, 0x1ee59}, {0x1ee5b, 0x1ee5b}, {0x1ee5d, 0x1ee5d}, {0x1ee5f, 0x1ee5f},
+ {0x1ee61, 0x1ee62}, {0x1ee64, 0x1ee64}, {0x1ee67, 0x1ee6a}, {0x1ee6c, 0x1ee72}, {0x1ee74, 0x1ee77}, {0x1ee79, 0x1ee7c},
+ {0x1ee7e, 0x1ee7e}, {0x1ee80, 0x1ee89}, {0x1ee8b, 0x1ee9b}, {0x1eea1, 0x1eea3}, {0x1eea5, 0x1eea9}, {0x1eeab, 0x1eebb},
+ {0x1f100, 0x1f10c}, {0x1fbf0, 0x1fbf9}, {0x20000, 0x2a6df}, {0x2a700, 0x2b739}, {0x2b740, 0x2b81d}, {0x2b820, 0x2cea1},
+ {0x2ceb0, 0x2ebe0}, {0x2f800, 0x2fa1d}, {0x30000, 0x3134a}, {0x31350, 0x323af},
+};
+static const GlUniRange gl_uni_space[10] = {
+ {0x9, 0xd}, {0x1c, 0x20}, {0x85, 0x85}, {0xa0, 0xa0}, {0x1680, 0x1680}, {0x2000, 0x200a},
+ {0x2028, 0x2029}, {0x202f, 0x202f}, {0x205f, 0x205f}, {0x3000, 0x3000},
+};
+static const GlUniRange gl_uni_cased[150] = {
+ {0x41, 0x5a}, {0x61, 0x7a}, {0xaa, 0xaa}, {0xb5, 0xb5}, {0xba, 0xba}, {0xc0, 0xd6},
+ {0xd8, 0xf6}, {0xf8, 0x1ba}, {0x1bc, 0x1bf}, {0x1c4, 0x293}, {0x295, 0x2af}, {0x370, 0x373},
+ {0x376, 0x377}, {0x37b, 0x37d}, {0x37f, 0x37f}, {0x386, 0x386}, {0x388, 0x38a}, {0x38c, 0x38c},
+ {0x38e, 0x3a1}, {0x3a3, 0x3f5}, {0x3f7, 0x481}, {0x48a, 0x52f}, {0x531, 0x556}, {0x560, 0x588},
+ {0x10a0, 0x10c5}, {0x10c7, 0x10c7}, {0x10cd, 0x10cd}, {0x10d0, 0x10fa}, {0x10fd, 0x10ff}, {0x13a0, 0x13f5},
+ {0x13f8, 0x13fd}, {0x1c80, 0x1c88}, {0x1c90, 0x1cba}, {0x1cbd, 0x1cbf}, {0x1d00, 0x1d2b}, {0x1d6b, 0x1d77},
+ {0x1d79, 0x1d9a}, {0x1e00, 0x1f15}, {0x1f18, 0x1f1d}, {0x1f20, 0x1f45}, {0x1f48, 0x1f4d}, {0x1f50, 0x1f57},
+ {0x1f59, 0x1f59}, {0x1f5b, 0x1f5b}, {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f7d}, {0x1f80, 0x1fb4}, {0x1fb6, 0x1fbc},
+ {0x1fbe, 0x1fbe}, {0x1fc2, 0x1fc4}, {0x1fc6, 0x1fcc}, {0x1fd0, 0x1fd3}, {0x1fd6, 0x1fdb}, {0x1fe0, 0x1fec},
+ {0x1ff2, 0x1ff4}, {0x1ff6, 0x1ffc}, {0x2102, 0x2102}, {0x2107, 0x2107}, {0x210a, 0x2113}, {0x2115, 0x2115},
+ {0x2119, 0x211d}, {0x2124, 0x2124}, {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212a, 0x212d}, {0x212f, 0x2134},
+ {0x2139, 0x2139}, {0x213c, 0x213f}, {0x2145, 0x2149}, {0x214e, 0x214e}, {0x2160, 0x217f}, {0x2183, 0x2184},
+ {0x24b6, 0x24e9}, {0x2c00, 0x2c7b}, {0x2c7e, 0x2ce4}, {0x2ceb, 0x2cee}, {0x2cf2, 0x2cf3}, {0x2d00, 0x2d25},
+ {0x2d27, 0x2d27}, {0x2d2d, 0x2d2d}, {0xa640, 0xa66d}, {0xa680, 0xa69b}, {0xa722, 0xa76f}, {0xa771, 0xa787},
+ {0xa78b, 0xa78e}, {0xa790, 0xa7ca}, {0xa7d0, 0xa7d1}, {0xa7d3, 0xa7d3}, {0xa7d5, 0xa7d9}, {0xa7f5, 0xa7f6},
+ {0xa7fa, 0xa7fa}, {0xab30, 0xab5a}, {0xab60, 0xab68}, {0xab70, 0xabbf}, {0xfb00, 0xfb06}, {0xfb13, 0xfb17},
+ {0xff21, 0xff3a}, {0xff41, 0xff5a}, {0x10400, 0x1044f}, {0x104b0, 0x104d3}, {0x104d8, 0x104fb}, {0x10570, 0x1057a},
+ {0x1057c, 0x1058a}, {0x1058c, 0x10592}, {0x10594, 0x10595}, {0x10597, 0x105a1}, {0x105a3, 0x105b1}, {0x105b3, 0x105b9},
+ {0x105bb, 0x105bc}, {0x10c80, 0x10cb2}, {0x10cc0, 0x10cf2}, {0x118a0, 0x118df}, {0x16e40, 0x16e7f}, {0x1d400, 0x1d454},
+ {0x1d456, 0x1d49c}, {0x1d49e, 0x1d49f}, {0x1d4a2, 0x1d4a2}, {0x1d4a5, 0x1d4a6}, {0x1d4a9, 0x1d4ac}, {0x1d4ae, 0x1d4b9},
+ {0x1d4bb, 0x1d4bb}, {0x1d4bd, 0x1d4c3}, {0x1d4c5, 0x1d505}, {0x1d507, 0x1d50a}, {0x1d50d, 0x1d514}, {0x1d516, 0x1d51c},
+ {0x1d51e, 0x1d539}, {0x1d53b, 0x1d53e}, {0x1d540, 0x1d544}, {0x1d546, 0x1d546}, {0x1d54a, 0x1d550}, {0x1d552, 0x1d6a5},
+ {0x1d6a8, 0x1d6c0}, {0x1d6c2, 0x1d6da}, {0x1d6dc, 0x1d6fa}, {0x1d6fc, 0x1d714}, {0x1d716, 0x1d734}, {0x1d736, 0x1d74e},
+ {0x1d750, 0x1d76e}, {0x1d770, 0x1d788}, {0x1d78a, 0x1d7a8}, {0x1d7aa, 0x1d7c2}, {0x1d7c4, 0x1d7cb}, {0x1df00, 0x1df09},
+ {0x1df0b, 0x1df1e}, {0x1df25, 0x1df2a}, {0x1e900, 0x1e943}, {0x1f130, 0x1f149}, {0x1f150, 0x1f169}, {0x1f170, 0x1f189},
+};
+static const GlUniRange gl_uni_ignorable[437] = {
+ {0x27, 0x27}, {0x2e, 0x2e}, {0x3a, 0x3a}, {0x5e, 0x5e}, {0x60, 0x60}, {0xa8, 0xa8},
+ {0xad, 0xad}, {0xaf, 0xaf}, {0xb4, 0xb4}, {0xb7, 0xb8}, {0x2b0, 0x36f}, {0x374, 0x375},
+ {0x37a, 0x37a}, {0x384, 0x385}, {0x387, 0x387}, {0x483, 0x489}, {0x559, 0x559}, {0x55f, 0x55f},
+ {0x591, 0x5bd}, {0x5bf, 0x5bf}, {0x5c1, 0x5c2}, {0x5c4, 0x5c5}, {0x5c7, 0x5c7}, {0x5f4, 0x5f4},
+ {0x600, 0x605}, {0x610, 0x61a}, {0x61c, 0x61c}, {0x640, 0x640}, {0x64b, 0x65f}, {0x670, 0x670},
+ {0x6d6, 0x6dd}, {0x6df, 0x6e8}, {0x6ea, 0x6ed}, {0x70f, 0x70f}, {0x711, 0x711}, {0x730, 0x74a},
+ {0x7a6, 0x7b0}, {0x7eb, 0x7f5}, {0x7fa, 0x7fa}, {0x7fd, 0x7fd}, {0x816, 0x82d}, {0x859, 0x85b},
+ {0x888, 0x888}, {0x890, 0x891}, {0x898, 0x89f}, {0x8c9, 0x902}, {0x93a, 0x93a}, {0x93c, 0x93c},
+ {0x941, 0x948}, {0x94d, 0x94d}, {0x951, 0x957}, {0x962, 0x963}, {0x971, 0x971}, {0x981, 0x981},
+ {0x9bc, 0x9bc}, {0x9c1, 0x9c4}, {0x9cd, 0x9cd}, {0x9e2, 0x9e3}, {0x9fe, 0x9fe}, {0xa01, 0xa02},
+ {0xa3c, 0xa3c}, {0xa41, 0xa42}, {0xa47, 0xa48}, {0xa4b, 0xa4d}, {0xa51, 0xa51}, {0xa70, 0xa71},
+ {0xa75, 0xa75}, {0xa81, 0xa82}, {0xabc, 0xabc}, {0xac1, 0xac5}, {0xac7, 0xac8}, {0xacd, 0xacd},
+ {0xae2, 0xae3}, {0xafa, 0xaff}, {0xb01, 0xb01}, {0xb3c, 0xb3c}, {0xb3f, 0xb3f}, {0xb41, 0xb44},
+ {0xb4d, 0xb4d}, {0xb55, 0xb56}, {0xb62, 0xb63}, {0xb82, 0xb82}, {0xbc0, 0xbc0}, {0xbcd, 0xbcd},
+ {0xc00, 0xc00}, {0xc04, 0xc04}, {0xc3c, 0xc3c}, {0xc3e, 0xc40}, {0xc46, 0xc48}, {0xc4a, 0xc4d},
+ {0xc55, 0xc56}, {0xc62, 0xc63}, {0xc81, 0xc81}, {0xcbc, 0xcbc}, {0xcbf, 0xcbf}, {0xcc6, 0xcc6},
+ {0xccc, 0xccd}, {0xce2, 0xce3}, {0xd00, 0xd01}, {0xd3b, 0xd3c}, {0xd41, 0xd44}, {0xd4d, 0xd4d},
+ {0xd62, 0xd63}, {0xd81, 0xd81}, {0xdca, 0xdca}, {0xdd2, 0xdd4}, {0xdd6, 0xdd6}, {0xe31, 0xe31},
+ {0xe34, 0xe3a}, {0xe46, 0xe4e}, {0xeb1, 0xeb1}, {0xeb4, 0xebc}, {0xec6, 0xec6}, {0xec8, 0xece},
+ {0xf18, 0xf19}, {0xf35, 0xf35}, {0xf37, 0xf37}, {0xf39, 0xf39}, {0xf71, 0xf7e}, {0xf80, 0xf84},
+ {0xf86, 0xf87}, {0xf8d, 0xf97}, {0xf99, 0xfbc}, {0xfc6, 0xfc6}, {0x102d, 0x1030}, {0x1032, 0x1037},
+ {0x1039, 0x103a}, {0x103d, 0x103e}, {0x1058, 0x1059}, {0x105e, 0x1060}, {0x1071, 0x1074}, {0x1082, 0x1082},
+ {0x1085, 0x1086}, {0x108d, 0x108d}, {0x109d, 0x109d}, {0x10fc, 0x10fc}, {0x135d, 0x135f}, {0x1712, 0x1714},
+ {0x1732, 0x1733}, {0x1752, 0x1753}, {0x1772, 0x1773}, {0x17b4, 0x17b5}, {0x17b7, 0x17bd}, {0x17c6, 0x17c6},
+ {0x17c9, 0x17d3}, {0x17d7, 0x17d7}, {0x17dd, 0x17dd}, {0x180b, 0x180f}, {0x1843, 0x1843}, {0x1885, 0x1886},
+ {0x18a9, 0x18a9}, {0x1920, 0x1922}, {0x1927, 0x1928}, {0x1932, 0x1932}, {0x1939, 0x193b}, {0x1a17, 0x1a18},
+ {0x1a1b, 0x1a1b}, {0x1a56, 0x1a56}, {0x1a58, 0x1a5e}, {0x1a60, 0x1a60}, {0x1a62, 0x1a62}, {0x1a65, 0x1a6c},
+ {0x1a73, 0x1a7c}, {0x1a7f, 0x1a7f}, {0x1aa7, 0x1aa7}, {0x1ab0, 0x1ace}, {0x1b00, 0x1b03}, {0x1b34, 0x1b34},
+ {0x1b36, 0x1b3a}, {0x1b3c, 0x1b3c}, {0x1b42, 0x1b42}, {0x1b6b, 0x1b73}, {0x1b80, 0x1b81}, {0x1ba2, 0x1ba5},
+ {0x1ba8, 0x1ba9}, {0x1bab, 0x1bad}, {0x1be6, 0x1be6}, {0x1be8, 0x1be9}, {0x1bed, 0x1bed}, {0x1bef, 0x1bf1},
+ {0x1c2c, 0x1c33}, {0x1c36, 0x1c37}, {0x1c78, 0x1c7d}, {0x1cd0, 0x1cd2}, {0x1cd4, 0x1ce0}, {0x1ce2, 0x1ce8},
+ {0x1ced, 0x1ced}, {0x1cf4, 0x1cf4}, {0x1cf8, 0x1cf9}, {0x1d2c, 0x1d6a}, {0x1d78, 0x1d78}, {0x1d9b, 0x1dff},
+ {0x1fbd, 0x1fbd}, {0x1fbf, 0x1fc1}, {0x1fcd, 0x1fcf}, {0x1fdd, 0x1fdf}, {0x1fed, 0x1fef}, {0x1ffd, 0x1ffe},
+ {0x200b, 0x200f}, {0x2018, 0x2019}, {0x2024, 0x2024}, {0x2027, 0x2027}, {0x202a, 0x202e}, {0x2060, 0x2064},
+ {0x2066, 0x206f}, {0x2071, 0x2071}, {0x207f, 0x207f}, {0x2090, 0x209c}, {0x20d0, 0x20f0}, {0x2c7c, 0x2c7d},
+ {0x2cef, 0x2cf1}, {0x2d6f, 0x2d6f}, {0x2d7f, 0x2d7f}, {0x2de0, 0x2dff}, {0x2e2f, 0x2e2f}, {0x3005, 0x3005},
+ {0x302a, 0x302d}, {0x3031, 0x3035}, {0x303b, 0x303b}, {0x3099, 0x309e}, {0x30fc, 0x30fe}, {0xa015, 0xa015},
+ {0xa4f8, 0xa4fd}, {0xa60c, 0xa60c}, {0xa66f, 0xa672}, {0xa674, 0xa67d}, {0xa67f, 0xa67f}, {0xa69c, 0xa69f},
+ {0xa6f0, 0xa6f1}, {0xa700, 0xa721}, {0xa770, 0xa770}, {0xa788, 0xa78a}, {0xa7f2, 0xa7f4}, {0xa7f8, 0xa7f9},
+ {0xa802, 0xa802}, {0xa806, 0xa806}, {0xa80b, 0xa80b}, {0xa825, 0xa826}, {0xa82c, 0xa82c}, {0xa8c4, 0xa8c5},
+ {0xa8e0, 0xa8f1}, {0xa8ff, 0xa8ff}, {0xa926, 0xa92d}, {0xa947, 0xa951}, {0xa980, 0xa982}, {0xa9b3, 0xa9b3},
+ {0xa9b6, 0xa9b9}, {0xa9bc, 0xa9bd}, {0xa9cf, 0xa9cf}, {0xa9e5, 0xa9e6}, {0xaa29, 0xaa2e}, {0xaa31, 0xaa32},
+ {0xaa35, 0xaa36}, {0xaa43, 0xaa43}, {0xaa4c, 0xaa4c}, {0xaa70, 0xaa70}, {0xaa7c, 0xaa7c}, {0xaab0, 0xaab0},
+ {0xaab2, 0xaab4}, {0xaab7, 0xaab8}, {0xaabe, 0xaabf}, {0xaac1, 0xaac1}, {0xaadd, 0xaadd}, {0xaaec, 0xaaed},
+ {0xaaf3, 0xaaf4}, {0xaaf6, 0xaaf6}, {0xab5b, 0xab5f}, {0xab69, 0xab6b}, {0xabe5, 0xabe5}, {0xabe8, 0xabe8},
+ {0xabed, 0xabed}, {0xfb1e, 0xfb1e}, {0xfbb2, 0xfbc2}, {0xfe00, 0xfe0f}, {0xfe13, 0xfe13}, {0xfe20, 0xfe2f},
+ {0xfe52, 0xfe52}, {0xfe55, 0xfe55}, {0xfeff, 0xfeff}, {0xff07, 0xff07}, {0xff0e, 0xff0e}, {0xff1a, 0xff1a},
+ {0xff3e, 0xff3e}, {0xff40, 0xff40}, {0xff70, 0xff70}, {0xff9e, 0xff9f}, {0xffe3, 0xffe3}, {0xfff9, 0xfffb},
+ {0x101fd, 0x101fd}, {0x102e0, 0x102e0}, {0x10376, 0x1037a}, {0x10780, 0x10785}, {0x10787, 0x107b0}, {0x107b2, 0x107ba},
+ {0x10a01, 0x10a03}, {0x10a05, 0x10a06}, {0x10a0c, 0x10a0f}, {0x10a38, 0x10a3a}, {0x10a3f, 0x10a3f}, {0x10ae5, 0x10ae6},
+ {0x10d24, 0x10d27}, {0x10eab, 0x10eac}, {0x10efd, 0x10eff}, {0x10f46, 0x10f50}, {0x10f82, 0x10f85}, {0x11001, 0x11001},
+ {0x11038, 0x11046}, {0x11070, 0x11070}, {0x11073, 0x11074}, {0x1107f, 0x11081}, {0x110b3, 0x110b6}, {0x110b9, 0x110ba},
+ {0x110bd, 0x110bd}, {0x110c2, 0x110c2}, {0x110cd, 0x110cd}, {0x11100, 0x11102}, {0x11127, 0x1112b}, {0x1112d, 0x11134},
+ {0x11173, 0x11173}, {0x11180, 0x11181}, {0x111b6, 0x111be}, {0x111c9, 0x111cc}, {0x111cf, 0x111cf}, {0x1122f, 0x11231},
+ {0x11234, 0x11234}, {0x11236, 0x11237}, {0x1123e, 0x1123e}, {0x11241, 0x11241}, {0x112df, 0x112df}, {0x112e3, 0x112ea},
+ {0x11300, 0x11301}, {0x1133b, 0x1133c}, {0x11340, 0x11340}, {0x11366, 0x1136c}, {0x11370, 0x11374}, {0x11438, 0x1143f},
+ {0x11442, 0x11444}, {0x11446, 0x11446}, {0x1145e, 0x1145e}, {0x114b3, 0x114b8}, {0x114ba, 0x114ba}, {0x114bf, 0x114c0},
+ {0x114c2, 0x114c3}, {0x115b2, 0x115b5}, {0x115bc, 0x115bd}, {0x115bf, 0x115c0}, {0x115dc, 0x115dd}, {0x11633, 0x1163a},
+ {0x1163d, 0x1163d}, {0x1163f, 0x11640}, {0x116ab, 0x116ab}, {0x116ad, 0x116ad}, {0x116b0, 0x116b5}, {0x116b7, 0x116b7},
+ {0x1171d, 0x1171f}, {0x11722, 0x11725}, {0x11727, 0x1172b}, {0x1182f, 0x11837}, {0x11839, 0x1183a}, {0x1193b, 0x1193c},
+ {0x1193e, 0x1193e}, {0x11943, 0x11943}, {0x119d4, 0x119d7}, {0x119da, 0x119db}, {0x119e0, 0x119e0}, {0x11a01, 0x11a0a},
+ {0x11a33, 0x11a38}, {0x11a3b, 0x11a3e}, {0x11a47, 0x11a47}, {0x11a51, 0x11a56}, {0x11a59, 0x11a5b}, {0x11a8a, 0x11a96},
+ {0x11a98, 0x11a99}, {0x11c30, 0x11c36}, {0x11c38, 0x11c3d}, {0x11c3f, 0x11c3f}, {0x11c92, 0x11ca7}, {0x11caa, 0x11cb0},
+ {0x11cb2, 0x11cb3}, {0x11cb5, 0x11cb6}, {0x11d31, 0x11d36}, {0x11d3a, 0x11d3a}, {0x11d3c, 0x11d3d}, {0x11d3f, 0x11d45},
+ {0x11d47, 0x11d47}, {0x11d90, 0x11d91}, {0x11d95, 0x11d95}, {0x11d97, 0x11d97}, {0x11ef3, 0x11ef4}, {0x11f00, 0x11f01},
+ {0x11f36, 0x11f3a}, {0x11f40, 0x11f40}, {0x11f42, 0x11f42}, {0x13430, 0x13440}, {0x13447, 0x13455}, {0x16af0, 0x16af4},
+ {0x16b30, 0x16b36}, {0x16b40, 0x16b43}, {0x16f4f, 0x16f4f}, {0x16f8f, 0x16f9f}, {0x16fe0, 0x16fe1}, {0x16fe3, 0x16fe4},
+ {0x1aff0, 0x1aff3}, {0x1aff5, 0x1affb}, {0x1affd, 0x1affe}, {0x1bc9d, 0x1bc9e}, {0x1bca0, 0x1bca3}, {0x1cf00, 0x1cf2d},
+ {0x1cf30, 0x1cf46}, {0x1d167, 0x1d169}, {0x1d173, 0x1d182}, {0x1d185, 0x1d18b}, {0x1d1aa, 0x1d1ad}, {0x1d242, 0x1d244},
+ {0x1da00, 0x1da36}, {0x1da3b, 0x1da6c}, {0x1da75, 0x1da75}, {0x1da84, 0x1da84}, {0x1da9b, 0x1da9f}, {0x1daa1, 0x1daaf},
+ {0x1e000, 0x1e006}, {0x1e008, 0x1e018}, {0x1e01b, 0x1e021}, {0x1e023, 0x1e024}, {0x1e026, 0x1e02a}, {0x1e030, 0x1e06d},
+ {0x1e08f, 0x1e08f}, {0x1e130, 0x1e13d}, {0x1e2ae, 0x1e2ae}, {0x1e2ec, 0x1e2ef}, {0x1e4eb, 0x1e4ef}, {0x1e8d0, 0x1e8d6},
+ {0x1e944, 0x1e94b}, {0x1f3fb, 0x1f3ff}, {0xe0001, 0xe0001}, {0xe0020, 0xe007f}, {0xe0100, 0xe01ef},
+};
+static const GlUniLower gl_uni_lower[1431] = {
+ {0x41, 0x61}, {0x42, 0x62}, {0x43, 0x63}, {0x44, 0x64}, {0x45, 0x65}, {0x46, 0x66},
+ {0x47, 0x67}, {0x48, 0x68}, {0x49, 0x69}, {0x4a, 0x6a}, {0x4b, 0x6b}, {0x4c, 0x6c},
+ {0x4d, 0x6d}, {0x4e, 0x6e}, {0x4f, 0x6f}, {0x50, 0x70}, {0x51, 0x71}, {0x52, 0x72},
+ {0x53, 0x73}, {0x54, 0x74}, {0x55, 0x75}, {0x56, 0x76}, {0x57, 0x77}, {0x58, 0x78},
+ {0x59, 0x79}, {0x5a, 0x7a}, {0xc0, 0xe0}, {0xc1, 0xe1}, {0xc2, 0xe2}, {0xc3, 0xe3},
+ {0xc4, 0xe4}, {0xc5, 0xe5}, {0xc6, 0xe6}, {0xc7, 0xe7}, {0xc8, 0xe8}, {0xc9, 0xe9},
+ {0xca, 0xea}, {0xcb, 0xeb}, {0xcc, 0xec}, {0xcd, 0xed}, {0xce, 0xee}, {0xcf, 0xef},
+ {0xd0, 0xf0}, {0xd1, 0xf1}, {0xd2, 0xf2}, {0xd3, 0xf3}, {0xd4, 0xf4}, {0xd5, 0xf5},
+ {0xd6, 0xf6}, {0xd8, 0xf8}, {0xd9, 0xf9}, {0xda, 0xfa}, {0xdb, 0xfb}, {0xdc, 0xfc},
+ {0xdd, 0xfd}, {0xde, 0xfe}, {0x100, 0x101}, {0x102, 0x103}, {0x104, 0x105}, {0x106, 0x107},
+ {0x108, 0x109}, {0x10a, 0x10b}, {0x10c, 0x10d}, {0x10e, 0x10f}, {0x110, 0x111}, {0x112, 0x113},
+ {0x114, 0x115}, {0x116, 0x117}, {0x118, 0x119}, {0x11a, 0x11b}, {0x11c, 0x11d}, {0x11e, 0x11f},
+ {0x120, 0x121}, {0x122, 0x123}, {0x124, 0x125}, {0x126, 0x127}, {0x128, 0x129}, {0x12a, 0x12b},
+ {0x12c, 0x12d}, {0x12e, 0x12f}, {0x132, 0x133}, {0x134, 0x135}, {0x136, 0x137}, {0x139, 0x13a},
+ {0x13b, 0x13c}, {0x13d, 0x13e}, {0x13f, 0x140}, {0x141, 0x142}, {0x143, 0x144}, {0x145, 0x146},
+ {0x147, 0x148}, {0x14a, 0x14b}, {0x14c, 0x14d}, {0x14e, 0x14f}, {0x150, 0x151}, {0x152, 0x153},
+ {0x154, 0x155}, {0x156, 0x157}, {0x158, 0x159}, {0x15a, 0x15b}, {0x15c, 0x15d}, {0x15e, 0x15f},
+ {0x160, 0x161}, {0x162, 0x163}, {0x164, 0x165}, {0x166, 0x167}, {0x168, 0x169}, {0x16a, 0x16b},
+ {0x16c, 0x16d}, {0x16e, 0x16f}, {0x170, 0x171}, {0x172, 0x173}, {0x174, 0x175}, {0x176, 0x177},
+ {0x178, 0xff}, {0x179, 0x17a}, {0x17b, 0x17c}, {0x17d, 0x17e}, {0x181, 0x253}, {0x182, 0x183},
+ {0x184, 0x185}, {0x186, 0x254}, {0x187, 0x188}, {0x189, 0x256}, {0x18a, 0x257}, {0x18b, 0x18c},
+ {0x18e, 0x1dd}, {0x18f, 0x259}, {0x190, 0x25b}, {0x191, 0x192}, {0x193, 0x260}, {0x194, 0x263},
+ {0x196, 0x269}, {0x197, 0x268}, {0x198, 0x199}, {0x19c, 0x26f}, {0x19d, 0x272}, {0x19f, 0x275},
+ {0x1a0, 0x1a1}, {0x1a2, 0x1a3}, {0x1a4, 0x1a5}, {0x1a6, 0x280}, {0x1a7, 0x1a8}, {0x1a9, 0x283},
+ {0x1ac, 0x1ad}, {0x1ae, 0x288}, {0x1af, 0x1b0}, {0x1b1, 0x28a}, {0x1b2, 0x28b}, {0x1b3, 0x1b4},
+ {0x1b5, 0x1b6}, {0x1b7, 0x292}, {0x1b8, 0x1b9}, {0x1bc, 0x1bd}, {0x1c4, 0x1c6}, {0x1c5, 0x1c6},
+ {0x1c7, 0x1c9}, {0x1c8, 0x1c9}, {0x1ca, 0x1cc}, {0x1cb, 0x1cc}, {0x1cd, 0x1ce}, {0x1cf, 0x1d0},
+ {0x1d1, 0x1d2}, {0x1d3, 0x1d4}, {0x1d5, 0x1d6}, {0x1d7, 0x1d8}, {0x1d9, 0x1da}, {0x1db, 0x1dc},
+ {0x1de, 0x1df}, {0x1e0, 0x1e1}, {0x1e2, 0x1e3}, {0x1e4, 0x1e5}, {0x1e6, 0x1e7}, {0x1e8, 0x1e9},
+ {0x1ea, 0x1eb}, {0x1ec, 0x1ed}, {0x1ee, 0x1ef}, {0x1f1, 0x1f3}, {0x1f2, 0x1f3}, {0x1f4, 0x1f5},
+ {0x1f6, 0x195}, {0x1f7, 0x1bf}, {0x1f8, 0x1f9}, {0x1fa, 0x1fb}, {0x1fc, 0x1fd}, {0x1fe, 0x1ff},
+ {0x200, 0x201}, {0x202, 0x203}, {0x204, 0x205}, {0x206, 0x207}, {0x208, 0x209}, {0x20a, 0x20b},
+ {0x20c, 0x20d}, {0x20e, 0x20f}, {0x210, 0x211}, {0x212, 0x213}, {0x214, 0x215}, {0x216, 0x217},
+ {0x218, 0x219}, {0x21a, 0x21b}, {0x21c, 0x21d}, {0x21e, 0x21f}, {0x220, 0x19e}, {0x222, 0x223},
+ {0x224, 0x225}, {0x226, 0x227}, {0x228, 0x229}, {0x22a, 0x22b}, {0x22c, 0x22d}, {0x22e, 0x22f},
+ {0x230, 0x231}, {0x232, 0x233}, {0x23a, 0x2c65}, {0x23b, 0x23c}, {0x23d, 0x19a}, {0x23e, 0x2c66},
+ {0x241, 0x242}, {0x243, 0x180}, {0x244, 0x289}, {0x245, 0x28c}, {0x246, 0x247}, {0x248, 0x249},
+ {0x24a, 0x24b}, {0x24c, 0x24d}, {0x24e, 0x24f}, {0x370, 0x371}, {0x372, 0x373}, {0x376, 0x377},
+ {0x37f, 0x3f3}, {0x386, 0x3ac}, {0x388, 0x3ad}, {0x389, 0x3ae}, {0x38a, 0x3af}, {0x38c, 0x3cc},
+ {0x38e, 0x3cd}, {0x38f, 0x3ce}, {0x391, 0x3b1}, {0x392, 0x3b2}, {0x393, 0x3b3}, {0x394, 0x3b4},
+ {0x395, 0x3b5}, {0x396, 0x3b6}, {0x397, 0x3b7}, {0x398, 0x3b8}, {0x399, 0x3b9}, {0x39a, 0x3ba},
+ {0x39b, 0x3bb}, {0x39c, 0x3bc}, {0x39d, 0x3bd}, {0x39e, 0x3be}, {0x39f, 0x3bf}, {0x3a0, 0x3c0},
+ {0x3a1, 0x3c1}, {0x3a4, 0x3c4}, {0x3a5, 0x3c5}, {0x3a6, 0x3c6}, {0x3a7, 0x3c7}, {0x3a8, 0x3c8},
+ {0x3a9, 0x3c9}, {0x3aa, 0x3ca}, {0x3ab, 0x3cb}, {0x3cf, 0x3d7}, {0x3d8, 0x3d9}, {0x3da, 0x3db},
+ {0x3dc, 0x3dd}, {0x3de, 0x3df}, {0x3e0, 0x3e1}, {0x3e2, 0x3e3}, {0x3e4, 0x3e5}, {0x3e6, 0x3e7},
+ {0x3e8, 0x3e9}, {0x3ea, 0x3eb}, {0x3ec, 0x3ed}, {0x3ee, 0x3ef}, {0x3f4, 0x3b8}, {0x3f7, 0x3f8},
+ {0x3f9, 0x3f2}, {0x3fa, 0x3fb}, {0x3fd, 0x37b}, {0x3fe, 0x37c}, {0x3ff, 0x37d}, {0x400, 0x450},
+ {0x401, 0x451}, {0x402, 0x452}, {0x403, 0x453}, {0x404, 0x454}, {0x405, 0x455}, {0x406, 0x456},
+ {0x407, 0x457}, {0x408, 0x458}, {0x409, 0x459}, {0x40a, 0x45a}, {0x40b, 0x45b}, {0x40c, 0x45c},
+ {0x40d, 0x45d}, {0x40e, 0x45e}, {0x40f, 0x45f}, {0x410, 0x430}, {0x411, 0x431}, {0x412, 0x432},
+ {0x413, 0x433}, {0x414, 0x434}, {0x415, 0x435}, {0x416, 0x436}, {0x417, 0x437}, {0x418, 0x438},
+ {0x419, 0x439}, {0x41a, 0x43a}, {0x41b, 0x43b}, {0x41c, 0x43c}, {0x41d, 0x43d}, {0x41e, 0x43e},
+ {0x41f, 0x43f}, {0x420, 0x440}, {0x421, 0x441}, {0x422, 0x442}, {0x423, 0x443}, {0x424, 0x444},
+ {0x425, 0x445}, {0x426, 0x446}, {0x427, 0x447}, {0x428, 0x448}, {0x429, 0x449}, {0x42a, 0x44a},
+ {0x42b, 0x44b}, {0x42c, 0x44c}, {0x42d, 0x44d}, {0x42e, 0x44e}, {0x42f, 0x44f}, {0x460, 0x461},
+ {0x462, 0x463}, {0x464, 0x465}, {0x466, 0x467}, {0x468, 0x469}, {0x46a, 0x46b}, {0x46c, 0x46d},
+ {0x46e, 0x46f}, {0x470, 0x471}, {0x472, 0x473}, {0x474, 0x475}, {0x476, 0x477}, {0x478, 0x479},
+ {0x47a, 0x47b}, {0x47c, 0x47d}, {0x47e, 0x47f}, {0x480, 0x481}, {0x48a, 0x48b}, {0x48c, 0x48d},
+ {0x48e, 0x48f}, {0x490, 0x491}, {0x492, 0x493}, {0x494, 0x495}, {0x496, 0x497}, {0x498, 0x499},
+ {0x49a, 0x49b}, {0x49c, 0x49d}, {0x49e, 0x49f}, {0x4a0, 0x4a1}, {0x4a2, 0x4a3}, {0x4a4, 0x4a5},
+ {0x4a6, 0x4a7}, {0x4a8, 0x4a9}, {0x4aa, 0x4ab}, {0x4ac, 0x4ad}, {0x4ae, 0x4af}, {0x4b0, 0x4b1},
+ {0x4b2, 0x4b3}, {0x4b4, 0x4b5}, {0x4b6, 0x4b7}, {0x4b8, 0x4b9}, {0x4ba, 0x4bb}, {0x4bc, 0x4bd},
+ {0x4be, 0x4bf}, {0x4c0, 0x4cf}, {0x4c1, 0x4c2}, {0x4c3, 0x4c4}, {0x4c5, 0x4c6}, {0x4c7, 0x4c8},
+ {0x4c9, 0x4ca}, {0x4cb, 0x4cc}, {0x4cd, 0x4ce}, {0x4d0, 0x4d1}, {0x4d2, 0x4d3}, {0x4d4, 0x4d5},
+ {0x4d6, 0x4d7}, {0x4d8, 0x4d9}, {0x4da, 0x4db}, {0x4dc, 0x4dd}, {0x4de, 0x4df}, {0x4e0, 0x4e1},
+ {0x4e2, 0x4e3}, {0x4e4, 0x4e5}, {0x4e6, 0x4e7}, {0x4e8, 0x4e9}, {0x4ea, 0x4eb}, {0x4ec, 0x4ed},
+ {0x4ee, 0x4ef}, {0x4f0, 0x4f1}, {0x4f2, 0x4f3}, {0x4f4, 0x4f5}, {0x4f6, 0x4f7}, {0x4f8, 0x4f9},
+ {0x4fa, 0x4fb}, {0x4fc, 0x4fd}, {0x4fe, 0x4ff}, {0x500, 0x501}, {0x502, 0x503}, {0x504, 0x505},
+ {0x506, 0x507}, {0x508, 0x509}, {0x50a, 0x50b}, {0x50c, 0x50d}, {0x50e, 0x50f}, {0x510, 0x511},
+ {0x512, 0x513}, {0x514, 0x515}, {0x516, 0x517}, {0x518, 0x519}, {0x51a, 0x51b}, {0x51c, 0x51d},
+ {0x51e, 0x51f}, {0x520, 0x521}, {0x522, 0x523}, {0x524, 0x525}, {0x526, 0x527}, {0x528, 0x529},
+ {0x52a, 0x52b}, {0x52c, 0x52d}, {0x52e, 0x52f}, {0x531, 0x561}, {0x532, 0x562}, {0x533, 0x563},
+ {0x534, 0x564}, {0x535, 0x565}, {0x536, 0x566}, {0x537, 0x567}, {0x538, 0x568}, {0x539, 0x569},
+ {0x53a, 0x56a}, {0x53b, 0x56b}, {0x53c, 0x56c}, {0x53d, 0x56d}, {0x53e, 0x56e}, {0x53f, 0x56f},
+ {0x540, 0x570}, {0x541, 0x571}, {0x542, 0x572}, {0x543, 0x573}, {0x544, 0x574}, {0x545, 0x575},
+ {0x546, 0x576}, {0x547, 0x577}, {0x548, 0x578}, {0x549, 0x579}, {0x54a, 0x57a}, {0x54b, 0x57b},
+ {0x54c, 0x57c}, {0x54d, 0x57d}, {0x54e, 0x57e}, {0x54f, 0x57f}, {0x550, 0x580}, {0x551, 0x581},
+ {0x552, 0x582}, {0x553, 0x583}, {0x554, 0x584}, {0x555, 0x585}, {0x556, 0x586}, {0x10a0, 0x2d00},
+ {0x10a1, 0x2d01}, {0x10a2, 0x2d02}, {0x10a3, 0x2d03}, {0x10a4, 0x2d04}, {0x10a5, 0x2d05}, {0x10a6, 0x2d06},
+ {0x10a7, 0x2d07}, {0x10a8, 0x2d08}, {0x10a9, 0x2d09}, {0x10aa, 0x2d0a}, {0x10ab, 0x2d0b}, {0x10ac, 0x2d0c},
+ {0x10ad, 0x2d0d}, {0x10ae, 0x2d0e}, {0x10af, 0x2d0f}, {0x10b0, 0x2d10}, {0x10b1, 0x2d11}, {0x10b2, 0x2d12},
+ {0x10b3, 0x2d13}, {0x10b4, 0x2d14}, {0x10b5, 0x2d15}, {0x10b6, 0x2d16}, {0x10b7, 0x2d17}, {0x10b8, 0x2d18},
+ {0x10b9, 0x2d19}, {0x10ba, 0x2d1a}, {0x10bb, 0x2d1b}, {0x10bc, 0x2d1c}, {0x10bd, 0x2d1d}, {0x10be, 0x2d1e},
+ {0x10bf, 0x2d1f}, {0x10c0, 0x2d20}, {0x10c1, 0x2d21}, {0x10c2, 0x2d22}, {0x10c3, 0x2d23}, {0x10c4, 0x2d24},
+ {0x10c5, 0x2d25}, {0x10c7, 0x2d27}, {0x10cd, 0x2d2d}, {0x13a0, 0xab70}, {0x13a1, 0xab71}, {0x13a2, 0xab72},
+ {0x13a3, 0xab73}, {0x13a4, 0xab74}, {0x13a5, 0xab75}, {0x13a6, 0xab76}, {0x13a7, 0xab77}, {0x13a8, 0xab78},
+ {0x13a9, 0xab79}, {0x13aa, 0xab7a}, {0x13ab, 0xab7b}, {0x13ac, 0xab7c}, {0x13ad, 0xab7d}, {0x13ae, 0xab7e},
+ {0x13af, 0xab7f}, {0x13b0, 0xab80}, {0x13b1, 0xab81}, {0x13b2, 0xab82}, {0x13b3, 0xab83}, {0x13b4, 0xab84},
+ {0x13b5, 0xab85}, {0x13b6, 0xab86}, {0x13b7, 0xab87}, {0x13b8, 0xab88}, {0x13b9, 0xab89}, {0x13ba, 0xab8a},
+ {0x13bb, 0xab8b}, {0x13bc, 0xab8c}, {0x13bd, 0xab8d}, {0x13be, 0xab8e}, {0x13bf, 0xab8f}, {0x13c0, 0xab90},
+ {0x13c1, 0xab91}, {0x13c2, 0xab92}, {0x13c3, 0xab93}, {0x13c4, 0xab94}, {0x13c5, 0xab95}, {0x13c6, 0xab96},
+ {0x13c7, 0xab97}, {0x13c8, 0xab98}, {0x13c9, 0xab99}, {0x13ca, 0xab9a}, {0x13cb, 0xab9b}, {0x13cc, 0xab9c},
+ {0x13cd, 0xab9d}, {0x13ce, 0xab9e}, {0x13cf, 0xab9f}, {0x13d0, 0xaba0}, {0x13d1, 0xaba1}, {0x13d2, 0xaba2},
+ {0x13d3, 0xaba3}, {0x13d4, 0xaba4}, {0x13d5, 0xaba5}, {0x13d6, 0xaba6}, {0x13d7, 0xaba7}, {0x13d8, 0xaba8},
+ {0x13d9, 0xaba9}, {0x13da, 0xabaa}, {0x13db, 0xabab}, {0x13dc, 0xabac}, {0x13dd, 0xabad}, {0x13de, 0xabae},
+ {0x13df, 0xabaf}, {0x13e0, 0xabb0}, {0x13e1, 0xabb1}, {0x13e2, 0xabb2}, {0x13e3, 0xabb3}, {0x13e4, 0xabb4},
+ {0x13e5, 0xabb5}, {0x13e6, 0xabb6}, {0x13e7, 0xabb7}, {0x13e8, 0xabb8}, {0x13e9, 0xabb9}, {0x13ea, 0xabba},
+ {0x13eb, 0xabbb}, {0x13ec, 0xabbc}, {0x13ed, 0xabbd}, {0x13ee, 0xabbe}, {0x13ef, 0xabbf}, {0x13f0, 0x13f8},
+ {0x13f1, 0x13f9}, {0x13f2, 0x13fa}, {0x13f3, 0x13fb}, {0x13f4, 0x13fc}, {0x13f5, 0x13fd}, {0x1c90, 0x10d0},
+ {0x1c91, 0x10d1}, {0x1c92, 0x10d2}, {0x1c93, 0x10d3}, {0x1c94, 0x10d4}, {0x1c95, 0x10d5}, {0x1c96, 0x10d6},
+ {0x1c97, 0x10d7}, {0x1c98, 0x10d8}, {0x1c99, 0x10d9}, {0x1c9a, 0x10da}, {0x1c9b, 0x10db}, {0x1c9c, 0x10dc},
+ {0x1c9d, 0x10dd}, {0x1c9e, 0x10de}, {0x1c9f, 0x10df}, {0x1ca0, 0x10e0}, {0x1ca1, 0x10e1}, {0x1ca2, 0x10e2},
+ {0x1ca3, 0x10e3}, {0x1ca4, 0x10e4}, {0x1ca5, 0x10e5}, {0x1ca6, 0x10e6}, {0x1ca7, 0x10e7}, {0x1ca8, 0x10e8},
+ {0x1ca9, 0x10e9}, {0x1caa, 0x10ea}, {0x1cab, 0x10eb}, {0x1cac, 0x10ec}, {0x1cad, 0x10ed}, {0x1cae, 0x10ee},
+ {0x1caf, 0x10ef}, {0x1cb0, 0x10f0}, {0x1cb1, 0x10f1}, {0x1cb2, 0x10f2}, {0x1cb3, 0x10f3}, {0x1cb4, 0x10f4},
+ {0x1cb5, 0x10f5}, {0x1cb6, 0x10f6}, {0x1cb7, 0x10f7}, {0x1cb8, 0x10f8}, {0x1cb9, 0x10f9}, {0x1cba, 0x10fa},
+ {0x1cbd, 0x10fd}, {0x1cbe, 0x10fe}, {0x1cbf, 0x10ff}, {0x1e00, 0x1e01}, {0x1e02, 0x1e03}, {0x1e04, 0x1e05},
+ {0x1e06, 0x1e07}, {0x1e08, 0x1e09}, {0x1e0a, 0x1e0b}, {0x1e0c, 0x1e0d}, {0x1e0e, 0x1e0f}, {0x1e10, 0x1e11},
+ {0x1e12, 0x1e13}, {0x1e14, 0x1e15}, {0x1e16, 0x1e17}, {0x1e18, 0x1e19}, {0x1e1a, 0x1e1b}, {0x1e1c, 0x1e1d},
+ {0x1e1e, 0x1e1f}, {0x1e20, 0x1e21}, {0x1e22, 0x1e23}, {0x1e24, 0x1e25}, {0x1e26, 0x1e27}, {0x1e28, 0x1e29},
+ {0x1e2a, 0x1e2b}, {0x1e2c, 0x1e2d}, {0x1e2e, 0x1e2f}, {0x1e30, 0x1e31}, {0x1e32, 0x1e33}, {0x1e34, 0x1e35},
+ {0x1e36, 0x1e37}, {0x1e38, 0x1e39}, {0x1e3a, 0x1e3b}, {0x1e3c, 0x1e3d}, {0x1e3e, 0x1e3f}, {0x1e40, 0x1e41},
+ {0x1e42, 0x1e43}, {0x1e44, 0x1e45}, {0x1e46, 0x1e47}, {0x1e48, 0x1e49}, {0x1e4a, 0x1e4b}, {0x1e4c, 0x1e4d},
+ {0x1e4e, 0x1e4f}, {0x1e50, 0x1e51}, {0x1e52, 0x1e53}, {0x1e54, 0x1e55}, {0x1e56, 0x1e57}, {0x1e58, 0x1e59},
+ {0x1e5a, 0x1e5b}, {0x1e5c, 0x1e5d}, {0x1e5e, 0x1e5f}, {0x1e60, 0x1e61}, {0x1e62, 0x1e63}, {0x1e64, 0x1e65},
+ {0x1e66, 0x1e67}, {0x1e68, 0x1e69}, {0x1e6a, 0x1e6b}, {0x1e6c, 0x1e6d}, {0x1e6e, 0x1e6f}, {0x1e70, 0x1e71},
+ {0x1e72, 0x1e73}, {0x1e74, 0x1e75}, {0x1e76, 0x1e77}, {0x1e78, 0x1e79}, {0x1e7a, 0x1e7b}, {0x1e7c, 0x1e7d},
+ {0x1e7e, 0x1e7f}, {0x1e80, 0x1e81}, {0x1e82, 0x1e83}, {0x1e84, 0x1e85}, {0x1e86, 0x1e87}, {0x1e88, 0x1e89},
+ {0x1e8a, 0x1e8b}, {0x1e8c, 0x1e8d}, {0x1e8e, 0x1e8f}, {0x1e90, 0x1e91}, {0x1e92, 0x1e93}, {0x1e94, 0x1e95},
+ {0x1e9e, 0xdf}, {0x1ea0, 0x1ea1}, {0x1ea2, 0x1ea3}, {0x1ea4, 0x1ea5}, {0x1ea6, 0x1ea7}, {0x1ea8, 0x1ea9},
+ {0x1eaa, 0x1eab}, {0x1eac, 0x1ead}, {0x1eae, 0x1eaf}, {0x1eb0, 0x1eb1}, {0x1eb2, 0x1eb3}, {0x1eb4, 0x1eb5},
+ {0x1eb6, 0x1eb7}, {0x1eb8, 0x1eb9}, {0x1eba, 0x1ebb}, {0x1ebc, 0x1ebd}, {0x1ebe, 0x1ebf}, {0x1ec0, 0x1ec1},
+ {0x1ec2, 0x1ec3}, {0x1ec4, 0x1ec5}, {0x1ec6, 0x1ec7}, {0x1ec8, 0x1ec9}, {0x1eca, 0x1ecb}, {0x1ecc, 0x1ecd},
+ {0x1ece, 0x1ecf}, {0x1ed0, 0x1ed1}, {0x1ed2, 0x1ed3}, {0x1ed4, 0x1ed5}, {0x1ed6, 0x1ed7}, {0x1ed8, 0x1ed9},
+ {0x1eda, 0x1edb}, {0x1edc, 0x1edd}, {0x1ede, 0x1edf}, {0x1ee0, 0x1ee1}, {0x1ee2, 0x1ee3}, {0x1ee4, 0x1ee5},
+ {0x1ee6, 0x1ee7}, {0x1ee8, 0x1ee9}, {0x1eea, 0x1eeb}, {0x1eec, 0x1eed}, {0x1eee, 0x1eef}, {0x1ef0, 0x1ef1},
+ {0x1ef2, 0x1ef3}, {0x1ef4, 0x1ef5}, {0x1ef6, 0x1ef7}, {0x1ef8, 0x1ef9}, {0x1efa, 0x1efb}, {0x1efc, 0x1efd},
+ {0x1efe, 0x1eff}, {0x1f08, 0x1f00}, {0x1f09, 0x1f01}, {0x1f0a, 0x1f02}, {0x1f0b, 0x1f03}, {0x1f0c, 0x1f04},
+ {0x1f0d, 0x1f05}, {0x1f0e, 0x1f06}, {0x1f0f, 0x1f07}, {0x1f18, 0x1f10}, {0x1f19, 0x1f11}, {0x1f1a, 0x1f12},
+ {0x1f1b, 0x1f13}, {0x1f1c, 0x1f14}, {0x1f1d, 0x1f15}, {0x1f28, 0x1f20}, {0x1f29, 0x1f21}, {0x1f2a, 0x1f22},
+ {0x1f2b, 0x1f23}, {0x1f2c, 0x1f24}, {0x1f2d, 0x1f25}, {0x1f2e, 0x1f26}, {0x1f2f, 0x1f27}, {0x1f38, 0x1f30},
+ {0x1f39, 0x1f31}, {0x1f3a, 0x1f32}, {0x1f3b, 0x1f33}, {0x1f3c, 0x1f34}, {0x1f3d, 0x1f35}, {0x1f3e, 0x1f36},
+ {0x1f3f, 0x1f37}, {0x1f48, 0x1f40}, {0x1f49, 0x1f41}, {0x1f4a, 0x1f42}, {0x1f4b, 0x1f43}, {0x1f4c, 0x1f44},
+ {0x1f4d, 0x1f45}, {0x1f59, 0x1f51}, {0x1f5b, 0x1f53}, {0x1f5d, 0x1f55}, {0x1f5f, 0x1f57}, {0x1f68, 0x1f60},
+ {0x1f69, 0x1f61}, {0x1f6a, 0x1f62}, {0x1f6b, 0x1f63}, {0x1f6c, 0x1f64}, {0x1f6d, 0x1f65}, {0x1f6e, 0x1f66},
+ {0x1f6f, 0x1f67}, {0x1f88, 0x1f80}, {0x1f89, 0x1f81}, {0x1f8a, 0x1f82}, {0x1f8b, 0x1f83}, {0x1f8c, 0x1f84},
+ {0x1f8d, 0x1f85}, {0x1f8e, 0x1f86}, {0x1f8f, 0x1f87}, {0x1f98, 0x1f90}, {0x1f99, 0x1f91}, {0x1f9a, 0x1f92},
+ {0x1f9b, 0x1f93}, {0x1f9c, 0x1f94}, {0x1f9d, 0x1f95}, {0x1f9e, 0x1f96}, {0x1f9f, 0x1f97}, {0x1fa8, 0x1fa0},
+ {0x1fa9, 0x1fa1}, {0x1faa, 0x1fa2}, {0x1fab, 0x1fa3}, {0x1fac, 0x1fa4}, {0x1fad, 0x1fa5}, {0x1fae, 0x1fa6},
+ {0x1faf, 0x1fa7}, {0x1fb8, 0x1fb0}, {0x1fb9, 0x1fb1}, {0x1fba, 0x1f70}, {0x1fbb, 0x1f71}, {0x1fbc, 0x1fb3},
+ {0x1fc8, 0x1f72}, {0x1fc9, 0x1f73}, {0x1fca, 0x1f74}, {0x1fcb, 0x1f75}, {0x1fcc, 0x1fc3}, {0x1fd8, 0x1fd0},
+ {0x1fd9, 0x1fd1}, {0x1fda, 0x1f76}, {0x1fdb, 0x1f77}, {0x1fe8, 0x1fe0}, {0x1fe9, 0x1fe1}, {0x1fea, 0x1f7a},
+ {0x1feb, 0x1f7b}, {0x1fec, 0x1fe5}, {0x1ff8, 0x1f78}, {0x1ff9, 0x1f79}, {0x1ffa, 0x1f7c}, {0x1ffb, 0x1f7d},
+ {0x1ffc, 0x1ff3}, {0x2126, 0x3c9}, {0x212a, 0x6b}, {0x212b, 0xe5}, {0x2132, 0x214e}, {0x2160, 0x2170},
+ {0x2161, 0x2171}, {0x2162, 0x2172}, {0x2163, 0x2173}, {0x2164, 0x2174}, {0x2165, 0x2175}, {0x2166, 0x2176},
+ {0x2167, 0x2177}, {0x2168, 0x2178}, {0x2169, 0x2179}, {0x216a, 0x217a}, {0x216b, 0x217b}, {0x216c, 0x217c},
+ {0x216d, 0x217d}, {0x216e, 0x217e}, {0x216f, 0x217f}, {0x2183, 0x2184}, {0x24b6, 0x24d0}, {0x24b7, 0x24d1},
+ {0x24b8, 0x24d2}, {0x24b9, 0x24d3}, {0x24ba, 0x24d4}, {0x24bb, 0x24d5}, {0x24bc, 0x24d6}, {0x24bd, 0x24d7},
+ {0x24be, 0x24d8}, {0x24bf, 0x24d9}, {0x24c0, 0x24da}, {0x24c1, 0x24db}, {0x24c2, 0x24dc}, {0x24c3, 0x24dd},
+ {0x24c4, 0x24de}, {0x24c5, 0x24df}, {0x24c6, 0x24e0}, {0x24c7, 0x24e1}, {0x24c8, 0x24e2}, {0x24c9, 0x24e3},
+ {0x24ca, 0x24e4}, {0x24cb, 0x24e5}, {0x24cc, 0x24e6}, {0x24cd, 0x24e7}, {0x24ce, 0x24e8}, {0x24cf, 0x24e9},
+ {0x2c00, 0x2c30}, {0x2c01, 0x2c31}, {0x2c02, 0x2c32}, {0x2c03, 0x2c33}, {0x2c04, 0x2c34}, {0x2c05, 0x2c35},
+ {0x2c06, 0x2c36}, {0x2c07, 0x2c37}, {0x2c08, 0x2c38}, {0x2c09, 0x2c39}, {0x2c0a, 0x2c3a}, {0x2c0b, 0x2c3b},
+ {0x2c0c, 0x2c3c}, {0x2c0d, 0x2c3d}, {0x2c0e, 0x2c3e}, {0x2c0f, 0x2c3f}, {0x2c10, 0x2c40}, {0x2c11, 0x2c41},
+ {0x2c12, 0x2c42}, {0x2c13, 0x2c43}, {0x2c14, 0x2c44}, {0x2c15, 0x2c45}, {0x2c16, 0x2c46}, {0x2c17, 0x2c47},
+ {0x2c18, 0x2c48}, {0x2c19, 0x2c49}, {0x2c1a, 0x2c4a}, {0x2c1b, 0x2c4b}, {0x2c1c, 0x2c4c}, {0x2c1d, 0x2c4d},
+ {0x2c1e, 0x2c4e}, {0x2c1f, 0x2c4f}, {0x2c20, 0x2c50}, {0x2c21, 0x2c51}, {0x2c22, 0x2c52}, {0x2c23, 0x2c53},
+ {0x2c24, 0x2c54}, {0x2c25, 0x2c55}, {0x2c26, 0x2c56}, {0x2c27, 0x2c57}, {0x2c28, 0x2c58}, {0x2c29, 0x2c59},
+ {0x2c2a, 0x2c5a}, {0x2c2b, 0x2c5b}, {0x2c2c, 0x2c5c}, {0x2c2d, 0x2c5d}, {0x2c2e, 0x2c5e}, {0x2c2f, 0x2c5f},
+ {0x2c60, 0x2c61}, {0x2c62, 0x26b}, {0x2c63, 0x1d7d}, {0x2c64, 0x27d}, {0x2c67, 0x2c68}, {0x2c69, 0x2c6a},
+ {0x2c6b, 0x2c6c}, {0x2c6d, 0x251}, {0x2c6e, 0x271}, {0x2c6f, 0x250}, {0x2c70, 0x252}, {0x2c72, 0x2c73},
+ {0x2c75, 0x2c76}, {0x2c7e, 0x23f}, {0x2c7f, 0x240}, {0x2c80, 0x2c81}, {0x2c82, 0x2c83}, {0x2c84, 0x2c85},
+ {0x2c86, 0x2c87}, {0x2c88, 0x2c89}, {0x2c8a, 0x2c8b}, {0x2c8c, 0x2c8d}, {0x2c8e, 0x2c8f}, {0x2c90, 0x2c91},
+ {0x2c92, 0x2c93}, {0x2c94, 0x2c95}, {0x2c96, 0x2c97}, {0x2c98, 0x2c99}, {0x2c9a, 0x2c9b}, {0x2c9c, 0x2c9d},
+ {0x2c9e, 0x2c9f}, {0x2ca0, 0x2ca1}, {0x2ca2, 0x2ca3}, {0x2ca4, 0x2ca5}, {0x2ca6, 0x2ca7}, {0x2ca8, 0x2ca9},
+ {0x2caa, 0x2cab}, {0x2cac, 0x2cad}, {0x2cae, 0x2caf}, {0x2cb0, 0x2cb1}, {0x2cb2, 0x2cb3}, {0x2cb4, 0x2cb5},
+ {0x2cb6, 0x2cb7}, {0x2cb8, 0x2cb9}, {0x2cba, 0x2cbb}, {0x2cbc, 0x2cbd}, {0x2cbe, 0x2cbf}, {0x2cc0, 0x2cc1},
+ {0x2cc2, 0x2cc3}, {0x2cc4, 0x2cc5}, {0x2cc6, 0x2cc7}, {0x2cc8, 0x2cc9}, {0x2cca, 0x2ccb}, {0x2ccc, 0x2ccd},
+ {0x2cce, 0x2ccf}, {0x2cd0, 0x2cd1}, {0x2cd2, 0x2cd3}, {0x2cd4, 0x2cd5}, {0x2cd6, 0x2cd7}, {0x2cd8, 0x2cd9},
+ {0x2cda, 0x2cdb}, {0x2cdc, 0x2cdd}, {0x2cde, 0x2cdf}, {0x2ce0, 0x2ce1}, {0x2ce2, 0x2ce3}, {0x2ceb, 0x2cec},
+ {0x2ced, 0x2cee}, {0x2cf2, 0x2cf3}, {0xa640, 0xa641}, {0xa642, 0xa643}, {0xa644, 0xa645}, {0xa646, 0xa647},
+ {0xa648, 0xa649}, {0xa64a, 0xa64b}, {0xa64c, 0xa64d}, {0xa64e, 0xa64f}, {0xa650, 0xa651}, {0xa652, 0xa653},
+ {0xa654, 0xa655}, {0xa656, 0xa657}, {0xa658, 0xa659}, {0xa65a, 0xa65b}, {0xa65c, 0xa65d}, {0xa65e, 0xa65f},
+ {0xa660, 0xa661}, {0xa662, 0xa663}, {0xa664, 0xa665}, {0xa666, 0xa667}, {0xa668, 0xa669}, {0xa66a, 0xa66b},
+ {0xa66c, 0xa66d}, {0xa680, 0xa681}, {0xa682, 0xa683}, {0xa684, 0xa685}, {0xa686, 0xa687}, {0xa688, 0xa689},
+ {0xa68a, 0xa68b}, {0xa68c, 0xa68d}, {0xa68e, 0xa68f}, {0xa690, 0xa691}, {0xa692, 0xa693}, {0xa694, 0xa695},
+ {0xa696, 0xa697}, {0xa698, 0xa699}, {0xa69a, 0xa69b}, {0xa722, 0xa723}, {0xa724, 0xa725}, {0xa726, 0xa727},
+ {0xa728, 0xa729}, {0xa72a, 0xa72b}, {0xa72c, 0xa72d}, {0xa72e, 0xa72f}, {0xa732, 0xa733}, {0xa734, 0xa735},
+ {0xa736, 0xa737}, {0xa738, 0xa739}, {0xa73a, 0xa73b}, {0xa73c, 0xa73d}, {0xa73e, 0xa73f}, {0xa740, 0xa741},
+ {0xa742, 0xa743}, {0xa744, 0xa745}, {0xa746, 0xa747}, {0xa748, 0xa749}, {0xa74a, 0xa74b}, {0xa74c, 0xa74d},
+ {0xa74e, 0xa74f}, {0xa750, 0xa751}, {0xa752, 0xa753}, {0xa754, 0xa755}, {0xa756, 0xa757}, {0xa758, 0xa759},
+ {0xa75a, 0xa75b}, {0xa75c, 0xa75d}, {0xa75e, 0xa75f}, {0xa760, 0xa761}, {0xa762, 0xa763}, {0xa764, 0xa765},
+ {0xa766, 0xa767}, {0xa768, 0xa769}, {0xa76a, 0xa76b}, {0xa76c, 0xa76d}, {0xa76e, 0xa76f}, {0xa779, 0xa77a},
+ {0xa77b, 0xa77c}, {0xa77d, 0x1d79}, {0xa77e, 0xa77f}, {0xa780, 0xa781}, {0xa782, 0xa783}, {0xa784, 0xa785},
+ {0xa786, 0xa787}, {0xa78b, 0xa78c}, {0xa78d, 0x265}, {0xa790, 0xa791}, {0xa792, 0xa793}, {0xa796, 0xa797},
+ {0xa798, 0xa799}, {0xa79a, 0xa79b}, {0xa79c, 0xa79d}, {0xa79e, 0xa79f}, {0xa7a0, 0xa7a1}, {0xa7a2, 0xa7a3},
+ {0xa7a4, 0xa7a5}, {0xa7a6, 0xa7a7}, {0xa7a8, 0xa7a9}, {0xa7aa, 0x266}, {0xa7ab, 0x25c}, {0xa7ac, 0x261},
+ {0xa7ad, 0x26c}, {0xa7ae, 0x26a}, {0xa7b0, 0x29e}, {0xa7b1, 0x287}, {0xa7b2, 0x29d}, {0xa7b3, 0xab53},
+ {0xa7b4, 0xa7b5}, {0xa7b6, 0xa7b7}, {0xa7b8, 0xa7b9}, {0xa7ba, 0xa7bb}, {0xa7bc, 0xa7bd}, {0xa7be, 0xa7bf},
+ {0xa7c0, 0xa7c1}, {0xa7c2, 0xa7c3}, {0xa7c4, 0xa794}, {0xa7c5, 0x282}, {0xa7c6, 0x1d8e}, {0xa7c7, 0xa7c8},
+ {0xa7c9, 0xa7ca}, {0xa7d0, 0xa7d1}, {0xa7d6, 0xa7d7}, {0xa7d8, 0xa7d9}, {0xa7f5, 0xa7f6}, {0xff21, 0xff41},
+ {0xff22, 0xff42}, {0xff23, 0xff43}, {0xff24, 0xff44}, {0xff25, 0xff45}, {0xff26, 0xff46}, {0xff27, 0xff47},
+ {0xff28, 0xff48}, {0xff29, 0xff49}, {0xff2a, 0xff4a}, {0xff2b, 0xff4b}, {0xff2c, 0xff4c}, {0xff2d, 0xff4d},
+ {0xff2e, 0xff4e}, {0xff2f, 0xff4f}, {0xff30, 0xff50}, {0xff31, 0xff51}, {0xff32, 0xff52}, {0xff33, 0xff53},
+ {0xff34, 0xff54}, {0xff35, 0xff55}, {0xff36, 0xff56}, {0xff37, 0xff57}, {0xff38, 0xff58}, {0xff39, 0xff59},
+ {0xff3a, 0xff5a}, {0x10400, 0x10428}, {0x10401, 0x10429}, {0x10402, 0x1042a}, {0x10403, 0x1042b}, {0x10404, 0x1042c},
+ {0x10405, 0x1042d}, {0x10406, 0x1042e}, {0x10407, 0x1042f}, {0x10408, 0x10430}, {0x10409, 0x10431}, {0x1040a, 0x10432},
+ {0x1040b, 0x10433}, {0x1040c, 0x10434}, {0x1040d, 0x10435}, {0x1040e, 0x10436}, {0x1040f, 0x10437}, {0x10410, 0x10438},
+ {0x10411, 0x10439}, {0x10412, 0x1043a}, {0x10413, 0x1043b}, {0x10414, 0x1043c}, {0x10415, 0x1043d}, {0x10416, 0x1043e},
+ {0x10417, 0x1043f}, {0x10418, 0x10440}, {0x10419, 0x10441}, {0x1041a, 0x10442}, {0x1041b, 0x10443}, {0x1041c, 0x10444},
+ {0x1041d, 0x10445}, {0x1041e, 0x10446}, {0x1041f, 0x10447}, {0x10420, 0x10448}, {0x10421, 0x10449}, {0x10422, 0x1044a},
+ {0x10423, 0x1044b}, {0x10424, 0x1044c}, {0x10425, 0x1044d}, {0x10426, 0x1044e}, {0x10427, 0x1044f}, {0x104b0, 0x104d8},
+ {0x104b1, 0x104d9}, {0x104b2, 0x104da}, {0x104b3, 0x104db}, {0x104b4, 0x104dc}, {0x104b5, 0x104dd}, {0x104b6, 0x104de},
+ {0x104b7, 0x104df}, {0x104b8, 0x104e0}, {0x104b9, 0x104e1}, {0x104ba, 0x104e2}, {0x104bb, 0x104e3}, {0x104bc, 0x104e4},
+ {0x104bd, 0x104e5}, {0x104be, 0x104e6}, {0x104bf, 0x104e7}, {0x104c0, 0x104e8}, {0x104c1, 0x104e9}, {0x104c2, 0x104ea},
+ {0x104c3, 0x104eb}, {0x104c4, 0x104ec}, {0x104c5, 0x104ed}, {0x104c6, 0x104ee}, {0x104c7, 0x104ef}, {0x104c8, 0x104f0},
+ {0x104c9, 0x104f1}, {0x104ca, 0x104f2}, {0x104cb, 0x104f3}, {0x104cc, 0x104f4}, {0x104cd, 0x104f5}, {0x104ce, 0x104f6},
+ {0x104cf, 0x104f7}, {0x104d0, 0x104f8}, {0x104d1, 0x104f9}, {0x104d2, 0x104fa}, {0x104d3, 0x104fb}, {0x10570, 0x10597},
+ {0x10571, 0x10598}, {0x10572, 0x10599}, {0x10573, 0x1059a}, {0x10574, 0x1059b}, {0x10575, 0x1059c}, {0x10576, 0x1059d},
+ {0x10577, 0x1059e}, {0x10578, 0x1059f}, {0x10579, 0x105a0}, {0x1057a, 0x105a1}, {0x1057c, 0x105a3}, {0x1057d, 0x105a4},
+ {0x1057e, 0x105a5}, {0x1057f, 0x105a6}, {0x10580, 0x105a7}, {0x10581, 0x105a8}, {0x10582, 0x105a9}, {0x10583, 0x105aa},
+ {0x10584, 0x105ab}, {0x10585, 0x105ac}, {0x10586, 0x105ad}, {0x10587, 0x105ae}, {0x10588, 0x105af}, {0x10589, 0x105b0},
+ {0x1058a, 0x105b1}, {0x1058c, 0x105b3}, {0x1058d, 0x105b4}, {0x1058e, 0x105b5}, {0x1058f, 0x105b6}, {0x10590, 0x105b7},
+ {0x10591, 0x105b8}, {0x10592, 0x105b9}, {0x10594, 0x105bb}, {0x10595, 0x105bc}, {0x10c80, 0x10cc0}, {0x10c81, 0x10cc1},
+ {0x10c82, 0x10cc2}, {0x10c83, 0x10cc3}, {0x10c84, 0x10cc4}, {0x10c85, 0x10cc5}, {0x10c86, 0x10cc6}, {0x10c87, 0x10cc7},
+ {0x10c88, 0x10cc8}, {0x10c89, 0x10cc9}, {0x10c8a, 0x10cca}, {0x10c8b, 0x10ccb}, {0x10c8c, 0x10ccc}, {0x10c8d, 0x10ccd},
+ {0x10c8e, 0x10cce}, {0x10c8f, 0x10ccf}, {0x10c90, 0x10cd0}, {0x10c91, 0x10cd1}, {0x10c92, 0x10cd2}, {0x10c93, 0x10cd3},
+ {0x10c94, 0x10cd4}, {0x10c95, 0x10cd5}, {0x10c96, 0x10cd6}, {0x10c97, 0x10cd7}, {0x10c98, 0x10cd8}, {0x10c99, 0x10cd9},
+ {0x10c9a, 0x10cda}, {0x10c9b, 0x10cdb}, {0x10c9c, 0x10cdc}, {0x10c9d, 0x10cdd}, {0x10c9e, 0x10cde}, {0x10c9f, 0x10cdf},
+ {0x10ca0, 0x10ce0}, {0x10ca1, 0x10ce1}, {0x10ca2, 0x10ce2}, {0x10ca3, 0x10ce3}, {0x10ca4, 0x10ce4}, {0x10ca5, 0x10ce5},
+ {0x10ca6, 0x10ce6}, {0x10ca7, 0x10ce7}, {0x10ca8, 0x10ce8}, {0x10ca9, 0x10ce9}, {0x10caa, 0x10cea}, {0x10cab, 0x10ceb},
+ {0x10cac, 0x10cec}, {0x10cad, 0x10ced}, {0x10cae, 0x10cee}, {0x10caf, 0x10cef}, {0x10cb0, 0x10cf0}, {0x10cb1, 0x10cf1},
+ {0x10cb2, 0x10cf2}, {0x118a0, 0x118c0}, {0x118a1, 0x118c1}, {0x118a2, 0x118c2}, {0x118a3, 0x118c3}, {0x118a4, 0x118c4},
+ {0x118a5, 0x118c5}, {0x118a6, 0x118c6}, {0x118a7, 0x118c7}, {0x118a8, 0x118c8}, {0x118a9, 0x118c9}, {0x118aa, 0x118ca},
+ {0x118ab, 0x118cb}, {0x118ac, 0x118cc}, {0x118ad, 0x118cd}, {0x118ae, 0x118ce}, {0x118af, 0x118cf}, {0x118b0, 0x118d0},
+ {0x118b1, 0x118d1}, {0x118b2, 0x118d2}, {0x118b3, 0x118d3}, {0x118b4, 0x118d4}, {0x118b5, 0x118d5}, {0x118b6, 0x118d6},
+ {0x118b7, 0x118d7}, {0x118b8, 0x118d8}, {0x118b9, 0x118d9}, {0x118ba, 0x118da}, {0x118bb, 0x118db}, {0x118bc, 0x118dc},
+ {0x118bd, 0x118dd}, {0x118be, 0x118de}, {0x118bf, 0x118df}, {0x16e40, 0x16e60}, {0x16e41, 0x16e61}, {0x16e42, 0x16e62},
+ {0x16e43, 0x16e63}, {0x16e44, 0x16e64}, {0x16e45, 0x16e65}, {0x16e46, 0x16e66}, {0x16e47, 0x16e67}, {0x16e48, 0x16e68},
+ {0x16e49, 0x16e69}, {0x16e4a, 0x16e6a}, {0x16e4b, 0x16e6b}, {0x16e4c, 0x16e6c}, {0x16e4d, 0x16e6d}, {0x16e4e, 0x16e6e},
+ {0x16e4f, 0x16e6f}, {0x16e50, 0x16e70}, {0x16e51, 0x16e71}, {0x16e52, 0x16e72}, {0x16e53, 0x16e73}, {0x16e54, 0x16e74},
+ {0x16e55, 0x16e75}, {0x16e56, 0x16e76}, {0x16e57, 0x16e77}, {0x16e58, 0x16e78}, {0x16e59, 0x16e79}, {0x16e5a, 0x16e7a},
+ {0x16e5b, 0x16e7b}, {0x16e5c, 0x16e7c}, {0x16e5d, 0x16e7d}, {0x16e5e, 0x16e7e}, {0x16e5f, 0x16e7f}, {0x1e900, 0x1e922},
+ {0x1e901, 0x1e923}, {0x1e902, 0x1e924}, {0x1e903, 0x1e925}, {0x1e904, 0x1e926}, {0x1e905, 0x1e927}, {0x1e906, 0x1e928},
+ {0x1e907, 0x1e929}, {0x1e908, 0x1e92a}, {0x1e909, 0x1e92b}, {0x1e90a, 0x1e92c}, {0x1e90b, 0x1e92d}, {0x1e90c, 0x1e92e},
+ {0x1e90d, 0x1e92f}, {0x1e90e, 0x1e930}, {0x1e90f, 0x1e931}, {0x1e910, 0x1e932}, {0x1e911, 0x1e933}, {0x1e912, 0x1e934},
+ {0x1e913, 0x1e935}, {0x1e914, 0x1e936}, {0x1e915, 0x1e937}, {0x1e916, 0x1e938}, {0x1e917, 0x1e939}, {0x1e918, 0x1e93a},
+ {0x1e919, 0x1e93b}, {0x1e91a, 0x1e93c}, {0x1e91b, 0x1e93d}, {0x1e91c, 0x1e93e}, {0x1e91d, 0x1e93f}, {0x1e91e, 0x1e940},
+ {0x1e91f, 0x1e941}, {0x1e920, 0x1e942}, {0x1e921, 0x1e943},
+};
+#endif
diff --git a/c/tests/test_convert_guard.py b/c/tests/test_convert_guard.py
index 8e84861f..60782560 100644
--- a/c/tests/test_convert_guard.py
+++ b/c/tests/test_convert_guard.py
@@ -56,6 +56,14 @@ class ConvertGuardTest(unittest.TestCase):
self.assertIn("NOT converted", str(caught.exception))
self.assertIn("FP8", str(caught.exception))
+ def test_a_gliner2_checkpoint_gets_its_pointer(self):
+ # GLiNER2's config.json says model_type "extractor", not the registry key
+ with self.assertRaises(SystemExit) as caught:
+ check_model_family({"model_type": "extractor", "architecture": "span"},
+ "fastino/GLiNER2.5-Decide")
+ self.assertIn("NOT converted", str(caught.exception))
+ self.assertIn("docs/gliner_decide.md", str(caught.exception))
+
def test_unknown_and_missing_types_are_refused_not_guessed(self):
for config in ({"model_type": "llama"}, {"model_type": ""}, {}):
with self.assertRaises(SystemExit):
diff --git a/c/tests/test_family_registry.py b/c/tests/test_family_registry.py
index 1223a363..716df9af 100644
--- a/c/tests/test_family_registry.py
+++ b/c/tests/test_family_registry.py
@@ -1056,6 +1056,7 @@ class FamilyRegistryTest(unittest.TestCase):
"qwen_image": "hello {world}",
# A decision model answers questions; it has no prompt to replay.
"laya": "hello {world}",
+ "gliner_decide": "hello {world}",
}
self.assertEqual(
{family.id: tuning_replay_prompt(family, prompt) for family in FAMILIES},
diff --git a/c/tools/clean.py b/c/tools/clean.py
index 34558703..7ee4c484 100644
--- a/c/tools/clean.py
+++ b/c/tools/clean.py
@@ -42,6 +42,7 @@ FILES = [
"mimo", "mimo.exe",
"qwenimage", "qwenimage.exe",
"laya", "laya.exe",
+ "gliner_decide", "gliner_decide.exe",
"native_quant.o", "native_quant_parallel.o", "native_quant_dual.o",
"native_quant_batch_avx512.o", "native_quant_fp4_rows16.o",
]
diff --git a/c/tools/convert_fp8_to_int4.py b/c/tools/convert_fp8_to_int4.py
index f1e59a27..7aa3c628 100644
--- a/c/tools/convert_fp8_to_int4.py
+++ b/c/tools/convert_fp8_to_int4.py
@@ -76,7 +76,13 @@ OTHER_FAMILY_PATHS = {
"diffusers checkpoint as downloaded; see docs/qwen-image.md",
"laya_modernbert": "Laya is NOT converted: the decision engine reads the release "
"as downloaded; see docs/laya.md",
+ "gliner2_span_deberta-v2": "GLiNER2.5-Decide is NOT converted: the decision engine reads "
+ "the release as downloaded; see docs/gliner_decide.md",
}
+# A config.json whose model_type is not the registry's key for its family: a
+# GLiNER2 checkpoint says "extractor" for every architecture and encoder, and
+# the registry names it by both (family_registry._resolve_gliner2_checkpoint).
+CONFIG_MODEL_TYPE_ALIASES = {"extractor": "gliner2_span_deberta-v2"}
def check_model_family(config, where):
@@ -92,7 +98,7 @@ def check_model_family(config, where):
"refusing to guess. This converter is for GLM-5.2 only.")
if model_type in GLM52_MODEL_TYPES:
return
- hint = OTHER_FAMILY_PATHS.get(model_type)
+ hint = OTHER_FAMILY_PATHS.get(CONFIG_MODEL_TYPE_ALIASES.get(model_type, model_type))
if hint:
raise SystemExit(f"ERROR: {where} is '{model_type}', not GLM-5.2.\n"
f" This converter would silently upcast most of its "
diff --git a/c/tools/gen_gliner_unicode.py b/c/tools/gen_gliner_unicode.py
new file mode 100644
index 00000000..1fbc5ab1
--- /dev/null
+++ b/c/tools/gen_gliner_unicode.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python3
+"""Generate c/gliner_unicode.h: the parts of Python's str that GLiNER2 reads text with.
+
+The gliner2 package splits a text into words with a Python regex
+(processing/word_splitter.py, WhitespaceTokenSplitter) and lower-cases every
+word with str.lower(). Reproducing that in C needs Python's own character
+classes, not another library's:
+
+ word \\w of a str pattern: str.isalnum() or "_"
+ space \\s of a str pattern: str.isspace()
+ lower str.lower() one code point at a time (U+0130 lowers to two code
+ points and capital sigma depends on its neighbours: both are
+ handled in gliner_decide.c, not here)
+ ignorable Case_Ignorable, and
+ cased Cased, for the final-sigma rule str.lower() applies
+ (Unicode 3.13 Final_Sigma)
+
+Python exposes no Cased or Case_Ignorable predicate, so both are read off
+str.lower() itself: for a code point c, "c" + capital sigma lowers to a final
+sigma exactly when c is cased and not case-ignorable, and "A" + c + capital
+sigma does when c is case-ignorable or cased. The three outcomes tell the
+classes apart wherever the rule can see them (a case-ignorable code point is
+always skipped, so whether it is also cased never matters).
+
+The tables follow the Unicode version of the Python that runs this script,
+which the header records; regenerate with the Python the reference runs on.
+
+ python3 tools/gen_gliner_unicode.py > gliner_unicode.h
+"""
+import sys
+import unicodedata
+
+SIGMA = "Σ"
+
+
+def ranges(predicate):
+ out, start = [], None
+ for cp in range(0x110000):
+ if 0xD800 <= cp <= 0xDFFF:
+ hit = False
+ else:
+ hit = predicate(chr(cp))
+ if hit and start is None:
+ start = cp
+ elif not hit and start is not None:
+ out.append((start, cp - 1))
+ start = None
+ if start is not None:
+ out.append((start, 0x10FFFF))
+ return out
+
+
+def final_sigma_after(text):
+ return text.lower().endswith("ς")
+
+
+def cased_not_ignorable(ch):
+ return final_sigma_after(ch + SIGMA)
+
+
+def ignorable(ch):
+ return final_sigma_after("A" + ch + SIGMA) and not final_sigma_after(ch + SIGMA)
+
+
+def emit_ranges(name, values):
+ lines = [f"static const GlUniRange {name}[{len(values)}] = {{"]
+ row = []
+ for lo, hi in values:
+ row.append(f"{{0x{lo:x}, 0x{hi:x}}}")
+ if len(row) == 6:
+ lines.append(" " + ", ".join(row) + ",")
+ row = []
+ if row:
+ lines.append(" " + ", ".join(row) + ",")
+ lines.append("};")
+ return lines
+
+
+def main():
+ word = ranges(lambda ch: ch.isalnum() or ch == "_")
+ space = ranges(lambda ch: ch.isspace())
+ cased = ranges(cased_not_ignorable)
+ ignore = ranges(ignorable)
+ lower = []
+ for cp in range(0x110000):
+ if 0xD800 <= cp <= 0xDFFF or cp in (0x130, 0x3A3):
+ continue
+ low = chr(cp).lower()
+ if low != chr(cp):
+ if len(low) != 1:
+ sys.exit(f"U+{cp:04X} lowers to {len(low)} code points: extend the generator")
+ lower.append((cp, ord(low)))
+ out = [
+ "/* GENERATED by tools/gen_gliner_unicode.py -- do not edit by hand.",
+ f" * Python {sys.version.split()[0]}, Unicode Character Database {unicodedata.unidata_version}.",
+ " * Python's \\w and \\s, str.lower() and the classes of its final-sigma rule,",
+ " * as the gliner2 word splitter reads text (gliner_decide.c). */",
+ "#ifndef COLI_GLINER_UNICODE_H",
+ "#define COLI_GLINER_UNICODE_H",
+ "#include <stdint.h>",
+ "typedef struct { uint32_t lo, hi; } GlUniRange;",
+ "typedef struct { uint32_t cp, lower; } GlUniLower;",
+ ]
+ out += emit_ranges("gl_uni_word", word)
+ out += emit_ranges("gl_uni_space", space)
+ out += emit_ranges("gl_uni_cased", cased)
+ out += emit_ranges("gl_uni_ignorable", ignore)
+ out.append(f"static const GlUniLower gl_uni_lower[{len(lower)}] = {{")
+ row = []
+ for cp, low in lower:
+ row.append(f"{{0x{cp:x}, 0x{low:x}}}")
+ if len(row) == 6:
+ out.append(" " + ", ".join(row) + ",")
+ row = []
+ if row:
+ out.append(" " + ", ".join(row) + ",")
+ out.append("};")
+ out.append("#endif")
+ sys.stdout.write("\n".join(out) + "\n")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/site/index.html b/site/index.html
index 8ea33539..93d440d5 100644
--- a/site/index.html
+++ b/site/index.html
@@ -437,7 +437,8 @@ footer{border-top:1px solid var(--line)}
Qwen3-Coder-30B-A3B and the dense Qwen3.8-27B), Qwen3.8-Flash-Next, DeepSeek V4 Flash,
DeepSeek V4.1 Flash, MiMo-V2.6 Flash (and Pro, on the same engine).
And for images, Qwen-Image-2.1: text to picture, drawn inside the terminal.
- And for decisions, Laya: typed questions in, calibrated probabilities out.</p>
+ And for decisions, Laya and GLiNER2.5-Decide: typed questions in, a probability per
+ option out.</p>
<a class="more" href="#models">Browse all models &rarr;</a>
</div>