Gemma4 Translate
Translate Prompts (and Screenshots) Locally With Gemma 4 E2B
- image
- translated_text
- info
If you write prompts in anything but English, you already know the dance: compose in your language, alt-tab to DeepL or Google Translate, paste the result into a CLIP Text Encode, repeat every time you tweak a word. Gemma4 Translate removes the tab-switching. It's a fully local translation node that runs Google's gemma-4-E2B-it model right inside ComfyUI - no API, no key, no data leaving your machine. The name is a lie only in the sense that there's no backend to pay for; it's pure transformers on your own GPU.
It's a fork of the popular ComfyUI-TranslateGemma, reworked for Gemma 4 E2B and for people who want to run it offline. The headline feature most people miss: it's multimodal. The E2B variant reads images too, so you can feed it a screenshot, a poster, or a manga page and get the visible text back - translated or not.
How it works
The model is fixed: google/gemma-4-E2B-it, an image-to-text vision-language model loaded through AutoModelForImageTextToText plus AutoProcessor. The node is genuinely offline-capable - there's a resolution order for where the weights come from:
local_model_dir(you can type a path on the node, which gets saved into the workflow - a real improvement over the parent pack's env-var-only approach)- the
GEMMA4_E2B_LOCAL_DIRenvironment variable - your Hugging Face cache
- a download from the Hub, dumped into
local_model_dir
If offline_mode is on and nothing local exists, it just errors instead of phoning home.
The other knob that matters is load_strategy. Default is reload_every_run, which unloads the model and clears CUDA cache after every execution - the VRAM-conscious choice. Flip to keep_loaded and it stays resident between runs, which makes batch translating a lot faster at the cost of VRAM.
The inputs that matter
source_language/target_language- pick from ~35 languages, withAuto Detectas the source default. Target defaults to English.input_text- the text to translate. If you leave it empty, you need an image.task_mode- this is the interesting one.translatefor plain text,ocr_translateto read text off an image and translate it,ocr_onlyto just extract text, andtranslate_and_explainwhich adds a short note on ambiguous bits.soft_token_budget- a budget for how much of the context window the image gets. Crank it up (560/1120) when the image has small or dense text you need OCR'd; 70 is fine for a quick caption.quantization-none,bnb-8bit, orbnb-4bit. The 4-bit option is how you squeeze the model onto a mid-range card.
Both outputs are plain strings: translated_text (wire it into a Show Text node, or into any prompt input) and info (a diagnostic string showing the repo, load path, and settings used - handy when you're debugging why a run was slow).
Installing it
ComfyUI Manager is the easy route - search for "Gemma4Translate" or the pack title comfyui-gemma4translate-e2b. Or clone it manually:
cd ComfyUI/custom_nodes
git clone https://github.com/jkmq-f/ComfyUI-Gemma4Translate-E2B
cd ComfyUI-Gemma4Translate-E2B
pip install -r requirements.txt
Then restart ComfyUI. Heads-up: the dependencies are chunky and pinned. It wants transformers==5.5.0, accelerate, sentencepiece, langcodes, and bitsandbytes (Linux + CUDA only - 8-bit/4-bit quant simply won't work on Windows). The README deliberately does not touch your Torch install, expecting the version ComfyUI bundles (2.5.x-ish). Don't go "fixing" that.
Where people get burned
- The first run downloads the model. It's a multi-GB fetch from Hugging Face, so don't panic when the queue sits there. If you're on a metered connection or repeating a run, set
offline_mode+local_model_dirto skip the HTTP check every time. - CUDA memory flakiness. The README suggests launching ComfyUI with
python main.py --disable-cuda-mallocif you hit instability around memory allocation. It's the first thing to try before blaming the node. - It re-runs every queue. The class sets
IS_CHANGEDtonan, so ComfyUI treats it as always dirty - every queue run re-translates, and withreload_every_runthat means a reload per run.keep_loadedis your friend for batch jobs. - Transformers version fights. If another custom node drags
transformerselsewhere, the README's fix ispip install --upgrade --force-reinstall "transformers==5.5.0".
Honest take: if you only translate a prompt occasionally, alt-tabbing to Google Translate is still fine and this is overkill. This node earns its keep when you translate a lot, want it private and offline, or need in-workflow OCR-translation of images - that last one is genuinely hard to do any other way without leaving ComfyUI.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| source_language | COMBO | Auto Detect | 36 options: Auto Detect, Arabic, Bulgarian, Chinese (Simplified), Chinese (Traditional), Czech, +30 |
| target_language | COMBO | English | 35 options: Arabic, Bulgarian, Chinese (Simplified), Chinese (Traditional), Czech, Danish, +29 |
| input_text | STRING | — | |
| task_mode | COMBO | translate | 4 options: translate, ocr_translate, ocr_only, translate_and_explain |
| soft_token_budget | COMBO | 280 | 5 options: 70, 140, 280, 560, 1120 |
| image_resize_mode | COMBO | fit | 3 options: fit, pad, stretch |
| image_enhance | BOOLEAN | false | — |
| max_new_tokens | INT | 5121–8192 | — |
| temperature | FLOAT | 0.200–2 | — |
| top_p | FLOAT | 0.900–1 | — |
| dtype | COMBO | auto | 4 options: auto, bfloat16, float16, float32 |
| quantization | COMBO | none | 3 options: none, bnb-8bit, bnb-4bit |
| attn_implementation | COMBO | sdpa | 2 options: sdpa, eager |
| local_model_dir | STRING | — | |
| offline_mode | BOOLEAN | false | — |
| load_strategy | COMBO | reload_every_run | 2 options: keep_loaded, reload_every_run |
| clear_loaded_model | BOOLEAN | false | — |
| imageopt | IMAGE | — | |
| system_promptopt | STRING | You are a precise multilingual translation assistant. Translate faithfully, preserve line breaks when useful, and return only the translated result unless asked otherwise. | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| translated_text | STRING | — |
| info | STRING | — |