Skip to main content

Python binding for UniRT — multi-backend on-device LLM inference with an extensible VLM API

Reason this release was yanked:

internal Error

Project description

unirt (Python binding)

Python binding for the UniRT SDK — run LLMs locally through a single API with interchangeable backends:

runtime models hardware
llama_cpp GGUF CPU / Metal / Vulkan / CUDA
mlx HF safetensors (validated SmolLM2-style Llama/ByteLevel-BPE layout; dense or MLX-quantized) Apple Silicon Metal GPU
onnxruntime ONNX encoder embeddings CPU / Apple Core ML

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

macOS arm64 wheels ship every native library — no toolchain, no build step.

Quickstart (CLI)

unirt chat bartowski/SmolLM2-135M-Instruct-GGUF   # download + interactive chat
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.

The native library is discovered automatically from <repo>/sdk/pkg-unirt/lib (dev layout) or the packaged wheel; set UNIRT_LIB_PATH / UNIRT_PLUGIN_PATH to override. See the repository README for build instructions, the interactive chat example, and the OpenAI-compatible server (python3 -m unirt.server).

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

Uploaded Python 3Windows ARM64

unirt-0.2.1-py3-none-win_amd64.whl (5.2 MB view details)

Uploaded Python 3Windows x86-64

unirt-0.2.1-py3-none-manylinux_2_31_x86_64.whl (5.3 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

unirt-0.2.1-py3-none-manylinux_2_31_aarch64.whl (4.9 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ ARM64

unirt-0.2.1-py3-none-macosx_14_0_arm64.whl (4.0 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: unirt-0.2.1-py3-none-win_arm64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for unirt-0.2.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 07b75dcee29565d8af8f11bdc05d1b4a3d572ff86d5515463ef9ba353d66e460
MD5 01dd5f8e0276900f3287bab91a8e0049
BLAKE2b-256 f200d10a1f29bb966e89c8b0960571fc60049c83620a3d9fe0bf6cc801096460

See more details on using hashes here.

File details

Details for the file unirt-0.2.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: unirt-0.2.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for unirt-0.2.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f55bebb514e99c437c7779bb0adf3c8ee498d0abf3e86e093443e82acd44fefb
MD5 7743e6f2582d54a079e8746135a195b0
BLAKE2b-256 143d3a066c57d672ed50a70192ba2b29375efadd3593eb9063b5e132aed78b8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unirt-0.2.1-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d9137faa86cbda23bb4c1490ce4dd5e9af6d66495e3e3e8044aa6df2ff42ae3e
MD5 d1e23d25593a6a0cfdb873e0dee617da
BLAKE2b-256 4a5e0760386fbb1cd4a1ef9f5aa9825200881c5e81654ddf7922ebecfac88e85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unirt-0.2.1-py3-none-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 33a5aa670351965b4bc473d00baa2872868dcef388814528eda614399a8711b7
MD5 b44de88dd4552e2c4473393bc55c9de3
BLAKE2b-256 c5aa7a38935205bbac9a99c0a055b048f009c62a74c66845326e848226f622f8

See more details on using hashes here.

File details

Details for the file unirt-0.2.1-py3-none-macosx_14_0_arm64.whl.

File metadata

  • Download URL: unirt-0.2.1-py3-none-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: Python 3, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for unirt-0.2.1-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 97613176438bd24317091897cb307cf9f13bee2f18a06bade1720fd285b12502
MD5 e18dcbf5e7e249acd254f188d9b1ab46
BLAKE2b-256 ef21adcc553ef89a2a30f2cf11c2f9aff509d781b79b003531f749779c6e9b1a

See more details on using hashes here.

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