--- license: apache-2.0 base_model: thinkingmachines/Inkling-2-Mini base_model_relation: quantized library_name: litert-lm pipeline_tag: image-text-to-text tags: - litert - litert-lm - litertlm - on-device - multimodal - vision-language - moe --- # Inkling-2-Mini LiteRT-LM This repository is a conversion of [thinkingmachines/Inkling-2-Mini](https://huggingface.co/thinkingmachines/Inkling-2-Mini) to LiteRT-LM, for text and image input. On an Apple M4 Max with 128 GB and macOS 27.0, a text-only benchmark with a 1,024-token prompt decoded 256 tokens on the GPU (WebGPU) at 8.64 tok/s with the GPU file and at 7.23 tok/s with the int8 file, measured in turn with LiteRT-LM 0.19.2. [LiteRT-LM](https://github.com/google-ai-edge/LiteRT-LM) is Google's runtime for running language models on your own device. Download the file for your backend: | Backend | File | Size | |---|---|---:| | GPU | [`Inkling-2-Mini_mixed_int4_gpu.litertlm`](https://huggingface.co/litert-community/Inkling-2-Mini/blob/main/Inkling-2-Mini_mixed_int4_gpu.litertlm) | 20.17 GB | | CPU | [`Inkling-2-Mini_int8.litertlm`](https://huggingface.co/litert-community/Inkling-2-Mini/blob/main/Inkling-2-Mini_int8.litertlm) | 27.74 GB | In that benchmark, the GPU file used more memory than the int8 file, and engine creation took longer with the GPU file. The first run of the commands below writes caches next to the file: the GPU file and its caches take 34.46 GB of disk, and the int8 file and its CPU caches 54.77 GB. Run these commands in the file's folder, from a fresh Python 3.13 virtual environment: they install the runtime, download a public photo and pad it to a square. ```bash pip install litert-lm==0.19.2 pillow curl -L -o cat.jpeg https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg python3 -c "from PIL import Image, ImageOps; im = ImageOps.exif_transpose(Image.open('cat.jpeg')).convert('RGB'); s = max(im.size); sq = Image.new('RGB', (s, s)); sq.paste(im); sq.save('cat_square.png')" ``` On the GPU, with the GPU file: ```bash litert-lm run Inkling-2-Mini_mixed_int4_gpu.litertlm --backend gpu --vision-backend gpu --attachment cat_square.png --prompt "Describe this picture." ``` On the CPU, with the int8 file: ```bash litert-lm run Inkling-2-Mini_int8.litertlm --backend cpu --vision-backend cpu --attachment cat_square.png --prompt "Describe this picture." ``` The GPU command printed its thought between `[thinking]` and `[/thinking]`, then this answer: ```text <|message_model|><|content_text|>The photo shows a small, stocky, fluffy wild cat—likely a Pallas’s cat (manul)—walking across a snow-covered surface. Its thick gray-brown fur is speckled and dusted with snow, giving it a frosty, mottled look. The cat has a flat face, small rounded ears, dark stripes on its cheeks, and a somewhat grumpy expression. One front leg is stretched forward and slightly blurred, suggesting it is in motion, while the other legs support its body. In the background are vertical pale tree trunks, possibly birch, with snow and dark markings, plus a chain-link fence visible on the left. The bottom part of the image is a solid black band.<|end_message|> ``` With LiteRT-LM 0.20.0, the GPU command printed the same bytes as with 0.19.2. The int8 file was not tried with 0.20.0. ## When it does not work - **The GPU file on the CPU.** Not checked: its text questions and pictures were not run on the CPU, and its CPU speed was not measured. On the CPU, use the int8 file. - **Phones.** Not tried: both files are larger than the 12 GB of memory of a Snapdragon Galaxy S26. - **Other computers.** Not tried: only the Mac above ran these files. - **Prompts over 4,096 tokens.** The context holds 4,096 tokens, and a picture takes 256 of them. Given a longer prompt, both commands above printed `An error occurred` on stdout and a Python traceback on stderr that ends with `RuntimeError: INVALID_ARGUMENT: Input token ids are too long. Exceeding the maximum number of tokens allowed: 7480 >= 4096`. They still exited with code 0, so the output is the only sign of the failure. - **Pictures that are not square.** The runtime stretches every picture to 640 × 640 pixels without keeping its proportions, so a circle in a wide picture becomes an oval. Pad the picture to a square first, black at the right and bottom, as the `python3` command above does. ## First run | | GPU file, GPU | int8 file, CPU | |---|---:|---:| | First run of each file's command above, reply included | under 2 min | under 4 min | ## Performance | File | Backend | Prefill (tok/s) | Decode (tok/s) | Time to first token | Engine creation, reading the caches | |---|---|---:|---:|---:|---:| | GPU file | GPU (WebGPU) | 84.89 | 8.64 | 12.18 s | 10.528–11.937 s | | int8 file | GPU (WebGPU) | 84.82 | 7.23 | 12.21 s | 2.442–3.214 s | | int8 file | CPU (XNNPACK, default threads) | 40.46 | 3.36 | 25.61 s | 0.445–0.935 s | Apple M4 Max (128 GB, macOS 27.0), LiteRT-LM 0.19.2 from PyPI, a 1,024-token text prompt and 256 generated tokens, the median of 3 processes (for engine creation, the range of the 3). Speed is still being tuned (updates follow). ## Memory | Peak memory footprint | GPU file, GPU (WebGPU) | int8 file, GPU (WebGPU) | int8 file, CPU | |---|---:|---:|---:| | 1,024-token text prompt, 256 tokens out | 16.53–16.54 GB | about 11 GB | 9.15 GB | | One picture and a short question | 22.60–22.63 GB | 16.54–16.60 GB | 4.76–4.86 GB | ## Accuracy | Check | GPU file, GPU (WebGPU) | int8 file, GPU (WebGPU) | int8 file, CPU | |---|---:|---:|---:| | 12 short text questions: answer correct | 12 / 12 | 12 / 12 | 12 / 12 | | The same 12: every reply token less than 1.0 logit below the author's model's top token | 11 / 12 | 12 / 12 | 12 / 12 | | 3 pictures: every reply token less than 1.0 logit below the author's model's top token | 3 / 3 | 3 / 3 | 3 / 3 | | One of them, a receipt with 16 lines of text: found in the answer | 15 / 16 | 14 / 16 | 15 / 16 | | 3-turn conversation: third answer correct | pass | pass | pass | In the remaining reply of the GPU file, one token is 1.12 logits below the author's model's top token. The author's model found all 16 from a different input: the picture at its own size, 768 image tokens instead of 256, at the lowest thinking effort. None of the WebGPU runs above, with either file, printed a `Validation error` message. ## Limitations - After each complete reply, LiteRT-LM prefills the reply again into the KV cache, thought included, so the thought stays in the conversation and counts toward the 4,096 tokens. In a two-turn WebGPU conversation with the int8 file through the Python API, the context held 605 tokens after the first turn: the cat picture, its question and the reply, 184 of them the thought. With the int8 file on LiteRT-LM 0.19.2, the reply's stream in the Python API ended only after this prefill: 3.5–7.4 s after `<|end_message|>` arrived on the CPU and 6.6–8.6 s on WebGPU. Through the Python API, the thought arrives in a separate `thinking` channel. - Start a new conversation after a message fails because it does not fit in the 4,096-token context. On LiteRT-LM 0.19.2, after such a failure, the next three messages in the same conversation, two of them short, all failed with `INTERNAL: Task failed with state: 7`, while a new conversation answered. This was measured once with another file, not with these two. - The model's markers `<|message_model|>`, `<|content_text|>` and `<|end_message|>` come out as text, in the command's output and in the reply text of the Python API. Remove them in your app. - On the CPU, the same greedy question can get a different reply in a new process. On the GPU, each file, asked about the photo in two processes, gave the same reply both times. - Create one Engine per conversation. Both files keep a running state for their short convolutions, and on LiteRT-LM 0.19.2 a new conversation on the same Engine can continue from the previous conversation's state ([LiteRT-LM#3165](https://github.com/google-ai-edge/LiteRT-LM/issues/3165)). This was not measured on these files. - After the first turn of a conversation, LiteRT-LM can put a token of the conversation into the KV cache without its embedding, because in both files the text embedder is a model of its own and the decoder takes embeddings. Later answers can then differ from what the model answers to the same messages in one prompt. This was read in the source of LiteRT-LM 0.19.1 and measured with 0.18.1 on WeVisOne-VL-2B and Qwen2.5-Coder-1.5B-Instruct, not on these files. One question per conversation avoids it, as does a new conversation that starts with the earlier messages and the new question. - Tool calls were not tried with either file. ## How it was made - Both files were converted from the author's revision `ed40e7da625f594fc9c4990f5f66be24873c22d7`, which stores the experts in NVFP4 and MXFP8 and the other weights in bf16. - The author's `mtp.safetensors` is not in either file. - The GPU file's models differ from the int8 file's only in the text decoder's experts. - The tokenizer is the author's `tokenizer.json`, byte for byte. - The chat template is the author's, with six edits for LiteRT-LM's template engine. ## License Apache 2.0, the license of the author's model: [LICENSE](https://huggingface.co/litert-community/Inkling-2-Mini/blob/main/LICENSE). The author's [Model Acceptable Use Policy](https://thinkingmachines.ai/model-acceptable-use-policy/) covers modified versions like these two files.