Python binding for UniRT — multi-backend on-device LLM inference with an extensible VLM API
Project description
unirt (Python binding)
Python binding for the UniRT SDK — run LLMs locally through a single API with interchangeable backends:
| runtime | models | hardware | in the published wheels |
|---|---|---|---|
llama_cpp |
GGUF (LLM, VLM, embeddings, rerank) | CPU, Metal on macOS | every wheel |
mlx |
HF safetensors (SmolLM2-style Llama/ByteLevel-BPE layout; dense or MLX-quantized) | Apple Silicon Metal GPU | macOS wheel (Apple-only) |
onnxruntime |
ONNX encoder embeddings | CPU, Apple Core ML | every wheel |
unirt devices lists what your install actually has. The llama_cpp runtime is
built for a generic CPU baseline plus Metal on macOS — no CUDA, no Vulkan.
The bundled llama_cpp runtime supports GGUF VLMs through libmtmd when an mmproj is present. MLX remains text-only and fails explicitly for VLM models. MLX also requires a usable Metal device; if none is visible, model loading fails before native model allocation.
Install
pip install unirt
Wheels ship the native libraries — no toolchain, no build step — for macOS 14+
arm64, Linux x86_64 and arm64 (manylinux_2_31, glibc 2.31+), and Windows 10+
x86_64 and arm64. Python 3.10+.
Quickstart (CLI)
unirt chat bartowski/SmolLM2-135M-Instruct-GGUF # download + interactive chat
unirt serve <model> --port 8080 # OpenAI-compatible server
unirt embed <encoder> "some text" # one vector per argument
unirt rerank <cross-encoder> "a query" "doc one" "doc two"
unirt pull <hf-repo> # download only
unirt ls # cached models
unirt devices # plugins + devices
Usage
from unirt.auto import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
'bartowski/SmolLM2-135M-Instruct-GGUF',
precision='Q4_K_M',
device_map='llama_cpp',
)
out = model.generate(prompt, max_new_tokens=128, temperature=0.7)
print(out.text)
model.close()
Embedding repositories select an ONNX variant and tokenizer sidecars without downloading the PyTorch checkpoint:
from unirt import AutoModelForEmbedding
with AutoModelForEmbedding.from_pretrained(
'sentence-transformers/all-MiniLM-L6-v2',
device_map='cpu', # or 'coreml' on Apple Silicon
) as model:
vectors = model.encode(['a cat on a mat', 'a kitten on a rug'])
print(len(vectors), len(vectors[0])) # 2, 384
Repository ids are inspected and downloaded with huggingface_hub. GGUF
repositories download only the selected quantization (including all of its
shards) plus tokenizer/config sidecars. The default cache is
~/.cache/unirt; set UNIRT_DATADIR to move it and UNIRT_HFTOKEN for gated
or private repositories.
Generation is stateless by default (n_past=0 clears prior KV state before
prefilling the supplied prompt). To continue from a known cached prefix, pass
the exact prefix length through n_past; invalid values are rejected rather
than silently duplicating context.
Structured output
Constrain decoding so the reply is guaranteed to parse — the grammar masks invalid tokens at every step, which makes even small models reliable JSON emitters (llama_cpp backend; MLX rejects these options):
schema = {'type': 'object',
'properties': {'city': {'type': 'string'}, 'country': {'type': 'string'}},
'required': ['city', 'country']}
out = model.generate('Facts about the capital of France as JSON.',
json_schema=schema) # dict or serialized JSON string
data = json.loads(out.text) # always parses
model.generate(prompt, json_mode=True) # any syntactically valid JSON
model.generate(prompt, grammar='root ::= ...') # raw GBNF
The server accepts the OpenAI response_format field with types
json_object and json_schema. Note a length finish can still truncate
mid-object — budget max_tokens accordingly.
OpenAI-compatible server
python3 -m unirt.server --model bartowski/SmolLM2-135M-Instruct-GGUF \
--backend llama_cpp --port 8080
Then point any OpenAI client (or plain curl) at
http://localhost:8080/v1/chat/completions — streaming SSE included, and
GGUF VLMs accept image content parts when loaded with an mmproj.
--embedding-model <encoder> adds /v1/embeddings and --rerank-model <cross-encoder> adds /v1/rerank; either may be given without --model, so a
retrieval sidecar needs no chat model at all.
Sampling takes temperature, top_p, top_k, min_p, seed,
repetition_penalty, presence_penalty and frequency_penalty. --api-key
(or UNIRT_API_KEY) requires Authorization: Bearer <key> on every /v1
endpoint, leaving /health open for probes — worth setting whenever --host
is not loopback.
The native library is closed-source and ships prebuilt. A wheel already bundles
it under unirt/lib/; a source checkout is discovered at
<repo>/sdk/pkg-unirt/lib after building the SDK, and installing from source
without building means populating unirt/lib/ yourself from a Release's
native-libs archive before pip install .. UNIRT_LIB_PATH /
UNIRT_PLUGIN_PATH override the search.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unirt-0.5.0-py3-none-win_arm64.whl.
File metadata
- Download URL: unirt-0.5.0-py3-none-win_arm64.whl
- Upload date:
- Size: 9.5 MB
- Tags: Python 3, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b611b5e028791ed0c4d7c12c2fe1d4956f0a22bc33a62f3c160501b5aea5f33
|
|
| MD5 |
0d8035cae34cf94ef3aa1ac25aaa690a
|
|
| BLAKE2b-256 |
101587c568e5a9de9a2d2e2c6674033837e8dd35d0751dd71534bdcd92648192
|
Provenance
The following attestation bundles were made for unirt-0.5.0-py3-none-win_arm64.whl:
Publisher:
publish-sdk.yml on SesameH/Edge-AI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unirt-0.5.0-py3-none-win_arm64.whl -
Subject digest:
5b611b5e028791ed0c4d7c12c2fe1d4956f0a22bc33a62f3c160501b5aea5f33 - Sigstore transparency entry: 2333049515
- Sigstore integration time:
-
Permalink:
SesameH/Edge-AI@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/SesameH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file unirt-0.5.0-py3-none-win_amd64.whl.
File metadata
- Download URL: unirt-0.5.0-py3-none-win_amd64.whl
- Upload date:
- Size: 12.3 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fb22e5d0a3ecb2fdd60f8bb91b983fac9801d18ccb4d969d3a113cc110f4156
|
|
| MD5 |
4f605bce01728b3b51f35cb8e3a17f14
|
|
| BLAKE2b-256 |
d623f3073b2a51af3c3e9199e54dedade8d794c2488ae5a25b7cd6d8e03b3abf
|
Provenance
The following attestation bundles were made for unirt-0.5.0-py3-none-win_amd64.whl:
Publisher:
publish-sdk.yml on SesameH/Edge-AI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unirt-0.5.0-py3-none-win_amd64.whl -
Subject digest:
2fb22e5d0a3ecb2fdd60f8bb91b983fac9801d18ccb4d969d3a113cc110f4156 - Sigstore transparency entry: 2333049537
- Sigstore integration time:
-
Permalink:
SesameH/Edge-AI@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/SesameH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 36.7 MB
- Tags: Python 3, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4affe6b13215c58b0e36482be5be8db44a5809f4179309da0641d6e652b8d6e3
|
|
| MD5 |
1436947c97eb03f9749b3a9f8e5ff916
|
|
| BLAKE2b-256 |
ac5bc3f540d28f3ce8f07f8716159440ee58f85040f1e1a6f151f4f77ca94db0
|
Provenance
The following attestation bundles were made for unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl:
Publisher:
publish-sdk.yml on SesameH/Edge-AI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl -
Subject digest:
4affe6b13215c58b0e36482be5be8db44a5809f4179309da0641d6e652b8d6e3 - Sigstore transparency entry: 2333049508
- Sigstore integration time:
-
Permalink:
SesameH/Edge-AI@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/SesameH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl.
File metadata
- Download URL: unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl
- Upload date:
- Size: 31.6 MB
- Tags: Python 3, manylinux: glibc 2.31+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18a18c527ae61143007d4943869f6dbd58875432b23895fec5cdf7da022c5216
|
|
| MD5 |
8f868f59f76cc4d2f97a28bd6f853070
|
|
| BLAKE2b-256 |
e44ae96d47b883c1ac3d866aaafe053946c337af1973b596e77c8bfd71c9ac4c
|
Provenance
The following attestation bundles were made for unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl:
Publisher:
publish-sdk.yml on SesameH/Edge-AI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl -
Subject digest:
18a18c527ae61143007d4943869f6dbd58875432b23895fec5cdf7da022c5216 - Sigstore transparency entry: 2333049521
- Sigstore integration time:
-
Permalink:
SesameH/Edge-AI@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/SesameH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file unirt-0.5.0-py3-none-macosx_14_0_arm64.whl.
File metadata
- Download URL: unirt-0.5.0-py3-none-macosx_14_0_arm64.whl
- Upload date:
- Size: 20.1 MB
- Tags: Python 3, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d464ddc94f9b9d70117f891ad64f61b42a0a2bf1cd6b1a9072679534ebddd5be
|
|
| MD5 |
66519bf8ccd83fedfdef9e3ffebb862f
|
|
| BLAKE2b-256 |
97a3eb09c73af558b2c33b6d79aa4b8ce4a400e04158a7ebadaaa4406fa82627
|
Provenance
The following attestation bundles were made for unirt-0.5.0-py3-none-macosx_14_0_arm64.whl:
Publisher:
publish-sdk.yml on SesameH/Edge-AI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unirt-0.5.0-py3-none-macosx_14_0_arm64.whl -
Subject digest:
d464ddc94f9b9d70117f891ad64f61b42a0a2bf1cd6b1a9072679534ebddd5be - Sigstore transparency entry: 2333049528
- Sigstore integration time:
-
Permalink:
SesameH/Edge-AI@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/SesameH
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@29cb794e1ce55c1f09d00a18893a0c2814947da2 -
Trigger Event:
push
-
Statement type: