mircq commited on
Commit
29cd9ec
·
verified ·
1 Parent(s): 84ed50e

GLINER quantized INT8

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: gliner2-onnx
3
+ base_model: fastino/gliner2-multi-v1
4
+ tags:
5
+ - onnx
6
+ - gliner
7
+ - gliner2
8
+ - ner
9
+ - named-entity-recognition
10
+ - zero-shot
11
+ - classification
12
+ license: mit
13
+ ---
14
+
15
+ > **Experimental ONNX build** - Unofficial ONNX export of [fastino/gliner2-multi-v1](https://huggingface.co/fastino/gliner2-multi-v1).
16
+
17
+ # gliner2-onnx
18
+
19
+ GLiNER2 ONNX runtime for Python. Runs GLiNER2 models without PyTorch.
20
+
21
+ This library is experimental. The API may change between versions.
22
+
23
+ ## Features
24
+
25
+ - Zero-shot NER and text classification
26
+ - Runs with ONNX Runtime (no PyTorch dependency)
27
+ - FP32 and FP16 precision support
28
+ - GPU acceleration via CUDA
29
+
30
+ All other GLiNER2 features such as JSON export are not supported.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gliner2-onnx
36
+ ```
37
+
38
+ ## NER
39
+
40
+ ```python
41
+ from gliner2_onnx import GLiNER2ONNXRuntime
42
+
43
+ runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-large-v1-onnx")
44
+
45
+ entities = runtime.extract_entities(
46
+ "John works at Google in Seattle",
47
+ ["person", "organization", "location"]
48
+ )
49
+ # [
50
+ # Entity(text='John', label='person', start=0, end=4, score=0.98),
51
+ # Entity(text='Google', label='organization', start=14, end=20, score=0.97),
52
+ # Entity(text='Seattle', label='location', start=24, end=31, score=0.96)
53
+ # ]
54
+ ```
55
+
56
+ ## Classification
57
+
58
+ ```python
59
+ from gliner2_onnx import GLiNER2ONNXRuntime
60
+
61
+ runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-large-v1-onnx")
62
+
63
+ # Single-label classification
64
+ result = runtime.classify(
65
+ "Buy milk from the store",
66
+ ["shopping", "work", "entertainment"]
67
+ )
68
+ # {'shopping': 0.95}
69
+
70
+ # Multi-label classification
71
+ result = runtime.classify(
72
+ "Buy milk and finish the report",
73
+ ["shopping", "work", "entertainment"],
74
+ threshold=0.3,
75
+ multi_label=True
76
+ )
77
+ # {'shopping': 0.85, 'work': 0.72}
78
+ ```
79
+
80
+ ## CUDA
81
+
82
+ To use CUDA for GPU acceleration:
83
+
84
+ ```python
85
+ runtime = GLiNER2ONNXRuntime.from_pretrained(
86
+ "lmo3/gliner2-large-v1-onnx",
87
+ providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
88
+ )
89
+ ```
90
+
91
+ ## Precision
92
+
93
+ Both FP32 and FP16 models are supported. Only the requested precision is downloaded.
94
+
95
+ ```python
96
+ runtime = GLiNER2ONNXRuntime.from_pretrained(
97
+ "lmo3/gliner2-large-v1-onnx",
98
+ precision="fp16"
99
+ )
100
+ ```
101
+
102
+ ## Models
103
+
104
+ Pre-exported ONNX models:
105
+
106
+ | Model | HuggingFace |
107
+ |-------|-------------|
108
+ | gliner2-large-v1 | [lmo3/gliner2-large-v1-onnx](https://huggingface.co/lmo3/gliner2-large-v1-onnx) |
109
+ | gliner2-multi-v1 | [lmo3/gliner2-multi-v1-onnx](https://huggingface.co/lmo3/gliner2-multi-v1-onnx) |
110
+
111
+ Note: `gliner2-base-v1` is not supported (uses a different architecture).
112
+
113
+ ## Exporting Models
114
+
115
+ To export your own models, clone the repository and use make:
116
+
117
+ ```bash
118
+ git clone https://github.com/lmoe/gliner2-onnx
119
+ cd gliner2-onnx
120
+
121
+ # FP32 only
122
+ make onnx-export MODEL=fastino/gliner2-large-v1
123
+
124
+ # FP32 + FP16
125
+ make onnx-export MODEL=fastino/gliner2-large-v1 QUANTIZE=fp16
126
+ ```
127
+
128
+ Output is saved to `model_out/<model-name>/`.
129
+
130
+ ## JavaScript/TypeScript
131
+
132
+ For Node.js, see [@lmoe/gliner-onnx.js](https://github.com/lmoe/gliner-onnx.js).
133
+
134
+ ## Credits
135
+
136
+ - [fastino-ai/GLiNER2](https://github.com/fastino-ai/GLiNER2) - Original GLiNER2 implementation
137
+ - [fastino/gliner2-large-v1](https://huggingface.co/fastino/gliner2-large-v1) - Pre-trained models
138
+
139
+ ## License
140
+
141
+ MIT
USAGE.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # gliner2-multi-v1 — INT8 ONNX (CPU)
2
+
3
+ Dynamically-quantized INT8 ONNX export of `fastino/gliner2-multi-v1`.
4
+ This bundle contains **only** the INT8 graphs — load it with `precision="int8"`.
5
+
6
+ ```python
7
+ from gliner2_onnx import GLiNER2ONNXRuntime
8
+
9
+ rt = GLiNER2ONNXRuntime(
10
+ "gliner2-multi-v1-int8", # this folder
11
+ precision="int8", # required: no fp32 graphs are included
12
+ providers=["CPUExecutionProvider"],
13
+ )
14
+
15
+ rt.extract_entities("pagamento polizza tfr A4983AS", ["amount", "reference_number"])
16
+ rt.classify("acquisto gasolio automezzi", ["carburanti", "polizze"], multi_label=True)
17
+ ```
18
+
19
+ For best CPU throughput set intra-op threads to your physical core count via ORT
20
+ `SessionOptions`.
21
+
22
+ ## Contents
23
+ - `gliner2_config.json` — model config, references the INT8 graphs only
24
+ - `config.json`, `tokenizer.json`, `tokenizer_config.json`
25
+ - `onnx/*_int8.onnx` — encoder / classifier / span_rep / count_embed
config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "hidden_size": 768,
3
+ "vocab_size": 250101
4
+ }
gliner2_config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "max_width": 8,
3
+ "special_tokens": {
4
+ "[SEP_STRUCT]": 250102,
5
+ "[SEP_TEXT]": 250103,
6
+ "[P]": 250104,
7
+ "[C]": 250105,
8
+ "[E]": 250106,
9
+ "[R]": 250107,
10
+ "[L]": 250108,
11
+ "[EXAMPLE]": 250109,
12
+ "[OUTPUT]": 250110,
13
+ "[DESCRIPTION]": 250111
14
+ },
15
+ "onnx_files": {
16
+ "int8": {
17
+ "encoder": "onnx/encoder_int8.onnx",
18
+ "classifier": "onnx/classifier_int8.onnx",
19
+ "span_rep": "onnx/span_rep_int8.onnx",
20
+ "count_embed": "onnx/count_embed_int8.onnx"
21
+ }
22
+ }
23
+ }
onnx/classifier_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5a3b5d015c10301739f8e15f2716f5da3ac7741d4a2b3e9456ef88d77418174
3
+ size 1190416
onnx/count_embed_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b890893dd4e49170ef13dfc01f986c20dfa4a679b422fd9fa0229f8ed38c235
3
+ size 10661306
onnx/encoder_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:162486021e7c65cbd8bba3c264fcfe31921783dc7a3d81c1e90283e44cbca1ce
3
+ size 337059961
onnx/span_rep_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6cb04115e8a85de950e81f2551713b34ac8a7b9fd4868e90c2d580fdadc6d6a1
3
+ size 16574642
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1c7ccb287623cccb7c03150953b6d2a09dd95122933393c9151c3a60095c97e
3
+ size 16337353
tokenizer_config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "[CLS]",
4
+ "clean_up_tokenization_spaces": false,
5
+ "cls_token": "[CLS]",
6
+ "do_lower_case": false,
7
+ "eos_token": "[SEP]",
8
+ "extra_special_tokens": [
9
+ "[SEP_STRUCT]",
10
+ "[SEP_TEXT]",
11
+ "[P]",
12
+ "[C]",
13
+ "[E]",
14
+ "[R]",
15
+ "[L]",
16
+ "[EXAMPLE]",
17
+ "[OUTPUT]",
18
+ "[DESCRIPTION]"
19
+ ],
20
+ "is_local": false,
21
+ "mask_token": "[MASK]",
22
+ "model_max_length": 1000000000000000019884624838656,
23
+ "model_specific_special_tokens": {},
24
+ "pad_token": "[PAD]",
25
+ "sep_token": "[SEP]",
26
+ "sp_model_kwargs": {},
27
+ "split_by_punct": false,
28
+ "tokenizer_class": "TokenizersBackend",
29
+ "unk_token": "[UNK]",
30
+ "vocab_type": "spm"
31
+ }