Skip to main content

hf-to-litertlm

One command from a Hugging Face model repo to a .litertlm bundle for Google's LiteRT-LM runtime, on a pinned toolchain. Rebuilding from the lock file it writes gives the same bytes.

uvx hf-to-litertlm <org>/<model>                              # -> out/<model>/: <model>_int8.litertlm, <model>.lock.json, convert_report.json
uvx hf-to-litertlm verify out/<model>/<model>.lock.json       # rebuild from the lock: MATCH = the same bytes
uvx hf-to-litertlm check out/<model>/<model>_int8.litertlm    # litert-lm 0.18.0, CPU: load + an echo prompt -> PASS / FAIL
uvx hf-to-litertlm nvidia/parakeet-tdt-0.6b-v3 --smoke        # speech recognition: a Speech2TextMetadata .litertlm (from 0.1.2)
uvx hf-to-litertlm ./my-finetune                              # Gemma 4 E2B finetune in a local folder, Linux x86-64 (from 0.1.3)

uvx needs uv; pip install hf-to-litertlm pulls uv in as a dependency and gives the same hf-to-litertlm command. hf-to-litertlm <org>/<model> is tested on macOS arm64 only. On an M4 Max (128 GB), a 1.7B model took 3 to 4 minutes, the gate included, and peaked at 25 GB of RAM; gemma-4-E2B-it took 7 minutes and 64 GB (locks/refs/CHANGELOG.md).

  • Toolchain for hf-to-litertlm <org>/<model>. litert-torch 0.9.4, litert-lm-builder 0.18.0, litert-lm 0.18.0, torch 2.13.0 and transformers 5.14.1, and every other package at the version in the repository's uv.lock. The package carries the converter scripts with that pyproject.toml and uv.lock and runs them with uv run --frozen --project ~/.cache/hf-to-litertlm/<version>/, which gives the environment uv sync makes in a clone of the repository; out/ is written in the current directory. So a lock the package wrote verifies in a clone, and a clone's lock verifies from the package, when both have the same uv.lock and the same Python patch version (the reference locks record 3.12.11). The first run installs the environment (about 1.5 GB on macOS arm64, 1.6 GB once a model has been converted; uv also fetches a Python 3.12 if none is installed). Model files download into the Hugging Face cache.
  • The lock (<model>.lock.json) records the Hub commit, the size and sha256 of every file the export read, the export call, every package version, and the sha256 of the bundle and of each of its sections. litert-lm-builder writes a random uuid and the current time into every bundle header (google-ai-edge/LiteRT-LM#4064); the converter takes the timestamp from the source commit and the uuid from the source, the recipe and the toolchain instead. The export runs under PYTHONHASHSEED=0, because litert-torch writes the stop tokens in set iteration order (google-ai-edge/litert-torch#1346). A lock verifies only on the toolchain that wrote it: when the Python version or a package version differs, verify stops with FAIL toolchain and lists the differences.
  • Checked before it is called done. The gate: eight short questions with known answers (17 + 25, the capital of Japan, …) on the pinned litert-lm CLI, CPU, greedy, scored for the answer and for degenerate output; pass = 6 of 8. Refused with a JSON reason, among others: repos gated behind an access request, architectures that need the repo's own Python code, pre-quantized weights, repos without full weights. A LoRA / PEFT adapter repo is merged into its base and then exported (that route writes no lock yet).
  • A chat template litert-lm 0.18 can render. litert-lm 0.18 renders chat templates on native values: a map has no Python methods, and a message's content is a list of text parts. When the model's template does not render the way transformers renders it, the converter edits it (.get → indexing, the parts → one string) and keeps the edit only if the prompt renders byte-identical to transformers on three test conversations (four when the template reads enable_thinking). The lock records the edits.
  • One line when it fails: FAIL <stage>: <op or first error line> -> next: <hint>. Exit codes of hf-to-litertlm <org>/<model>: 0 = converted and passed the gate, 1 = the gate or the check failed, 2 = refused or stopped before any weight file is downloaded, 3 = any later failure; verify exits 0 on MATCH, check exits 0 on PASS.

Rebuilt byte for byte from their locks in a clone, on macOS arm64: Qwen/Qwen3-1.7B, HuggingFaceTB/SmolLM2-1.7B-Instruct and google/gemma-4-E2B-it (gate 8/8, 7/8 and 8/8). From this package, Qwen/Qwen3-1.7B converted to the bytes that its lock in locks/refs/ records (gate 8/8), and a clone rebuilt the package's lock to the same bytes.

Speech recognition (from 0.1.2). A standalone speech recognition checkpoint converts with the same command. Today that is transformers' ParakeetForTDT (model_type parakeet_tdt: nvidia/parakeet-tdt-0.6b-v3 and finetunes saved with transformers); the model_type picks the route, and --task asr names it. The output is one .litertlm in the form of litert-torch PR #1426: a Speech2TextMetadata section, the repo's own tokenizer.json and one .tflite with the encode / decode / decode_1 signatures. MediaPipe 1.2.0's AudioTranscriber runs it; the litert-lm 0.19.0 Python package and CLI have no speech-to-text API. The gate transcribes LibriSpeech clips on the CPU (--smoke: one clip; by default 73 clips, word error rate at most 0.10). The first such run also installs a second environment for the bundle writer and the gate (litert-lm-builder 0.19.0, mediapipe 1.2.0). CTC, RNN-T, Whisper, Moonshine and the streaming Nemotron models are refused with the reason. Details: docs/asr-route.md.

Gemma 4 E2B finetunes in a local folder (from 0.1.3). uvx hf-to-litertlm ./my-finetune converts the Gemma 4 E2B finetune in ./my-finetune to out/my-finetune/my-finetune_int4.litertlm and writes no lock file. It needs Linux x86-64 and at least 22 GiB of available memory (a container with a 24 GiB limit worked). The folder holds merged weights that are not quantized, with their tokenizer and chat template, or a LoRA adapter whose adapter_config.json names, by Hugging Face id, a base that is not quantized. The converter stops with one line that says what to do next, before any weight file is downloaded: on any other platform, with less memory, with a folder that holds another Gemma 4 size or another model, or with an adapter whose adapter_config.json does not name its base. The .litertlm file is text only, with a 2,048-token KV cache. It carries the folder's tokenizer unchanged. The chat template is edited only as far as LiteRT-LM's renderer needs (for the templates tested here, .get(...) written as indexing) and checked on test conversations against the prompts that transformers renders from the original template. A template the converter cannot fix this way stops the conversion. An adapter folder that lacks a tokenizer or a chat template takes each missing one from the base. The converter then asks the file the same eight questions as hf-to-litertlm <org>/<model> does (litert-lm 0.19.2, CPU, pass = 6 of 8).

On a Google Colab T4 runtime with High-RAM, Unsloth's Gemma 4 E2B text notebook ran unchanged and saved a LoRA on the attention and MLP layers to gemma_4_lora. A pre-release build of 0.1.3 converted gemma_4_lora in about 17 minutes, the first-run installs and the eight questions included, and the file got 7 of 8 right on Colab's CPU. On a T4 runtime with standard RAM, an earlier pre-release build found 9.9 GiB of available memory and stopped at the memory check. The public LoRA 3ndetz/zoomerlm-gemma4-e2b was also tested in two forms: merged into unsloth/gemma-4-E2B-it, and as its adapter folder with base_model_name_or_path in its adapter_config.json set to unsloth/gemma-4-E2B-it. In a linux/amd64 Docker container (x86-64 emulated on an Apple-silicon Mac), both files got 8 of 8 right; the adapter folder's file, made byte for byte the same on Colab, got 7 of 8 right on Colab's CPU. A file made by an earlier pre-release build, identical to the merged folder's file except for its header, also ran on a Pixel 11 Pro's CPU and GPU with LiteRT-LM from its main branch and got 7 of 8 right on each.

The hybrid families that need a patched litert-torch checkout (granite-4.0-h, Falcon-H1, Zamba2, Nemotron-H) and the hand-made recipes of the repository's published conversions (--curated) run from a clone of the repository; the package refuses both before any weight file is downloaded and names the clone (a model that has a hand-made recipe still converts on the generic path).

The design, the lock format and how to raise the toolchain: docs/one-command-lock.md.

Metadata

Release files for hf-to-litertlm 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hf-to-litertlm 0.1.3
File Size Uploaded Provenance Actions
hf_to_litertlm-0.1.3.tar.gz 325.7 kB Without provenance Details for hf_to_litertlm-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hf-to-litertlm 0.1.3
File Interpreter ABI Platform Actions
hf_to_litertlm-0.1.3-py3-none-any.whl Python 3 none any Details for hf_to_litertlm-0.1.3-py3-none-any.whl

Total release size: 651.7 kB

Release files / hf_to_litertlm-0.1.3.tar.gz

Download URL hf_to_litertlm-0.1.3.tar.gz
Size 325.7 kB
Tags Source
SHA-256 checksum
How to use checksums
da12d2988cc3cf4de1d5a456b721058bf2763475ef9362eb729e4f2f07d1d8ea
BLAKE2b-256 checksum
How to use checksums
16e73436bc9b848f588ec2673e61f452e1b367d966a2914bee7d07d8910f2b9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / hf_to_litertlm-0.1.3-py3-none-any.whl

Download URL hf_to_litertlm-0.1.3-py3-none-any.whl
Size 326.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ea996072a71af7aca0b21cbeb0017e6265cfc50462dc93ed50888bbfb0a0cb9
BLAKE2b-256 checksum
How to use checksums
8c16b1885f6e3e7c54fe2f389ac404e6f95eccedf57cb15f5913f9883a9c23b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Security for hf-to-litertlm 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page