ComfyUI Node

Gemma4 Translate

Translate Prompts (and Screenshots) Locally With Gemma 4 E2B

By jkmq-f·Created 6 months ago·Updated 6 months ago· 0
Gemma4 Translate
  • image
  • translated_text
  • info
◄source_languageAuto Detect►
◄target_languageEnglish►
◄input_text►
◄task_modetranslate►
◄soft_token_budget280►
◄image_resize_modefit►
◄image_enhancefalse►
◄max_new_tokens512►
◄temperature0.20►
◄top_p0.90►
◄dtypeauto►
◄quantizationnone►
◄attn_implementationsdpa►
◄local_model_dir►
◄offline_modefalse►
◄load_strategyreload_every_run►
◄clear_loaded_modelfalse►
◄system_promptYou are a precise multilingual translation assistant. Translate faithfully, preserve line breaks when useful, and return only the translated result unless asked otherwise.►

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:

  1. 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)
  2. the GEMMA4_E2B_LOCAL_DIR environment variable
  3. your Hugging Face cache
  4. 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, with Auto Detect as 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. translate for plain text, ocr_translate to read text off an image and translate it, ocr_only to just extract text, and translate_and_explain which 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, or bnb-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_dir to skip the HTTP check every time.
  • CUDA memory flakiness. The README suggests launching ComfyUI with python main.py --disable-cuda-malloc if 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_CHANGED to nan, so ComfyUI treats it as always dirty - every queue run re-translates, and with reload_every_run that means a reload per run. keep_loaded is your friend for batch jobs.
  • Transformers version fights. If another custom node drags transformers elsewhere, the README's fix is pip 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.

Categorylanguage

Inputs (19)

NameTypeDefaultDescription
source_languageCOMBOAuto Detect36 options: Auto Detect, Arabic, Bulgarian, Chinese (Simplified), Chinese (Traditional), Czech, +30
target_languageCOMBOEnglish35 options: Arabic, Bulgarian, Chinese (Simplified), Chinese (Traditional), Czech, Danish, +29
input_textSTRING—
task_modeCOMBOtranslate4 options: translate, ocr_translate, ocr_only, translate_and_explain
soft_token_budgetCOMBO2805 options: 70, 140, 280, 560, 1120
image_resize_modeCOMBOfit3 options: fit, pad, stretch
image_enhanceBOOLEANfalse—
max_new_tokensINT5121–8192—
temperatureFLOAT0.200–2—
top_pFLOAT0.900–1—
dtypeCOMBOauto4 options: auto, bfloat16, float16, float32
quantizationCOMBOnone3 options: none, bnb-8bit, bnb-4bit
attn_implementationCOMBOsdpa2 options: sdpa, eager
local_model_dirSTRING—
offline_modeBOOLEANfalse—
load_strategyCOMBOreload_every_run2 options: keep_loaded, reload_every_run
clear_loaded_modelBOOLEANfalse—
imageoptIMAGE—
system_promptoptSTRINGYou are a precise multilingual translation assistant. Translate faithfully, preserve line breaks when useful, and return only the translated result unless asked otherwise.—

Outputs (2)

NameTypeDescription
translated_textSTRING—
infoSTRING—