模型介绍

混元翻译模型,包含一个翻译模型Hunyuan-MT-7B和一个集成模型Hunyuan-MT-Chimera。翻译模型用于将待翻译的文本翻译成目标语言,集成模型用于将翻译模型的多个翻译结果集成为一个更好的翻译。重点支持33种语言互译,支持5种民汉语言。

相关服务:菲律宾服务器租用

核心特性与优势

  • WMT25参赛者31种语种获得30种获得第一名的成绩。
  • Hunyuan-MT-7B同尺寸市场效果最优化
  • Hunyuan-MT-Chimera-7B是业务首个开源翻译集成模型,可以将翻译效果再拉高一个档次
  • 提出了一个完整的翻译模型训练范式,从Pretrain->CPT->SFT->翻译强化->集成强化,翻译效果达到同尺寸SOTA。

新闻

  • 2025.9.1我们在抱脸开源了Hunyuan-MT-7B , Hunyuan-MT-Chimera-7B。

效果

更多的实验效果和分析可以参考我们的技术报告Technical Report

模型链接

型号名称描述下载
混元-MT-7B混元7B翻译模型🤗模型
混元-MT-7B-fp8混元7B翻译模型,fp8量化🤗模型
浑源-MT-奇美拉混元7B翻译集成模型🤗模型
混元-MT-奇美拉-fp8混元7B翻译集成模型,fp8量化🤗模型

提示

ZH<=>XX 翻译的提示模板。


<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>把下面的文本翻译成<target_language>,不要额外解释。

<source_text>
</code></span></span></span></span>

XX<=>XX 翻译的提示模板,不包括 ZH<=>XX。


<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>Translate the following segment into <target_language>, without additional explanation.

<source_text>
</code></span></span></span></span>

混元-MT-Chmeria-7B提示模板


<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>Analyze the following multiple <target_language> translations of the <source_language> segment surrounded in triple backticks and generate a single refined <target_language> translation. Only output the refined translation, do not explain.

The <source_language> segment:
```<source_text>```

The multiple <target_language> translations:
1. ```<translated_text1>```
2. ```<translated_text2>```
3. ```<translated_text3>```
4. ```<translated_text4>```
5. ```<translated_text5>```
6. ```<translated_text6>```
</code></span></span></span></span>

使用变形金刚推理

首先,需要安装最新版本的变压器,推荐v4.56.0

pip install transformers==4.56.0

!!! 如果要使用 transforms 加载 fp8 模型,则需要将 config.json 中的名称“ignored_layers”更改为“ignore”,并将 compression-tensors 升级到 compression-tensors-0.11.0。

以下代码片段展示了如何使用变形金刚库加载和使用模型。

from transformers import AutoModelForCausalLM, AutoTokenizer
import os

model_name_or_path = "tencent/Hunyuan-MT-7B"

tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map="auto")  # You may want to use bfloat16 and/or move to GPU here
messages = [
    {"role": "user", "content": "Translate the following segment into Chinese, without additional explanation.\n\nGet something off your chest"},
]
tokenized_chat = tokenizer.apply_chat_template(
    messages,
    tokenize=True
    add_generation_prompt=False,
    return_tensors="pt"
)

outputs = model.generate(tokenized_chat.to(model.device), max_new_tokens=2048)
output_text = tokenizer.decode(outputs[0])

我们推荐使用下面这组参数进行推理。注意,我们的模型没有默认 system_prompt。

{
  "top_k": 20,
  "top_p": 0.6,
  "repetition_penalty": 1.05,
  "temperature": 0.7
}

支持的语种:

语言缩写中文名字
中国人zh中文
英语英文英语
法语法语法语
葡萄牙语点葡萄牙语
西班牙语es西班牙语
日本人啊拉丁
土耳其tr土耳其语
俄语汝彼
阿拉伯应收账阿拉伯语
韩国人ko韩语
泰国日泰语
意大利语它系统
德语德德国
越南语六越南语
马来语多发性硬化症马来语
印度尼西亚ID对话语
菲律宾语tl运动语
印地语你好印地语
繁体中文zh-Hant繁体中文
抛光pl波兰语
捷克语CS捷克语
荷兰语荷兰荷兰语
高棉语公里高棉语
缅甸语我的英语
波斯语法波斯语
古吉拉特语顾古吉拉特语
乌尔都语你的乌尔都语
泰卢固语特泰卢固语
马拉地语先生马拉地语
希伯来语他希伯来语
孟加拉国民军孟加拉语
泰米尔语塔泰米尔语
乌克兰英国乌克兰语
藏博藏语
哈萨克斯坦千哈萨克语
蒙锰蒙古语
维吾尔族呃维吾尔语
广东话悦粤语

