Instructions to use barakplasma/translategemma-4b-it-android-task-quantized with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use barakplasma/translategemma-4b-it-android-task-quantized 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
Merge multimodal TranslateGemma artifact docs
Browse files
CLAUDE.md
CHANGED
|
@@ -6,6 +6,9 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
| 6 |
|
| 7 |
Python toolkit that converts Google's TranslateGemma 4B IT model (HuggingFace) into on-device inference bundles for Android. Google's official TFLite files only support WebGPU β this project produces CPU/XNNPACK-compatible `.litertlm` (LiteRT-LM) and `.task` (MediaPipe) files with proper KV-cache prefill/decode signatures.
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
## Common Commands
|
| 10 |
|
| 11 |
### Single quantization conversion (produces `.task`)
|
|
@@ -109,6 +112,7 @@ In Google AI Edge Gallery **Prompt Lab** mode, paste this as the System Prompt w
|
|
| 109 |
- `conv-venv/` β virtualenv with all deps (`litert-torch==0.8.0`, `mediapipe`, `ai_edge_torch`, `transformers`)
|
| 110 |
- `/tmp/litert-lm-pkg/` β manually assembled package from cloned LiteRT-LM repo with compiled FlatBuffer (`flatc -p --gen-onefile`) and proto (`protoc`) Python bindings; required by `bundle_litertlm.py` at runtime; NOT persistent across reboots
|
| 111 |
- `/tmp/litert-lm/` β cloned `google-ai-edge/LiteRT-LM` repo (schema source for rebuilding the package)
|
| 112 |
-
-
|
|
|
|
| 113 |
- `translategemma-4b-it/tokenizer.model` is the SentencePiece binary used by both `.task` and `.litertlm` bundlers; `ensure_tokenizer_model()` auto-converts from `tokenizer.json` if missing
|
| 114 |
- HuggingFace repo: `barakplasma/translategemma-4b-it-android-task-quantized`; upload token in `HF_TOKEN` env var
|
|
|
|
| 6 |
|
| 7 |
Python toolkit that converts Google's TranslateGemma 4B IT model (HuggingFace) into on-device inference bundles for Android. Google's official TFLite files only support WebGPU β this project produces CPU/XNNPACK-compatible `.litertlm` (LiteRT-LM) and `.task` (MediaPipe) files with proper KV-cache prefill/decode signatures.
|
| 8 |
|
| 9 |
+
The primary Hugging Face app artifact is the multimodal image+text LiteRT-LM bundle:
|
| 10 |
+
`artifacts/int4-multimodal/translategemma-4b-it-int4-multimodal.litertlm` (~2.76 GB). It supports structured text translation and image translation through LiteRT-LM vision, and is intended for PrivateAITranslate. If this file is absent from the Hugging Face repo, the app download URL for the multimodal model will 404.
|
| 11 |
+
|
| 12 |
## Common Commands
|
| 13 |
|
| 14 |
### Single quantization conversion (produces `.task`)
|
|
|
|
| 112 |
- `conv-venv/` β virtualenv with all deps (`litert-torch==0.8.0`, `mediapipe`, `ai_edge_torch`, `transformers`)
|
| 113 |
- `/tmp/litert-lm-pkg/` β manually assembled package from cloned LiteRT-LM repo with compiled FlatBuffer (`flatc -p --gen-onefile`) and proto (`protoc`) Python bindings; required by `bundle_litertlm.py` at runtime; NOT persistent across reboots
|
| 114 |
- `/tmp/litert-lm/` β cloned `google-ai-edge/LiteRT-LM` repo (schema source for rebuilding the package)
|
| 115 |
+
- Multimodal conversion observed peak RSS around 73.9 GiB; require 96 GB minimum RAM, with 128 GB preferred. Ideal builder is a Vast.ai PyTorch image or Ubuntu-based NVIDIA/PyTorch image rather than a bare CUDA runtime image.
|
| 116 |
+
- CPU real-device validation has passed on Pixel 10 and Galaxy S22 / S22 Ultra-class targets. GPU initialization currently fails during validation and should be considered experimental and not validated.
|
| 117 |
- `translategemma-4b-it/tokenizer.model` is the SentencePiece binary used by both `.task` and `.litertlm` bundlers; `ensure_tokenizer_model()` auto-converts from `tokenizer.json` if missing
|
| 118 |
- HuggingFace repo: `barakplasma/translategemma-4b-it-android-task-quantized`; upload token in `HF_TOKEN` env var
|
README.md
CHANGED
|
@@ -19,7 +19,7 @@ On-device translation model for Android using [Google AI Edge](https://ai.google
|
|
| 19 |
Converts [google/translategemma-4b-it](https://huggingface.co/google/translategemma-4b-it) (55 languages, 4B params)
|
| 20 |
into formats that run locally on Android without internet or cloud APIs.
|
| 21 |
|
| 22 |
-
Google only publishes WebGPU-only TFLite files. This repo bridges that gap with CPU/XNNPACK-compatible `.litertlm` bundles (LiteRT-LM format) with embedded chat template.
|
| 23 |
|
| 24 |
---
|
| 25 |
|
|
@@ -29,8 +29,11 @@ Google only publishes WebGPU-only TFLite files. This repo bridges that gap with
|
|
| 29 |
|------|------|-------|
|
| 30 |
| `artifacts/int4-generic/translategemma-4b-it-int4-generic.litertlm` | ~2 GB | INT4 blockwise quant β faster, lower RAM |
|
| 31 |
| `artifacts/dynamic_int8-generic/translategemma-4b-it-dynamic_int8-generic.litertlm` | ~4 GB | Dynamic INT8 β better quality |
|
|
|
|
| 32 |
|
| 33 |
-
**Start with INT4** if you're unsure β it loads faster and uses less RAM. Use dynamic_int8 for better translation quality.
|
|
|
|
|
|
|
| 34 |
|
| 35 |
---
|
| 36 |
|
|
@@ -68,6 +71,10 @@ Use standard ISO 639-1 language codes: `en`, `he`, `fr`, `es`, `de`, `ar`, `zh`,
|
|
| 68 |
|
| 69 |
Plain text (no tags) is also accepted β the model will attempt translation based on context.
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
---
|
| 72 |
|
| 73 |
## Device Requirements
|
|
@@ -79,6 +86,8 @@ Plain text (no tags) is also accepted β the model will attempt translation bas
|
|
| 79 |
| OS | Android 10+ |
|
| 80 |
| Runtime | Google AI Edge Gallery or LiteRT-LM SDK |
|
| 81 |
|
|
|
|
|
|
|
| 82 |
---
|
| 83 |
|
| 84 |
## What's Different From Google's Official Files
|
|
@@ -106,7 +115,17 @@ The `scripts/` folder contains the full conversion pipeline:
|
|
| 106 |
|
| 107 |
### Reproduce a build
|
| 108 |
|
| 109 |
-
Requirements:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
```bash
|
| 112 |
# Clone LiteRT-LM builder (needed by bundle_litertlm.py)
|
|
@@ -117,7 +136,7 @@ pip install litert-torch==0.8.0 mediapipe transformers huggingface-hub
|
|
| 117 |
# Download model
|
| 118 |
huggingface-cli download google/translategemma-4b-it --local-dir ./translategemma-4b-it
|
| 119 |
|
| 120 |
-
# Convert to TFLite with KV cache (~30-60 min, needs
|
| 121 |
python scripts/convert_translategemma_android.py \
|
| 122 |
--model-dir ./translategemma-4b-it \
|
| 123 |
--tflite-dir ./tflite_output/dynamic_int8 \
|
|
|
|
| 19 |
Converts [google/translategemma-4b-it](https://huggingface.co/google/translategemma-4b-it) (55 languages, 4B params)
|
| 20 |
into formats that run locally on Android without internet or cloud APIs.
|
| 21 |
|
| 22 |
+
Google only publishes WebGPU-only TFLite files. This repo bridges that gap with CPU/XNNPACK-compatible `.litertlm` bundles (LiteRT-LM format) with embedded chat template, including a multimodal image+text Android bundle for PrivateAITranslate.
|
| 23 |
|
| 24 |
---
|
| 25 |
|
|
|
|
| 29 |
|------|------|-------|
|
| 30 |
| `artifacts/int4-generic/translategemma-4b-it-int4-generic.litertlm` | ~2 GB | INT4 blockwise quant β faster, lower RAM |
|
| 31 |
| `artifacts/dynamic_int8-generic/translategemma-4b-it-dynamic_int8-generic.litertlm` | ~4 GB | Dynamic INT8 β better quality |
|
| 32 |
+
| `artifacts/int4-multimodal/translategemma-4b-it-int4-multimodal.litertlm` | ~2.76 GB | INT4 multimodal image+text bundle for structured text translation and LiteRT-LM vision image translation |
|
| 33 |
|
| 34 |
+
**Start with INT4** if you're unsure β it loads faster and uses less RAM. Use dynamic_int8 for better text translation quality.
|
| 35 |
+
|
| 36 |
+
The multimodal artifact is the bundle expected by PrivateAITranslate for image translation. If `artifacts/int4-multimodal/translategemma-4b-it-int4-multimodal.litertlm` is not present in this Hugging Face repo, the app download URL for that model will return 404.
|
| 37 |
|
| 38 |
---
|
| 39 |
|
|
|
|
| 71 |
|
| 72 |
Plain text (no tags) is also accepted β the model will attempt translation based on context.
|
| 73 |
|
| 74 |
+
### Image translation
|
| 75 |
+
|
| 76 |
+
The multimodal `.litertlm` bundle uses LiteRT-LM vision support for image+text translation flows in PrivateAITranslate. It is intended for structured text translation and image translation, not general image captioning.
|
| 77 |
+
|
| 78 |
---
|
| 79 |
|
| 80 |
## Device Requirements
|
|
|
|
| 86 |
| OS | Android 10+ |
|
| 87 |
| Runtime | Google AI Edge Gallery or LiteRT-LM SDK |
|
| 88 |
|
| 89 |
+
CPU real-device validation passed on Pixel 10 and Galaxy S22 / S22 Ultra-class targets. GPU execution currently fails initialization in validation and should be treated as experimental and not validated.
|
| 90 |
+
|
| 91 |
---
|
| 92 |
|
| 93 |
## What's Different From Google's Official Files
|
|
|
|
| 115 |
|
| 116 |
### Reproduce a build
|
| 117 |
|
| 118 |
+
Requirements: 96 GB minimum system RAM, 128 GB preferred, Python 3.12, `litert-torch==0.8.0`.
|
| 119 |
+
|
| 120 |
+
Observed multimodal export peak RSS was about 73.9 GiB, so 96 GB is the practical floor once Python, model cache, filesystem cache, and conversion overhead are included. Use 128 GB when running multiple quantization attempts or keeping extra build artifacts.
|
| 121 |
+
|
| 122 |
+
Ideal Vast.ai image:
|
| 123 |
+
|
| 124 |
+
- Vast.ai PyTorch image or an Ubuntu-based NVIDIA/PyTorch CUDA image, not a bare CUDA runtime image.
|
| 125 |
+
- Python 3.12 with `uv`/pip, Git, Git LFS, Hugging Face CLI, and build tools available.
|
| 126 |
+
- CUDA/PyTorch wheel support matching the rented GPU architecture; use CUDA 12.8+ PyTorch wheels on Blackwell GPUs.
|
| 127 |
+
- 96+ GB RAM and at least 80 GB free disk; 150+ GB disk is safer for source checkpoint, caches, exported TFLite files, and `.litertlm` bundles.
|
| 128 |
+
- Persistent `/workspace` volume if the instance may be stopped/recycled before upload.
|
| 129 |
|
| 130 |
```bash
|
| 131 |
# Clone LiteRT-LM builder (needed by bundle_litertlm.py)
|
|
|
|
| 136 |
# Download model
|
| 137 |
huggingface-cli download google/translategemma-4b-it --local-dir ./translategemma-4b-it
|
| 138 |
|
| 139 |
+
# Convert to TFLite with KV cache (~30-60 min, needs 96 GB minimum RAM)
|
| 140 |
python scripts/convert_translategemma_android.py \
|
| 141 |
--model-dir ./translategemma-4b-it \
|
| 142 |
--tflite-dir ./tflite_output/dynamic_int8 \
|
artifacts/int4-multimodal/translategemma-4b-it-int4-multimodal.litertlm
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1bc8e828fbe56dfb503ac033ac84a9eb941d85a9c196803167fa39b35f7fb033
|
| 3 |
+
size 2757894128
|
scripts/multi_quant_build_upload.py
CHANGED
|
@@ -196,7 +196,10 @@ def plan_quants(requested_quants, native_ok: bool):
|
|
| 196 |
|
| 197 |
def main():
|
| 198 |
ap = argparse.ArgumentParser(
|
| 199 |
-
description=
|
|
|
|
|
|
|
|
|
|
| 200 |
)
|
| 201 |
ap.add_argument("--converter-script", default="/home/ubuntu/convert_translategemma_android.py")
|
| 202 |
ap.add_argument("--model-id", default="google/translategemma-4b-it")
|
|
@@ -477,4 +480,4 @@ def main():
|
|
| 477 |
|
| 478 |
|
| 479 |
if __name__ == "__main__":
|
| 480 |
-
main()
|
|
|
|
| 196 |
|
| 197 |
def main():
|
| 198 |
ap = argparse.ArgumentParser(
|
| 199 |
+
description=(
|
| 200 |
+
"Run multi-quant conversion+bundle and upload successful artifacts to HF. "
|
| 201 |
+
"Requires 96 GB minimum system RAM; 128 GB is preferred for headroom."
|
| 202 |
+
)
|
| 203 |
)
|
| 204 |
ap.add_argument("--converter-script", default="/home/ubuntu/convert_translategemma_android.py")
|
| 205 |
ap.add_argument("--model-id", default="google/translategemma-4b-it")
|
|
|
|
| 480 |
|
| 481 |
|
| 482 |
if __name__ == "__main__":
|
| 483 |
+
main()
|