Repository navigation
Add GLiNER2.5-Decide, a zero-shot decision model, for macOS - #592
Open
carinapeng wants to merge 4 commits into
Open
carinapeng wants to merge 4 commits into
carinapeng wants to merge 4 commits into
Conversation
GLiNER2's classification path scores caller-named labels against a text in one forward pass. The macOS definition is a DeBERTa-v2 encoder with disentangled attention (relative-position terms realigned with a reshape instead of a gather, position projections folded at load) and the GLiNER2 classification head; the span and count heads are not loaded. Attention is written out because DeBERTa's additive position bias cannot pass through the boolean-mask SDPA composite. Tests compare the encoder with Hugging Face DebertaV2Model and the head with a reference implementation on tiny random configurations.
`coreai.classification.export gliner2.5-decide` writes a bundle of kind "classification": model.aimodel with one batch-1 function per token length (128, 256, 512) over shared weights and 64 label slots, the tokenizer, and metadata.json describing how a host builds the token row (marker tokens are written by id). float16 compute is the default; float32 is available. `coreai.classification.run` builds the row, runs the bundle on the Core AI runtime and returns a probability per label. Adds the registry entry (macOS) and asset metadata. Tests cover the contract, the row layout, export dry runs, Core AI CPU and GPU runs of a tiny bundle, and recorded outputs of the upstream gliner2 package (run when the model is in the local Hugging Face cache).
Export and run steps, bundle layout, limits, parity against the upstream gliner2 package and latency on the macOS GPU. Lists the model under Decision Models in models/README.md.
- Task specs must be a list of strings or a string-to-string mapping; other values raise ValueError instead of splitting strings or crashing. - validate_block requires each marker role to carry an integer id and the text block to carry pad_token_id, append_period, lowercase_words and word_pattern. The runner rejects bundles whose text rules differ from the ones the encoder implements. - The compute precision is resolved before an existing bundle is removed or a snapshot is fetched. - classify returns the number of dropped trailing words; the CLI writes it to the JSON output and warns on stderr when text was truncated. - The exporter reuses resolve_snapshot (now taking allow_patterns) and a shared find_repo_root in export/bundle.py, also used by the embedding exporter. - Removes the unused token_pooling field and corrects the attention comment. The model card documents truncation and request limits; models/README.md lists the exporter under --include-debug-info. Tests: malformed task specs and metadata, precision checked before overwrite, over-long text on CPU and GPU and in the CLI, resolve_snapshot patterns, find_repo_root, the recorded-output test pinned to the model revision and skipped only when the snapshot is not cached, and float16 logits compared with float32.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Motivation and Context
Addresses the model request in #449.
Adds GLiNER2.5-Decide (fastino, Apache-2.0), a zero-shot decision model for text: a text plus caller-named tasks and labels go in, and one probability per label comes out of a single forward pass, with several tasks per call. It is the first decision model in the repo.
models/macos/gliner2.py): a DeBERTa-v2 encoder with disentangled attention and GLiNER2's classification head. The relative-position terms are realigned with a reshape instead of a gather, and the position projections are folded at load. Attention is written out because DeBERTa's additive position bias cannot go through the boolean-mask SDPA composite.coreai.classification.export gliner2.5-decide): writes a bundle of kindclassification. It containsmodel.aimodelwith one batch-1 function per token length (128, 256, 512) over shared weights and 64 label slots, the tokenizer, andmetadata.json, which describes how a host builds the token row.coreai.classification.run): builds the row, runs the bundle on the Core AI runtime and returns label probabilities.New model
fastino/GLiNER2.5-Decide@ 9d1bfb84), DeBERTa-v3-large encoder, 340M parametersNumerical equivalence
Measured against the upstream
gliner2package (2.2.0, PyTorch float32, CPU) on 25 requests (36 tasks, 30–444 tokens). Token ids match upstream on all 25 requests.Performance
Batch 1, full-length rows, tokenization excluded, median of 50 runs after 10 warm-up runs, same Mac.
gliner2-mlx0.1.2, float32 (reference)gliner2PyTorch MPS, float16The float32 bundle reaches 89% / 64% / 66% of the reference.
Example output
(Core AI float16 bundle, macOS GPU.)
Limits
swift-transformers1.4.0 has noDebertaV2Tokenizerentry and maps GLiNER's marker tokens to unknown. The bundle contract therefore has hosts write the markers by id, ascoreai.classification.rundoes.Testing
Tested locally
Added/updated tests
Added/updated docs
test_gliner2.py(19 tests): encoder vs Hugging FaceDebertaV2Modeland head vs a reference implementation on tiny random configs.test_classification_gliner2.py(31 tests): contract, row layout, export dry runs, Core AI CPU and GPU runs of a tiny bundle, and recorded upstream outputs (run when the model is in the local Hugging Face cache).Registry and embedding-contract tests pass.
ruff checkandruff format --checkare clean, anduv.lockis unchanged.