This is an
optimized variant of the original
urchade/gliner_small-v2.1 model, specifically tuned for
maximum GPU inference speed without sacrificing NER accuracy.
1from gliner import GLiNER
2import torch
3
4model = GLiNER.from_pretrained("binga/gliner_small_v2.1-optimized-gpu", map_location="cuda")
5model.to("cuda")
6model.half() # FP16 — critical for speed
7
8# Optional: compile submodules for additional speed
9if hasattr(model, "model"):
10 inner = model.model
11 for attr in ["token_rep_layer", "span_rep_layer", "prompt_rep_layer"]:
12 layer = getattr(inner, attr, None)
13 if layer is not None:
14 setattr(inner, attr, torch.compile(layer, mode="max-autotune"))
15
16text = "Apple Inc. was founded by Steve Jobs in California."
17labels = ["person", "organization", "location"]
18entities = model.predict_entities(text, labels, threshold=0.5)
1from gliner import InferencePackingConfig
2
3# Enable inference packing (packs variable-length sequences)
4model.configure_inference_packing(
5 InferencePackingConfig(max_length=384, streams_per_batch=8)
6)
7
8results = model.inference(texts, labels, threshold=0.5, batch_size=32)
1@inproceedings{zaratiana2024gliner,
2 title={GLiNER: Generalist Model for Named Entity Recognition using Bidirectional Transformer},
3 author={Zaratiana, Urchade and Tomeh, Nadi and Holat, Pierre and Charnois, Thierry},
4 booktitle={NAACL},
5 year={2024}
6}
This optimized model is based on the original
urchade/gliner_small-v2.1 by Urchade Zaratiana et al. All credit for the model architecture and training goes to the original authors.