Instructions to use smdesai/GLiFormer-0.4B-v1.5-FP16-CoreAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiFormer
How to use smdesai/GLiFormer-0.4B-v1.5-FP16-CoreAI with GLiFormer:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
GLiFormer 0.4B v1.5 β Core AI, FP16 (iOS 27+ / macOS 27+)
Core AI port of knowledgator/gliformer-0.4b-v1.5.
GLiFormer is a DeBERTa-v3-large encoder with lightweight task heads. One on-device model covers:
- Entities (flat or nested, label groups, task prompts)
- Text classification (single- and multi-label, several label groups)
- Joint entities and relations
- Structured records: text, class and enum fields, nested objects and lists, numbers, dates and times read as values
- Calculated fields (
$calculate: sums, differences, ratios over numbers in the text) - Text editing (spelling, grammar, instructed rewrites)
- Text embeddings
Several tasks can run in one pass. This is the reference variant: FP16 weights, the closest match
to the upstream model. A smaller variant with int8 task heads is
smdesai/GLiFormer-0.4B-v1.5-H8-CoreAI.
All credit for the model goes to Knowledgator and the
GLiFormer authors. The original model card is included
as model-card.md.
Files
| File | Purpose |
|---|---|
GLiFormer-0.4B-FP16.aimodel/ |
GPU asset, FP16 (1.66 GB): encoder segments, position tables, every task head (42 functions sharing one set of weights) |
GLiFormer-0.4B-FP16.mix_<L>.aimodel/ |
Encoder attention for a row of L tokens, L β {128, 256, 384, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096} (12 assets, weight-free, 20β80 KB each) |
GLiFormer-0.4B-LSTM.aimodel/ |
Word BiLSTM, FP32, for the CPU (25 MB) |
tokenizer.json, tokenizer_config.json |
Checkpoint tokenizer: SentencePiece Unigram, 128k vocabulary plus the GLiFormer task tokens |
gliner_config.json |
Checkpoint configuration (token indices, word splitting, limits) |
functions.json |
Input and output names, shapes and dtypes of every function, by asset |
SHA256SUMS |
Checksums of every file |
model-card.md |
Upstream model card (knowledgator/gliformer-0.4b-v1.5, Apache-2.0) |
LICENSE |
Apache License 2.0 |
Source:
- Checkpoint
knowledgator/gliformer-0.4b-v1.5at revisionf76390db3cc8b7c7ee990f2f67bb97384b2f90d5. - Upstream code: Knowledgator/GLiFormer at commit
e63a2c5(for preprocessing and decoding).
Export:
- coreai-torch 0.4.3, coreai-core 1.0.0b3, Torch 2.9.0, Transformers 5.12.1.
- Learned weights are unchanged apart from the FP16 cast. The export only rewrites graph structure:
- DeBERTa attention: constant relative-position buckets (the float log-bucket path produces wrong indices inside converted graphs), a gather-free relative shift, fused SDPA, fused QKV projections, and per-layer relative-position key/query projections folded and pre-scaled into constant tables.
- The encoder is regrouped into 128-token segments (below), so its weights are stored once and serve every text length.
- The word BiLSTM is unrolled into a 32-word step with carried state (no LSTM lowering exists).
- Upstream helpers that branch on tensor values are replaced by equivalent fixed-shape code under preconditions the host guarantees.
- Debug locations are stripped from every graph: the assets hold no source paths.
How the model is split
GLiFormer has data-dependent steps between its neural parts (word gathering, label and schema encoding, span and pair selection, decoding), so it is exported as fixed-shape functions and the host runs the logic between them.
Encoder (chunked). In a specialized Core AI asset every function holds its own copy of its matmul weights, so one static encoder per sequence length would repeat the 303M layer weights per length. Instead every weight sits in a graph of one fixed chunk length, 128 tokens:
| Function | Computes |
|---|---|
seg_0 |
Embeddings and layer 0's fused query/key/value projection (qkv), for 128 tokens |
seg_1 β¦ seg_23 |
Finish layer iβ1 (attention output, feed-forward, norms), project layer i's fused qkv |
seg_24 |
Finish the last layer |
postables |
Every layer's pre-scaled relative-position key/query tables (fetched once, then released) |
mix_<L> (own asset) |
DeBERTa disentangled self-attention over the whole padded row of L tokens; weight-free, so one function per length serves all 24 layers |
The host runs the segments chunk by chunk and the mix over the whole row, 24 times, padding the row to the next available mix length (up to 4096). Each mix length is its own small asset: an asset's first function load sets up all of its functions, and a loaded mix keeps buffers for its length.
Task heads (elementwise word/token heads run in fixed 128-unit chunks; calcp uses word buckets W β {128, 1024, 4096}):
| Function | Computes |
|---|---|
lstm_k32 (CPU asset) |
32 steps of the word BiLSTM, both directions, carried state |
ner_w128 |
Entity span scores for up to 8 labels, chunked 128 words at a time (anchored span scorer) |
cls |
Classification logits for up to 64 labels |
relspan, entspan |
Span representations for up to 16 spans |
relpair |
Relation scores for up to 256 entity pairs Γ 16 relation types |
records_w4096 |
Structuring record slots: anchors, anchor relations, objectness (up to 32 schema fields) |
options_w4096 |
Class-field options (8 class fields Γ 16 options per call) |
norm |
Number, date and time readouts for up to 8 spans |
calcq_w4096, calcscore_w128, calcp_w<W> |
Calculation: query fusion, chunked per-word operand scoring (128 words), then the program over the operands |
editops_w4096 |
Edit operations for an [EDIT] group |
editcontent_t4096 |
Content of up to 4 predicted edits (length, spacing, vocabulary and pointer choices) |
embed_t128 |
Chunked embedding projection and masked FP32 sum (128 tokens per chunk, pooled on the host) |
records, options, calcq, editops and editcontent cost about the same at any size on an
iPhone, so they keep one bucket. Exact shapes are in functions.json.
Host responsibilities:
- Tokenization, word splitting and the GLiFormer prompt layout.
- The chunked encoder loop, word gathering and the LSTM loop.
- Label, schema, relation and calculation inputs; chunking above the per-call capacities.
- Every decoding step: thresholds, flat and nested spans, relation pairing, record assembly, value normalization, calculation programs, edit application and the edit loop.
These must follow upstream exactly. A Swift implementation of all of them was validated against upstream (tokenizer, preprocessing, every decoder, structuring, normalization, calculation and editing). It lives in the companion repository.
Required: compute placement
import CoreAI
let gpu = SpecializationOptions(preferredComputeUnitKind: .gpu)
let main = try await AIModel(contentsOf: mainURL, options: gpu) // GLiFormer-0.4B-FP16.aimodel and every mix
let lstm = try await AIModel(contentsOf: lstmURL,
options: SpecializationOptions(preferredComputeUnitKind: .cpu))
- The main asset and the mixes were validated on the GPU. With default placement, the first specialization on an iPhone did not finish within 7 minutes.
- The LSTM is sequential: 0.9 ms per 32-word chunk on the CPU, 13 ms for 128 steps on the GPU.
- On an iPhone, give the app the
com.apple.developer.kernel.increased-memory-limitentitlement (peak footprint about 2.2 GB across the corpus).
Validation
The reference is upstream GLiFormer in PyTorch FP32, run through its public API. A 59-case corpus
covers every task: 12 entity cases (groups, prompts, nested spans, low thresholds, documents up to
1,630 tokens), 6 classification, 16 structuring (typed, nested, lists, $root, enums, values,
reference dates, prompts), 7 editing and 2 embedding cases, and 16 inference calls (relations,
calculations, several tasks at once).
| Check | Result |
|---|---|
| Exported graphs at FP32 vs upstream | identical results on all 59 cases |
| Swift host fed the recorded FP32 stage outputs | 59/59 identical to upstream (iPhone and Mac) |
| iPhone Duo (iOS 27.3, GPU), full Swift pipeline | 59/59 pass: 44 exact, 15 differ only on FP32 boundary items; max score error 0.0028 |
| Mac (M5 Ultra, macOS 27.2, GPU), full Swift pipeline | 59/59 pass: 44 exact, 15 differ only on FP32 boundary items; max score error 0.0029 |
| GLiFormer Lab app self-test (39 examples) | 39/39 |
Boundary items were precomputed at FP32 before any device run: items that change when every
GPU stage output gets N(0, 0.001Β·rms) noise in any of 20 runs. On this corpus the 15 cases differ
only in the normalization head's number readouts (numbers.bins, numbers.regression); every
entity, class, relation, record and edit is the same as upstream.
Performance, iPhone Duo, end to end (preprocessing + model + decoding):
| Input | Time |
|---|---|
| Short texts, one task (entities, classes) | 28β55 ms |
Records, calculations, multi-task inference |
53β115 ms |
| Editing (edit loop) | 38β102 ms |
| 2,800-character document (816 tokens), entities | 397 ms |
| 5,600-character document (1,630 tokens), entities | 899 ms |
| Encoder alone, 4,000 tokens | 2.45 s |
Median over the corpus 55.9 ms (H8 variant: 49.9 ms).
Load: about 11.6 s the first time (on-device specialization; cached on disk afterwards), a few milliseconds from the cache. The first request after launch takes about 1.4 s while the functions it needs are set up; later requests run at the times above.
Memory: process footprint about 1.3 GB after the whole corpus, peak 2.2 GB; a 4,000-token row peaks at about 4.2 GB across all encoder lengths. The weights are memory-mapped.
Limitations
- One call handles up to 4096 tokens (upstream
max_len); longer texts need chunking. The corpus reaches 1,630 tokens: longer rows run (timings above) but were not compared with upstream end to end. - Per-call capacities are fixed by the function shapes. The host splits entity labels (8 per call), entity pairs (256), spans (16), normalization spans (8),
class fields (8), calculation queries (2) and edits (4) across several calls. Requests beyond the other
limits are rejected with
GLiFormerError.capacity: more than 64 class labels in one group, 16 relation types, 32 schema fields, 16 options per class field, or 48 operand candidates per calculation query. - Compression was evaluated: int8 and 8-bit palettized encoder weights changed entities and were
rejected; dynamic shapes re-specialize on an iPhone for every new length (1β105 s) and were
rejected. Int8 task heads are the
H8variant.
License and attribution
- Weights: from
knowledgator/gliformer-0.4b-v1.5by Knowledgator, released under the Apache License 2.0. This repository redistributes them converted to Core AI format, unchanged in value apart from the FP16 cast (the LSTM stays FP32), under the same license (LICENSE). - Tokenizer: the DeBERTa-v3 SentencePiece tokenizer with the GLiFormer task tokens, as shipped with the upstream checkpoint.
- Citation: see the upstream card.
SHA-256
The main files are below; SHA256SUMS lists every file.
f3c69546eca0732a10fdf070abac4b4dbaa9fdac222d55349444678d0b5f3140 GLiFormer-0.4B-FP16.aimodel/main.mlirb
3a1b63927f0e3c0efbef2f2121fd99609f59f61b6b1d8abf4d76c32477104f68 GLiFormer-0.4B-LSTM.aimodel/main.mlirb
ffaf8464830c4babf35b6855226d1e082fbf578b6ff39c46e1398c1c6a166a3b tokenizer.json
8280839b8f828a7b235549b7b42e135beb1216d3391ac0251487ee407c94cead gliner_config.json
f1a04677fed1800c36c8a36b27a7217f89dc2e054103dbbba1ebe97df21abdba functions.json
- Downloads last month
- 33
Model tree for smdesai/GLiFormer-0.4B-v1.5-FP16-CoreAI
Base model
knowledgator/DeBERTa-large-joint-3000