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.4.0-py3-none-win_arm64.whl (9.5 MB view details)

Uploaded Python 3Windows ARM64

unirt-0.4.0-py3-none-win_amd64.whl (12.2 MB view details)

Uploaded Python 3Windows x86-64

unirt-0.4.0-py3-none-manylinux_2_31_x86_64.whl (36.6 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

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

Uploaded Python 3manylinux: glibc 2.31+ ARM64

unirt-0.4.0-py3-none-macosx_14_0_arm64.whl (20.0 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file unirt-0.4.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: unirt-0.4.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.4.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 522273fb3e42be62bb2727823d5f16d87278419923f6f98e58e01a3b15deb531
MD5 6802e8ea00ed88fda26f64b82c51e8bf
BLAKE2b-256 4ccda2eebdc2793975d39549e6c88f3599e75c6f08f176d1cadfad5df6bf2f5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for unirt-0.4.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.4.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: unirt-0.4.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 12.2 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.4.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 946817639f3eafdf09526e4298e3fb37092bea46ac747124a741725a50d43452
MD5 8786a770892d1fc5db4823813cdd1d97
BLAKE2b-256 b04e3de10604dade67d760e46b7589b90969f124e36e19cf588dd7281ab2aef1

See more details on using hashes here.

Provenance

The following attestation bundles were made for unirt-0.4.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.4.0-py3-none-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for unirt-0.4.0-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 71353ad75091117d290d2097890600e90e1d073e0f62f464a6b5e99f5ece2da7
MD5 187c459050fbc4d9397b664e2f27db49
BLAKE2b-256 d84cef98e1315a73e1d3c91b04a68339c0e3b5c637a285c03c09245916be97c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for unirt-0.4.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.4.0-py3-none-manylinux_2_31_aarch64.whl.

File metadata

File hashes

Hashes for unirt-0.4.0-py3-none-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 3c712a0283a75c6a87e6f4d20404b0ec86ea00a037514a0c41609078c2870b42
MD5 4b86a8d5951351e5c5816f0e41d5b4b4
BLAKE2b-256 5456838cd00826204b70990ba24f46b0720b62d8ee806d52b27eaeae7452d995

See more details on using hashes here.

Provenance

The following attestation bundles were made for unirt-0.4.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.4.0-py3-none-macosx_14_0_arm64.whl.

File metadata

  • Download URL: unirt-0.4.0-py3-none-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 20.0 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.4.0-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d37a81862ac4878511c23e61aae8b3111db501cf4cf85a1b8d880a203954eb9f
MD5 fb50733d7f26c2c077b2b2be102f71a0
BLAKE2b-256 246539dd2d0f0ca7a3b5bebed7c69bffa2b471db9abc90e706953c2f7b4b6461

See more details on using hashes here.

Provenance

The following attestation bundles were made for unirt-0.4.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