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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.31+ x86-64

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

Uploaded Python 3manylinux: glibc 2.31+ ARM64

unirt-0.2.2-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.2-py3-none-win_arm64.whl.

File metadata

  • Download URL: unirt-0.2.2-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.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 515eb816d234710c465a5f365f7993ea607eef6c3d85469e0d68491039728219
MD5 6983ac91e69fd4bab6f8027bb55a445b
BLAKE2b-256 ce6c704062cddb30322488a840f256c29c0094aa6f21f138d54752eb2147c60a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unirt-0.2.2-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.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 07d219ec806331e72f141788071a775ec42c0fa66b3ccb7f3b918cdb82e195f7
MD5 361414092bda93ba9e8a44df3f00e2c6
BLAKE2b-256 8c8a5bd9d9e91b2fbdb6b5a68240e372a1ee96079e3ac3d549a329d1fb07ac47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unirt-0.2.2-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 f4d8e9d055035887d8836a877ea46213fb126235f03a3b85f04bee7b605fa18e
MD5 9ad7e052e2b4fab72b0e0aeed8690ea3
BLAKE2b-256 0b44b671e78bf730cb0fed9e4ab11000e5cd2bb0201507420e191bd626045d9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unirt-0.2.2-py3-none-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 5e7a444be5d8acce4c80d01499bf4043fca1d0c5c06cf33cf472a4b96d5cc4e1
MD5 dcd050d0ba1828ffeec0c32030ea1e46
BLAKE2b-256 5598b1cadd8b57734b8b3d5f6a1c3f2c633e8af910268b270c0a9bd22e531956

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unirt-0.2.2-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.2-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e4f802f3ff2c2b3999caeac57cba7bea322d0420e3166d1cd66bbbef66c6a0e2
MD5 a9b6ee9e00abfaf78fd63fa8c0b8ab3c
BLAKE2b-256 a21dda0496e1987aec485f3df1d11a1520bccd77a65c9c2b1d19c1a5ca690653

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