训练数据格式处理

如果需要模拟我们的模型,建议将数据处理成以下格式。

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "海水为什么是咸的" },
    {"role": "assistant", "content": "海水是咸的主要是因为其中含有许多溶解在水中的盐类和矿物质。这些盐类和矿物质来自于地球表面的岩石和土壤中的化学物质,随着时间的推移,它们被带到了海洋中。当海水蒸发时,水分蒸发掉了,但盐类和矿物质仍然留在水中,导致海水变得更加咸味。因此,海水的咸度是由其中的盐类和矿物质的含量决定的。"}
]

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("your_tokenizer_path", trust_remote_code=True)
train_ids = tokenizer.apply_chat_template(messages)

使用 LLaMA-Factory 训练

我们将介绍如何使用LLaMA-Factory来进行参数混元模型。

安装环境

开始之前,确保您已经安装了以下代码库:

  1. 使用LLaMA-Factory官方指导进行安装。
  2. 使用DeepSpeed官方指导进行安装(任选)。
  3. 安装配套的变压器库。当前混元提交的变压器正在评审中,需要获取代码的分支。
<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>pip install git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca
</code></span></span></span></span>

准备数据

我们需要准备自定义的数据集:

  1. 输入您的数据以json格式进行组织,将数据放入LLaMA-Factory的data目录中。当前使用的是sharegpt格式的数据集,需要遵循以下格式:
<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>[
  {
    "messages": [
      {
        "role": "system",
        "content": "系统提示词(选填)"
      },
      {
        "role": "user",
        "content": "人类指令"
      },
      {
        "role": "assistant",
        "content": "模型回答"
      }
    ]
  }
]
</code></span></span></span></span>

可以参考前面章节中对数据格式的说明。

  1. 在data/dataset_info.json文件中提供您的数据集定义,并采用以下格式:
<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "columns": {
    "messages": "messages"
  },
  "tags": {
    "role_tag": "role",
    "content_tag": "content",
    "user_tag": "user",
    "assistant_tag": "assistant",
    "system_tag": "system"
  }
}
</code></span></span></span></span>

训练

  1. 将llama_factory_support/example_configs目录下的文件都拷贝到LLaMA-Factory目录example/hunyuan下。
  2. 修改配置文件hunyuan_full.yaml中的模型路径和数据集名称,其他的配置请根据需要进行修改。
<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>### model
model_name_or_path: [!!!add the model path here!!!]

### dataset
dataset: [!!!add the data set name here!!!]
</code></span></span></span></span>
  1. 执行训练命令
    • 运行单机训练请注意这里需要设置DISABLE_VERSION_CHECK环境变量,避免版本冲突。
    <span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>export DISABLE_VERSION_CHECK=1
    llamafactory-cli train examples/hunyuan/hunyuan_full.yaml
    </code></span></span></span>
    • 运行多机训练在每个节点上执行以下命令。请注意将torchrun需要的NNODES、NODE_RANK、MASTER_ADDR和MASTER_PORT按照您运行的环境进行配置。
    <span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>export DISABLE_VERSION_CHECK=1
    FORCE_TORCHRUN=1 NNODES=${NNODES} NODE_RANK=${NODE_RANK} MASTER_ADDR=${MASTER_ADDR} MASTER_PORT=${MASTER_PORT} \
    llamafactory-cli train examples/hunyuan_full.yaml
    </code></span></span></span>

推理与运用

HunyuanLLM可以采用TensorRT-LLM、vLLM或sglang部署。为了简化部署过程HunyuanLLM提供了预构建docker镜像,请参阅一下章节。

镜像:https://hub.docker.com/r/hunyuaninfer/hunyuan-7b/tags

使用TensorRT-LLM推理

Docker:

为了简化部署过程,HunyuanLLM提供了预构建docker镜像(注意:镜像要求Host的Cuda版本为12.8以上):

hunyuaninfer/hunyuan-7b:hunyuan-7b-trtllm。您只需要下载模型文件并用下面代码启动docker即可开始推理模型。

