Views
No views yet
Experimental ONNX build - Unofficial ONNX export of hivetrace/gliner-guard-omni.
pip install gliner2-onnx| Single text | Batch | Returns |
|---|---|---|
classify(text, labels) | classify_batch(texts, labels) | dict[str, float] |
extract_entities(text, labels) | extract_entities_batch(texts, labels) | list[Entity] |
extract(text, schema) | extract_batch(texts, schema) | ExtractionResult |
batch_size argument (default 8) controlling how many texts are encoded per forward pass.1from gliner2_onnx import GLiNER2ONNXRuntime
2
3runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-multi-v1-onnx")
4
5entities = runtime.extract_entities(
6 "John works at Google in Seattle",
7 ["person", "organization", "location"],
8)
9# [
10# Entity(text='John', label='person', start=0, end=4, score=0.98),
11# Entity(text='Google', label='organization', start=14, end=20, score=0.97),
12# Entity(text='Seattle', label='location', start=24, end=31, score=0.96),
13# ]
14
15# Batch
16results = runtime.extract_entities_batch(
17 ["John works at Google", "Paris is in France"],
18 ["person", "organization", "location"],
19)1# Single-label
2result = runtime.classify("Buy milk from the store", ["shopping", "work", "entertainment"])
3# {'shopping': 0.95}
4
5# Multi-label
6result = runtime.classify(
7 "Buy milk and finish the report",
8 ["shopping", "work", "entertainment"],
9 threshold=0.3,
10 multi_label=True,
11)
12# {'shopping': 0.85, 'work': 0.72}
13
14# Batch
15results = runtime.classify_batch(
16 ["Buy milk", "Write the report", "Watch a movie"],
17 ["shopping", "work", "entertainment"],
18)1from gliner2_onnx import GLiNER2ONNXRuntime, Schema
2
3runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-multi-v1-onnx")
4
5schema = (
6 Schema()
7 .entities(["person", "organization", "location"], threshold=0.5)
8 .classification("safety", ["safe", "unsafe"])
9 .classification("intent", ["informational", "adversarial", "instructional"])
10)
11
12result = runtime.extract("John Smith works at Google in New York.", schema)
13
14result.entities
15# [Entity(text='John Smith', label='person', ...), ...]
16
17result.classifications
18# {
19# 'safety': {'safe': 0.91},
20# 'intent': {'informational': 0.87},
21# }
22
23# Batch
24results = runtime.extract_batch(["text one", "text two"], schema)Schema is immutable — each .entities() / .classification() call returns a new instance, so schemas can be reused and composed safely.1runtime = GLiNER2ONNXRuntime.from_pretrained(
2 "lmo3/gliner2-multi-v1-onnx",
3 providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
4)1# FP16
2runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-multi-v1-onnx", precision="fp16")
3
4# INT8 (dynamic quantization, local export only — see Exporting Models)
5runtime = GLiNER2ONNXRuntime("./model_out/gliner2-multi-v1", precision="int8")ONNXSessionOptions:1from gliner2_onnx import GLiNER2ONNXRuntime, ONNXSessionOptions
2
3runtime = GLiNER2ONNXRuntime.from_pretrained(
4 "lmo3/gliner2-multi-v1-onnx",
5 session_options=ONNXSessionOptions(
6 intra_op_num_threads=4,
7 inter_op_num_threads=1,
8 ),
9)| Model | HuggingFace |
|---|---|
| gliner2-large-v1 | lmo3/gliner2-large-v1-onnx |
| gliner2-multi-v1 | lmo3/gliner2-multi-v1-onnx |
gliner2-base-v1 is not supported (uses a different architecture).1git clone https://github.com/lmoe/gliner2-onnx
2cd gliner2-onnx
3
4# FP32 only
5make onnx-export MODEL=fastino/gliner2-large-v1
6
7# FP32 + FP16
8make onnx-export hivetrace/gliner-guard-omni QUANTIZE=fp16
9
10# FP32 + INT8
11make onnx-export MODEL=fastino/gliner2-large-v1 QUANTIZE=int8model_out/<model-name>/.