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 |
|---|---|---|
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.
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.
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
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 Distribution
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.1.3-py3-none-macosx_14_0_arm64.whl.
File metadata
- Download URL: unirt-0.1.3-py3-none-macosx_14_0_arm64.whl
- Upload date:
- Size: 19.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06b752a46b5564e106996e5ba7a420e8c50092f1032d9480a4db2874191ce40e
|
|
| MD5 |
13da10b26c71c05640368be1167696da
|
|
| BLAKE2b-256 |
d7bc7f8694ee1523124a575c83f56af0aee6f0a1d9dc233a5b71b6ede9eb5a8a
|