Instructions to use litert-community/Phi-4-mini-reasoning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT-LM
How to use litert-community/Phi-4-mini-reasoning with LiteRT-LM:
# LiteRT-LM runs on various platforms (Android, iOS, Windows, Linux, macOS, IoT, Web/WASM) # and supports many APIs (C++, Python, Kotlin, Swift, JavaScript, Flutter). # For platform-specific integration guides, please refer to the official developer website: # https://ai.google.dev/edge/litert-lm # To try LiteRT-LM, the easiest way is to use our CLI tool. # 1. Install the LiteRT-LM CLI tool: pip install litert-lm # 2. Download and run this model locally: # See: https://ai.google.dev/edge/litert-lm/cli litert-lm run \ --from-huggingface-repo=litert-community/Phi-4-mini-reasoning \ model.litertlm \ --prompt="Write me a poem"
- LiteRT
How to use litert-community/Phi-4-mini-reasoning with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Phi-4-mini-reasoning β LiteRT-LM (blockwise int4)
microsoft/Phi-4-mini-reasoning converted to
the LiteRT-LM (.litertlm) format for on-device inference with Google's
LiteRT-LM runtime (the engine behind the official
litert-community/* models).
Phi-4-mini-reasoning is a dense 3.8B math/reasoning model from Microsoft (implemented as
Phi3ForCausalLM, 32 layers) β it solves problems with a <think>β¦</think> chain-of-thought, then
the answer.
| File | model.litertlm β int4 block 32 (~2.6 GB) |
| Quantization | int4 weights (symmetric) + OCTAV optimal-clipping; embeddings INT8 (externalized section) |
| Compute | integer |
| Context (KV cache) | 4096 |
| Base model | microsoft/Phi-4-mini-reasoning |
| Decode speed | ~84 tok/s (Mac M-series, GPU) |
β οΈ It's a reasoning model β give it room to think
This model emits a <think>β¦</think> chain-of-thought, then a \boxed{} answer. Run it with
max_tokens β₯ 2048 β at a short limit it gets cut off before the answer. (All quality numbers below
were measured at 2048.)
Quality β GSM8K parity
Measured on GSM8K (n=100, greedy, 0-shot chain-of-thought, max_tokens 2048, identical prompt and answer-extraction for every row).
| Configuration | GSM8K |
|---|---|
| bf16 (reference) | 89.0% |
| LiteRT int4 β block 32 | 81.0% (β8 pt) |
int4 (block 32) is at parity (β8 pt). Why block 32 (not block 128)? This is a precision-sensitive math model: the coarser block-128 int4 dropped to 74% (β15 pt) and degenerated on some prompts, while block 32 holds at 81%. So only the block-32 build is published.
Usage
# build litert-lm from https://github.com/google-ai-edge/litert-lm, then:
litert_lm_main \
--model_path model.litertlm \
--backend gpu \
--input_prompt "A bat and a ball cost \$1.10. The bat costs \$1.00 more than the ball. How much is the ball?"
The .litertlm bundle carries the tokenizer and prompt template (Phi format β <|user|>β¦<|end|><|assistant|>),
so no separate tokenizer files are needed.
Run on Android
The official Google AI Edge Gallery app runs
.litertlm models on-device:
- Install a recent Gallery (package
com.google.ai.edge.gallery, 1.0.15+ supports.litertlm). - Download
model.litertlmand push it:adb push model.litertlm /sdcard/Download/ - In the app tap +, pick the file, choose the GPU backend, and raise the max-tokens setting (β₯2048).
Run on iPhone
Verified on iPhone 17 Pro (LiteRT-LM Swift runtime): loads and generates correct answers. This is a ~2.6 GB bundle (Phi's 200K-token vocab makes a large externalized embedder), so it sits near the iOS memory ceiling β if you hit "embedding lookup model is not initialized" (a low-memory symptom), reboot the phone to free RAM and reload.
Conversion
Converted with the official litert-torch
converter. Phi-4-mini uses the Phi3ForCausalLM arch with LongRoPE + a (nominal) sliding window;
two export-time adjustments are needed for current litert-torch:
- LongRoPE: replace
Phi3RotaryEmbedding.forwardwith a static version (the@dynamic_rope_updateseq-len branch is data-dependent under torch.export; for cache β€ original_max=4096 the short factor is always correct). - Sliding window: set
config.sliding_window=None(it is 262144 β« context, i.e. full-causal) so the standard causal mask path is used.
Recipe: blockwise-32 int4 + OCTAV, embeddings INT8, KV cache 4096, externalize_embedder=True.
License
MIT, inherited from the base model microsoft/Phi-4-mini-reasoning.
- Downloads last month
- 32
Model tree for litert-community/Phi-4-mini-reasoning
Base model
microsoft/Phi-4-mini-reasoning