# 拉取
国内:
docker pull docker.cnb.cool/tencent/hunyuan/hunyuan-7b:hunyuan-7b-trtllm
国外:
docker pull hunyuaninfer/hunyuan-7b:hunyuan-7b-trtllm

# 启动
docker run --privileged --user root --name hunyuanLLM_infer --rm -it --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --gpus=all hunyuaninfer/hunyuan-7b:hunyuan-7b-trtllm

注:Docker容器权限管理。以上代码采用特权模式(--privileged)启动Docker非容器会赋予容器相关的权限,增加数据泄露和集群安全风险。建议在必要情况下避免使用特权模式,以降低安全威胁。对于必须使用特权模式的场景,应进行严格的安全监控、队列评估。

BF16部署

Step1:执行推理
方式一:命令行推理

下面我们展示一个代码片段,采用TensorRT-LLM快速请求聊天模型: 修改examples/pytorch/quickstart_advanced.py 中如下代码:

def setup_llm(args):
    kv_cache_config = KvCacheConfig(
        enable_block_reuse=not args.disable_kv_cache_reuse,
        free_gpu_memory_fraction=args.kv_cache_fraction,
    )
    spec_config = None

    hf_ckpt_path="$your_hunyuan_model_path"
    tokenizer = AutoTokenizer.from_pretrained(hf_ckpt_path, trust_remote_code=True)
    llm = LLM(
        tokenizer=tokenizer,
        model=args.model_dir,
        backend='pytorch',
        disable_overlap_scheduler=args.disable_overlap_scheduler,
        kv_cache_dtype=args.kv_cache_dtype,
        kv_cache_config=kv_cache_config,
        attn_backend=args.attention_backend,
        use_cuda_graph=args.use_cuda_graph,
        cuda_graph_padding_enabled=args.cuda_graph_padding_enabled,
        cuda_graph_batch_sizes=args.cuda_graph_batch_sizes,
        load_format=args.load_format,
        print_iter_log=args.print_iter_log,
        enable_iter_perf_stats=args.print_iter_log,
        torch_compile_config=TorchCompileConfig(
            enable_fullgraph=args.use_torch_compile,
            enable_inductor=args.use_torch_compile,
            enable_piecewise_cuda_graph= \
                args.use_piecewise_cuda_graph)
        if args.use_torch_compile else None,
        moe_backend=args.moe_backend,
        enable_trtllm_sampler=args.enable_trtllm_sampler,
        max_seq_len=args.max_seq_len,
        max_batch_size=args.max_batch_size,
        max_num_tokens=args.max_num_tokens,
        enable_attention_dp=args.enable_attention_dp,
        tensor_parallel_size=args.tp_size,
        pipeline_parallel_size=args.pp_size,
        moe_expert_parallel_size=args.moe_ep_size,
        moe_tensor_parallel_size=args.moe_tp_size,
        moe_cluster_parallel_size=args.moe_cluster_size,
        enable_chunked_prefill=args.enable_chunked_prefill,
        speculative_config=spec_config,
        trust_remote_code=args.trust_remote_code,
        gather_generation_logits=args.return_generation_logits)

    sampling_params = SamplingParams(
        end_id=127960,
        max_tokens=args.max_tokens,
        temperature=args.temperature,
        top_k=args.top_k,
        top_p=args.top_p,
        return_context_logits=args.return_context_logits,
        return_generation_logits=args.return_generation_logits,
        logprobs=args.logprobs)
    return llm, sampling_params


def main():
    args = parse_arguments()
    prompts = args.prompt if args.prompt else example_prompts

    llm, sampling_params = setup_llm(args)
    new_prompts = []
    for prompt in prompts:
        messages = [{"role": "user", "content": f"{prompt}"}]
        new_prompts.append(
            llm.tokenizer.apply_chat_template(messages,
                                                tokenize=False,
                                                add_generation_prompt=True))
    prompts = new_prompts
    outputs = llm.generate(prompts, sampling_params)

    for i, output in enumerate(outputs):
        prompt = output.prompt
        generated_text = output.outputs[0].text
        print(f"[{i}] Prompt: {prompt!r}, Generated text: {generated_text!r}")

运行方式:

python3 quickstart_advanced.py --model_dir "HunyuanLLM模型路径" --tp_size 1
方式2:服务化推理

下面我们展示使用TensorRT-LLM服务化的部署方式模型和请求。

以tencent/Hunyuan-7B-Instruct为例准备配置文件:

