Title: feat(pii): add opt-in GLiNER NER engine (PII_ENGINE), device-agnostic by TheodoreSpeaks · Pull Request #5495 · simstudioai/sim · GitHub
Open Graph Title: feat(pii): add opt-in GLiNER NER engine (PII_ENGINE), device-agnostic by TheodoreSpeaks · Pull Request #5495 · simstudioai/sim
X Title: feat(pii): add opt-in GLiNER NER engine (PII_ENGINE), device-agnostic by TheodoreSpeaks · Pull Request #5495 · simstudioai/sim
Description: What
Adds GLiNER (zero-shot transformer NER) as an opt-in engine for the PII service, selected by PII_ENGINE (spacy | gliner, default spacy). Of the ~40 supported entity types only 4 are NER — PERSON, LOCATION, NRP, DATE_TIME — and GLiNER replaces exactly those; all ~36 regex/checksum recognizers (locale IDs, credit card, email, VIN, …) are registered identically on both engines.
One image, one tag. The pii image ships both engines (spaCy *_lg models + torch-CPU + gliner + baked GLiNER weights), so switching engines is a pure env flip — no image swap, no tag matrix, and rollback is PII_ENGINE=spacy. Image grows ~6.1GB → ~9.6GB.
Device-agnostic: PII_DEVICE (cpu/cuda) or auto-detect. The same code runs on Fargate CPU today and the EC2-GPU fleet later — no code change to switch. GPU capacity/scheduling is a separate infra task (not touched here).
Design
apps/pii/engines.py (new): side-effect-free engine builders extracted from server.py (which is now just env dispatch + endpoints; the spacy path is construction-identical to before).
One multilingual model (urchade/gliner_multi_pii-v1, override via PII_GLINER_MODEL) shared across the 5 per-language recognizer instances — SharedModelGLiNERRecognizer.load() caches the ~1.2GB model instead of loading it 5×.
Its analyze() restricts requested entities to the 4 it owns: presidio passes the full ~40-entity list to every recognizer and stock GLiNERRecognizer would append unknown entities (CREDIT_CARD, VIN, ES_NIF, …) as ad-hoc zero-shot labels — wrong scope and slower.
The gliner path uses the small spaCy models (*_sm, ~60MB total) purely for tokenization + lemmas so NlpArtifacts/context-boosts for the regex recognizers behave as before (blank pipelines don't work — presidio tries to pip-download them). SpacyRecognizer is removed from the registry so sm-model NER never competes with GLiNER.
Fail-fast: invalid PII_ENGINE dies at import; a custom image missing gliner deps dies with an actionable message instead of presidio's silent pip-download fallback.
docker/pii.Dockerfile: single linear image. GLiNER weights are baked at build (cached layer) with HF_HUB_OFFLINE=1 so startup never touches the network and a typo'd PII_GLINER_MODEL fails loudly. The GPU variant for the infra follow-up is the same Dockerfile built with --build-arg TORCH_INDEX_URL=https://download.pytorch.org/whl/cu128 (torch pinned to the newest version published on both cpu and cu128 indexes). Bench + tests + pytest ride along in the image.
CI: unchanged — same single pii build/tags as before.
Helm: pii.engine (spacy|gliner, default spacy) and pii.device render to PII_ENGINE/PII_DEVICE as chart-owned env keys (pii.env can't override them; PII_GLINER_MODEL stays a plain pii.env passthrough). nvidia.com/gpu requests are deliberately not wired — infra follow-up.
PII_WORKERS (merged from #5457) note: each uvicorn worker loads its own GLiNER model copy — into GPU memory on cuda — so GPU deployments generally want PII_WORKERS=1 per GPU (documented in Dockerfile + server.py; behavior unchanged).
Parity & throughput (spaCy vs GLiNER-CPU)
apps/pii/scripts/bench_engines.py runs the same payload through both engines and diffs results; the 32-text multilingual payload (en/es/it/pl/fi with names, locations, dates, NRP, and regex bait: emails, phones, valid-checksum VIN/ES_NIF/IT_FISCAL_CODE/PESEL/HETU) ships in the repo. Numbers below from the CPU (aarch64 docker) run; rerun with docker run --rm
Open Graph Description: What Adds GLiNER (zero-shot transformer NER) as an opt-in engine for the PII service, selected by PII_ENGINE (spacy | gliner, default spacy). Of the ~40 supported entity types only 4 are NER — PERS...
X Description: What Adds GLiNER (zero-shot transformer NER) as an opt-in engine for the PII service, selected by PII_ENGINE (spacy | gliner, default spacy). Of the ~40 supported entity types only 4 are NER — PERS...
Opengraph URL: https://github.com/simstudioai/sim/pull/5495
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:80724d9e-8640-aa73-5830-728fac248483 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8B6A:223A5F:AEB976:F0D022:6AFB52A7 |
| html-safe-nonce | bf454ab0d928e6f2a36a1c102b81d73a7453c73c129a989e2daa7c0760e3e99b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjZBOjIyM0E1RjpBRUI5NzY6RjBEMDIyOjZBRkI1MkE3IiwidmlzaXRvcl9pZCI6IjQ4ODM3NTQ2MjM0MTc2NjgyNjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b3e99c745d789d6ee8f1e92b3e093fe78847bcb49ed997730d5865fd6673a64b |
| hovercard-subject-tag | pull_request:4010573034 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/5495/files |
| twitter:image | https://avatars.githubusercontent.com/u/19564703?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/19564703?s=400&v=4 |
| og:image:alt | What Adds GLiNER (zero-shot transformer NER) as an opt-in engine for the PII service, selected by PII_ENGINE (spacy | gliner, default spacy). Of the ~40 supported entity types only 4 are NER — PERS... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width