Nodes/comfyui-tencent-hymt2/Hy-MT2 Translation (Tencent)
ComfyUI Node

Hy-MT2 Translation (Tencent)

Tencent's Hy-MT2 in ComfyUI, No API Key Needed

By mamorett·Created 4 months ago·Updated 4 months ago· 0
Hy-MT2 Translation (Tencent)
    • translated_text
    text
    modeltencent/Hy-MT2-1.8B
    instructionTranslate the following text into Chinese:
    max_tokens4096
    temperature0.70
    top_p0.60
    top_k20
    repetition_penalty1.05

    Here's the situation where this node earns its keep: you've got a Chinese or Japanese diffusion model whose text encoder basically speaks one language, and your carefully written English prompt comes out garbled. Or you're captioning a LoRA training set in another language, or you need translated subtitles for a video workflow. The obvious answer is to paste everything into a web translator - but this node puts a real translation model inside the graph, so your text never leaves the machine.

    Hy-MT2 Translation (Tencent) wraps Tencent's Hy-MT2 family of instruction-tuned translation LLMs - a real, current model line (the 1.8B release made the rounds in the May 2026 local-AI news roundups) covering 33 languages. It runs fully locally. No API, no key, no account, no "you've hit your free limit." Once the weights are downloaded you could yank the network cable and it keeps working.

    How it works

    Under the hood it's a compact but complete LLM pipeline, not a toy. The node takes your text, prepends an instruction ("Translate the following text into Chinese:" by default), wraps the pair in a chat template, and runs it through model.generate(). The output is whatever the model wrote after the prompt tokens, whitespace-stripped.

    The clever part is model storage. Most LLM nodes silently fill up ~/.cache/huggingface and forget about it. This one overrides HF_HOME, downloads each model once into ComfyUI/models/hy-mt2/<ModelName>/, and saves a clean snapshot there. After that it loads with local_files_only=True - no network, no HF cache pollution. Loaded models also cache in-process, so switching workflows mid-session is instant.

    The inputs that matter

    Two required, and honestly you'll fiddle with mostly one of them:

    • text - the source text. Multiline, any length that fits the context window.
    • model - pick tencent/Hy-MT2-1.8B, tencent/Hy-MT2-7B, or tencent/Hy-MT2-7B-FP8. Defaults to the 1.8B.

    Everything else is optional and has sane defaults inherited from Tencent's model card (temperature 0.7, top_p 0.6, top_k 20, repetition_penalty 1.05, max_tokens 4096). The one you will change is instruction - that's how you pick the target language. It's free-form, so you can get fancy: "Translate into formal English, preserving technical terms" works, and the model is instruction-tuned enough to actually follow it. Since instruction is a plain STRING input, you can even drive it from a dropdown node to make language a workflow parameter.

    The single output, translated_text (STRING), wires straight into any Show Text / Display Any node, a text file saver, or - the pattern that actually motivated this pack - back into a CLIP text encoder for a foreign diffusion model.

    Installation

    Install via ComfyUI Manager (search "Hy-MT2 Translation" or the pack title comfyui-tencent-hymt2), or clone it yourself:

    cd ComfyUI/custom_nodes
    git clone https://github.com/mamorett/comfyui-tencent-hymt2
    

    Then restart ComfyUI and install the Python deps it imports but doesn't ship - there's no requirements.txt, so this one's on you:

    pip install transformers accelerate sentencepiece
    

    On the Windows portable build, use .\python_embeded\python.exe -m pip install ... instead.

    Sizing and VRAM

    The first run downloads the model automatically, and that's where people get surprised:

    • 1.8B - ~3.6 GB download, ~4 GB VRAM, fits alongside a diffusion model on a 24 GB card
    • 7B - ~14 GB download, ~15 GB VRAM in bf16. This is the quality pick if your card can breathe.
    • 7B-FP8 - ~7 GB download, ~8 GB VRAM, but requires an RTX 40-series or H100/H200 for native FP8. On older cards it'll choke or crawl - use the plain 7B instead.

    device_map="auto" means it spills to CPU RAM rather than hard-crash, but that's slow. Honest recommendation: start with the 1.8B, and only pay the VRAM for the 7B if translation quality underwhelms.

    Common issues

    • ModuleNotFoundError: No module named 'transformers' - the classic; install the deps above into ComfyUI's Python environment.
    • CUDA out of memory - you're sharing the card with a diffusion model. Drop to the 1.8B, or run translation as a separate pass.
    • Empty output - the node deliberately returns "" for empty/whitespace-only input, and a mid-generation OOM can truncate to nothing. Give it real text and check the console.
    • A trust_remote_code warning - expected. Hy-MT2's tokeniser/config load custom code from the repo; the node passes the flag for you. Informational, ignore it.
    • Downloads to the wrong place - the HF_HOME override only works if it's set before any library imports transformers first. If another extension beat it to the punch, set HF_HOME yourself before launching ComfyUI.

    One caveat: this pack is young (a single-fix commit history) and barely community-tested - you're the beta test. The README even ships a placeholder clone URL, so ignore that and use the one above. Fine for a utility job like this; the standard custom-node caution still applies - read what you install.

    Categorytext/translation

    Inputs (8)

    NameTypeDefaultDescription
    textSTRINGThe text to translate.
    modelCOMBOtencent/Hy-MT2-1.8BWhich Hy-MT2 model variant to use.
    instructionoptSTRINGTranslate the following text into Chinese:Task instruction prepended to the source text. Change this to target a different language.
    max_tokensoptINT409664–8192Maximum number of new tokens to generate.
    temperatureoptFLOAT0.700–2Sampling temperature. 0 = greedy/deterministic.
    top_poptFLOAT0.600–1Nucleus sampling probability mass.
    top_koptINT200–200Top-K sampling. 0 disables top-k filtering.
    repetition_penaltyoptFLOAT1.051–2Penalty for repeating tokens. 1.0 = no penalty.

    Outputs (1)

    NameTypeDescription
    translated_textSTRING