<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>cat >/path/to/extra-llm-api-config.yml <<EOF
use_cuda_graph: true
cuda_graph_padding_enabled: true
cuda_graph_batch_sizes:
- 1
- 2
- 4
- 8
- 16
- 32
print_iter_log: true
EOF
</code></span></span></span></span>

启动服务:

trtllm-serve \
  /path/to/HunYuan-7b \
  --host localhost \
  --port 8000 \
  --backend pytorch \
  --max_batch_size 32 \
  --max_num_tokens 16384 \
  --tp_size 1 \
  --kv_cache_free_gpu_memory_fraction 0.6 \
  --trust_remote_code \
  --extra_llm_api_options /path/to/extra-llm-api-config.yml

服务启动成功后,使用OpenAI API进行模型推理调用:

<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>curl -X POST "http://localhost:8000/v1/chat/completions" \
  -H "Content-Type: application/json" \
  --data '{
    "model": "HunYuan/HunYuan-7b",
    "messages": [
      {
        "role": "user",
        "content": "Write a short summary of the benefits of regular exercise"
      }
    ]
  }'
</code></span></span></span></span>
FP8/Int4量化模型部署:

目前TensorRT-LLM的fp8和int4量化模型正在支持中,期待。

使用vLLM推理

版本要求:

请使用vLLM v0.10.0之后的版本进行部署和推理

需要安装指定版本的变压器,我们将在不久后完成对变压器主分支的合入

pip install git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca

BF16部署

以tencent/Hunyuan-7B-为例,已经通过上述的变形金刚获取了模型地址

export MODEL_PATH=PATH_TO_MODEL
Step1:执行推理
方式一:命令行推理

下面我们展示一个代码片段,采用vLLM快速请求聊天模型:

注:vLLM组件远程代码执行防护。以下代码中vLLM的组件远程代码配置项若被启用,将允许加载并执行来自远程模型仓库的代码,这可能会导致恶意代码的执行。除非业务需求明确要求,否则建议该配置项取消状态,以降低潜在的安全威胁。

import os
from typing import List, Optional
from vllm import LLM, SamplingParams
from vllm.inputs import PromptType
from transformers import AutoTokenizer

model_path=os.environ.get('MODEL_PATH')
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

llm = LLM(model=model_path,
        tokenizer=model_path,
        trust_remote_code=True,
        dtype='bfloat16',
        tensor_parallel_size=4,
        gpu_memory_utilization=0.9)

sampling_params = SamplingParams(
    temperature=0.7, top_p=0.8, max_tokens=4096, top_k=20, repetition_penalty=1.05)

messages = [
    {
        "role": "system",
        "content": "You are a helpful assistant.",
    },
    {"role": "user", "content": "Write a short summary of the benefits of regular exercise"},
]

tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")

dummy_inputs: List[PromptType] = [{
    "prompt_token_ids": batch
} for batch in tokenized_chat.numpy().tolist()]

outputs = llm.generate(dummy_inputs, sampling_params)

# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
方式2:服务化推理

下面我们展示使用vLLM服务化的部署方式模型并请求

我们启动服务,运行:

python3 -m vllm.entrypoints.openai.api_server \
    --host 0.0.0.0 \
    --port 8000 \
    --trust-remote-code \
    --model ${MODEL_PATH} \
    --tensor-parallel-size 1 \
    --dtype bfloat16 \
    --quantization experts_int8 \
    --served-model-name hunyuan \
    2>&1 | tee log_server.txt

运行成功后,运行脚本脚本:

curl http://0.0.0.0:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "hunyuan",
"messages": [
    {
        "role": "system",
        "content": [{"type": "text", "text": "You are a helpful assistant."}]
    },
    {
        "role": "user",
        "content": [{"type": "text", "text": "请按面积大小对四大洋进行排序,并给出面积最小的洋是哪一个?直接输出结果。"}]
    }
],
"max_tokens": 2048,
"temperature":0.7,
"top_p": 0.6,
"top_k": 20,
"repetition_penalty": 1.05,
"stop_token_ids": [127960]
}'

量化模型部署:

本部分介绍采用vLLM部署量化后模型的流程。

Int8量化模型部署:

配置Int8-weight-only版本HunYuan-7B模型

我们启动Int8服务,运行:

