Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

unirt-0.5.0-py3-none-win_arm64.whl (9.5 MB view details)

Uploaded Python 3Windows ARM64

unirt-0.5.0-py3-none-win_amd64.whl (12.3 MB view details)

Uploaded Python 3Windows x86-64

unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl (36.7 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl (31.6 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ ARM64

unirt-0.5.0-py3-none-macosx_14_0_arm64.whl (20.1 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

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

Hashes for unirt-0.5.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 5b611b5e028791ed0c4d7c12c2fe1d4956f0a22bc33a62f3c160501b5aea5f33
MD5 0d8035cae34cf94ef3aa1ac25aaa690a
BLAKE2b-256 101587c568e5a9de9a2d2e2c6674033837e8dd35d0751dd71534bdcd92648192

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for unirt-0.5.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 2fb22e5d0a3ecb2fdd60f8bb91b983fac9801d18ccb4d969d3a113cc110f4156
MD5 4f605bce01728b3b51f35cb8e3a17f14
BLAKE2b-256 d623f3073b2a51af3c3e9199e54dedade8d794c2488ae5a25b7cd6d8e03b3abf

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 4affe6b13215c58b0e36482be5be8db44a5809f4179309da0641d6e652b8d6e3
MD5 1436947c97eb03f9749b3a9f8e5ff916
BLAKE2b-256 ac5bc3f540d28f3ce8f07f8716159440ee58f85040f1e1a6f151f4f77ca94db0

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl.

File metadata

File hashes

Hashes for unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 18a18c527ae61143007d4943869f6dbd58875432b23895fec5cdf7da022c5216
MD5 8f868f59f76cc4d2f97a28bd6f853070
BLAKE2b-256 e44ae96d47b883c1ac3d866aaafe053946c337af1973b596e77c8bfd71c9ac4c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for unirt-0.5.0-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d464ddc94f9b9d70117f891ad64f61b42a0a2bf1cd6b1a9072679534ebddd5be
MD5 66519bf8ccd83fedfdef9e3ffebb862f
BLAKE2b-256 97a3eb09c73af558b2c33b6d79aa4b8ce4a400e04158a7ebadaaa4406fa82627

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page