python3 -m vllm.entrypoints.openai.api_server \
    --host 0.0.0.0 \
    --port 8000 \
    --trust-remote-code \
    --model ${MODEL_PATH} \
    --tensor-parallel-size 1 \
    --dtype bfloat16 \
    --served-model-name hunyuan \
    --quantization experts_int8 \
    2>&1 | tee log_server.txt
Int4模型部署:

配置Int4-weight-only版本HunYuan-7B模型,采用GPTQ方式:

export MODEL_PATH=PATH_TO_INT4_MODEL

接下来我们启动Int4服务,运行:

python3 -m vllm.entrypoints.openai.api_server \
    --host 0.0.0.0 \
    --port 8000 \
    --trust-remote-code \
    --model ${MODEL_PATH} \
    --tensor-parallel-size 1 \
    --dtype bfloat16 \
    --served-model-name hunyuan \
    --quantization gptq_marlin \
    2>&1 | tee log_server.txt
FP8量化模型部署:

配置W8A8C8版本HunYuan-7B模型

我们启动FP8服务,运行:

python3 -m vllm.entrypoints.openai.api_server \
    --host 0.0.0.0 \
    --port 8000 \
    --trust-remote-code \
    --model ${MODEL_PATH} \
    --tensor-parallel-size 1 \
    --dtype bfloat16 \
    --served-model-name hunyuan \
    --kv-cache-dtype fp8 \
    2>&1 | tee log_server.txt

使用俚语推理

BF16部署

Step1:拉取镜像
<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>docker pull lmsysorg/sglang:latest
</code></span></span></span></span>
  • 启动API服务器:
<span style="background-color:#f6f8fa"><span style="color:#1f2328"><span style="color:#1f2328"><span style="background-color:#f6f8fa"><code>docker run --entrypoint="python3" --gpus all \
    --shm-size 32g \
    -p 30000:30000 \
    --ulimit nproc=10000 \
    --privileged \
    --ipc=host \
     lmsysorg/sglang:latest \
    -m sglang.launch_server --model-path hunyuan/huanyuan_7B --tp 1 --trust-remote-code --host 0.0.0.0 --port 30000
</code></span></span></span></span>
Step2:执行推理
方式一:命令行推理

下面我们展示一个代码片段,采用sglang快速请求聊天模型:

import sglang as sgl
from transformers import AutoTokenizer

model_path=os.environ.get('MODEL_PATH')


tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

messages = [
    {
        "role": "system",
        "content": "You are a helpful assistant.",
    },
    {"role": "user", "content": "Write a short summary of the benefits of regular exercise"},
]
prompts = []
prompts.append(tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
))
print(prompts)

llm = sgl.Engine(
    model_path=model_path,
    tp_size=1,
    trust_remote_code=True,
    mem_fraction_static=0.7,
)

sampling_params = {"temperature": 0.7, "top_p": 0.8, "top_k": 20, "max_new_tokens": 4096}
outputs = llm.generate(prompts, sampling_params)
for prompt, output in zip(prompts, outputs):
    print(f"Prompt: {prompt}\nGenerated text: {output['text']}")
方式2:服务化推理

下面我们展示使用sglang服务化的部署方式模型和请求。

model_path="HunyuanLLM模型路径"
python3 -u -m sglang.launch_server \
    --model-path $model_path \
    --tp 4 \
    --trust-remote-code

服务启动成功,运行脚本脚本后:

import openai
client = openai.Client(
    base_url="http://localhost:30000/v1", api_key="EMPTY")

response = client.chat.completions.create(
    model="default",
    messages= [
        {"role": "user", "content": "Write a short summary of the benefits of regular exercise"},
    ],
    temperature=0.7,
    max_tokens=4096,
    extra_body={"top_p": 0.8, "top_k": 20}
)
print(response)

引用浑源-MT:

@misc{hunyuanmt2025,
  title={Hunyuan-MT Technical Report},
  author={Mao Zheng, Zheng Li, Bingxin Qu, Mingyang Song, Yang Du, Mingrui Sun, Di Wang, Tao Chen, Jiaqi Zhu, Xingwu Sun, Yufei Wang, Can Xu, Chen Li, Kai Wang, Decheng Wu},
  howpublished={\url{https://github.com/Tencent-Hunyuan/Hunyuan-MT}},
  year={2025}
}

联系我们

如果您想给我们的研发和产品团队留言,欢迎联系我们腾讯混元LLM团队。您可以通过邮件([email protected])联系我们。