01.模型介绍

混元是腾讯开源的高效大型语言模型系列,旨在在各种计算环境中灵活部署。从边缘设备到高并发生产系统,这些模型通过先进的量化支持和超长上下文能力提供了最佳性能。
 

本次腾讯开源了一系列混元Dense模型,包括Pretrain和Instruct版本,参数规模分别为0.5B、1.8B、4B和7B,消费级显卡即可运行,适用于笔记本电脑、手机、智能座舱、智能家居等低功耗场景,且支持垂直领域低成本微调。
 

这些模型采用了与Hunyuan-A13B相似的训练策略,从而继承了其强大的性能特点。这一全面的模型家族使得从资源受限的边缘计算(使用较小参数量的模型)到高吞吐量的生产环境(使用较大参数量的模型)都能进行灵活的部署优化,同时在各种场景中保持强大的能力。
 

主要特性和优势

  • 混合推理支持:支持快速和慢速思考模式,允许用户根据需要灵活选择。
  • 超长上下文理解:原生支持256K上下文窗口,在长文本任务上保持稳定性能。
  • 增强的Agent能力:针对Agent类任务进行了优化,在BFCL-v3、τ-Bench和C3-Bench等基准测试中取得了领先的结果。
  • 高效的推理:利用GQA并支持多种量化格式,实现高效的推理。
     

02.模型链接

Hunyuan-0.5B-Pretrain:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-0.5B-Pretrain

 

Hunyuan-1.8B-Pretrain:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-1.8B-Pretrain
 

Hunyuan-4B-Pretrain:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-4B-Pretrain
 

Hunyuan-7B-Pretrain:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-7B-Pretrain
 

Hunyuan-0.5B-Instruct:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-0.5B-Instruct
 

Hunyuan-1.8B-Instruct:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-1.8B-Instruct
 

Hunyuan-4B-Instruct:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-4B-Instruct
 

Hunyuan-7B-Instruct:
 

https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-7B-Instruct

03.基准测试

注意:以下基准测试是由 TRT-LLM 后端在几个 基础模型 上评估的。

模型

Hunyuan-0.5B-Pretrain

Hunyuan-1.8B-Pretrain

Hunyuan-4B-Pretrain

Hunyuan-7B-Pretrain

MMLU

54.02

64.62

74.01

79.82

MMLU-Redux

54.72

64.42

73.53

79

MMLU-Pro

31.15

38.65

51.91

57.79

SuperGPQA

17.23

24.98

27.28

30.47

BBH

45.92

74.32

75.17

82.95

GPQA

27.76

35.81

43.52

44.07

GSM8K

55.64

77.26

87.49

88.25

MATH

42.95

62.85

72.25

74.85

EvalPlus

39.71

60.67

67.76

66.96

MultiPL-E

21.83

45.92

59.87

60.41

MBPP

43.38

66.14

76.46

76.19

CRUX-O

30.75

36.88

56.5

60.75

Chinese SimpleQA

12.51

22.31

30.53

38.86

simpleQA (5shot)

2.38

3.61

4.21

5.69

主题

基准

Hunyuan-0.5B-Instruct

Hunyuan-1.8B-Instruct

Hunyuan-4B-Instruct

Hunyuan-7B-Instruct

数学

AIME 2024

AIME 2025

MATH

17.2

20

48.5

56.7

53.9

86

78.3

66.5

92.6

81.1

75.3

93.7

科学

GPQA-Diamond

OlympiadBench

23.3

29.6

47.2

63.4

61.1

73.1

60.1

76.5

编程

Livecodebench

Fullstackbench

11.1

20.9

31.5

42

49.4

54.6

57

56.3

推理

BBH

DROP

ZebraLogic

40.3

52.8

34.5

64.6

76.7

74.6

83

78.2

83.5

87.8

85.9

85.1

指令

遵循

IF-Eval

SysBench

49.7

28.1

67.6

55.5

76.6

68

79.3

72.7

Agent

BFCL v3

τ-Bench

ComplexFuncBench

C3-Bench

49.8

14.4

13.9

45.3

58.3

18.2

22.3

54.6

67.9

30.1

26.3

64.3

70.8

35.3

29.2

68.5

上下文

PenguinScrolls

longbench-v2

FRAMES

53.9

34.7

41.9

73.1

33.2

55.6

83.1

44.1

79.2

82

43

78.6

 

04.模型推理

使用 transformers

首先,请安装 transformers。我们稍后会将其合并到主分支中。

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

 

我们的模型默认使用慢思考推理,有两种方法可以禁用 CoT 推理。

  1. 调用 apply_chat_template 时传递 "enable_thinking=False"。
  2. 在提示前添加 "/no_think" 将强制模型不进行 CoT 推理。类似地,在提示前添加 "/think" 将强制模型进行 CoT 推理。


 

以下代码片段展示了如何使用 transformers 库来加载和应用模型。它还演示了如何启用和禁用推理模式,以及如何解析推理过程及其最终输出。

我们以 tencent/Hunyuan-7B-Instruct 为例

from modelscope import AutoModelForCausalLM, AutoTokenizer
import os
import re
model_name_or_path = "Tencent-Hunyuan/Hunyuan-7B-Instruct"
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": "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",
                                                enable_thinking=True # Toggle thinking mode (default: True)
                                                )
outputs = model.generate(tokenized_chat.to(model.device), max_new_tokens=2048)
output_text = tokenizer.decode(outputs[0])
print("output_text=",output_text)
think_pattern = r'<think>(.*?)</think>'
think_matches = re.findall(think_pattern, output_text, re.DOTALL)
answer_pattern = r'<answer>(.*?)</answer>'
answer_matches = re.findall(answer_pattern, output_text, re.DOTALL)
think_content = [match.strip() for match in think_matches][0]
answer_content = [match.strip() for match in answer_matches][0]
print(f"thinking_content:{think_content}\n\n")
print(f"answer_content:{answer_content}\n\n")

 

我们建议使用以下一组参数进行推理。请注意,我们的模型没有默认的系统提示。


{
  "do_sample": true,
  "top_k": 20,
  "top_p": 0.8,
  "repetition_penalty": 1.05,
  "temperature": 0.7
}

 

05.模型微调

我们介绍使用ms-swift对Hunyuan-7B-Instruct进行训练。ms-swift是魔搭社区官方提供的大模型与多模态大模型训练部署框架。
 

ms-swift开源地址:

https://github.com/modelscope/ms-swift
 

我们将展示可运行的微调demo,并给出自定义数据集的格式。

在开始微调之前,请确保您的环境已准备妥当。

# pip install git+https://github.com/modelscope/ms-swift.git
git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .
pip install git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca

自定义数据格式

 

如果您需要微调 Instruct 模型,我们建议将数据准备成以下格式。

慢思考:

{"messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "1+1=" },
    {"role": "assistant", "content": "<think>\n嗯,用户问的是1加1等于多少。首先,我需要确认这是一个基本的算术问题。1加1在十进制的数学体系中,通常的结果是2。不过,可能需要考虑是否有其他情况,比如二进制或者其他数制,但用户没有特别说明,所以默认应该是十进制。另外,有时候可能会有脑筋急转弯的情况,比如在某些语境下1+1可能等于1(比如1滴水加1滴水还是1滴水),但通常数学问题中都是2。所以最准确的回答应该是2。</think>\n<answer>\n在十进制的基本算术运算中,1加1的结果是2。这是数学中最基础的加法运算之一,遵循自然数的加法规则。因此,1 + 1 = 2。\n</answer>"}
]}

快思考:

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

训练脚本:

# 显存占用:4 * 68GiB
# 你可以设置`--dataset swift/Chinese-Qwen3-235B-2507-Distill-data-110k-SFT`跑通代码
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
NPROC_PER_NODE=4 \
CUDA_VISIBLE_DEVICES=0,1,2,3 \
swift sft \
    --model Tencent-Hunyuan/Hunyuan-7B-Instruct \
    --train_type full \
    --dataset '<your-dataset>' \
    --attn_impl flash_attention_2 \
    --num_train_epochs 3 \
    --split_dataset_ratio 0.01 \
    --torch_dtype bfloat16 \
    --per_device_train_batch_size 1 \
    --per_device_eval_batch_size 1 \
    --learning_rate 1e-5 \
    --gradient_accumulation_steps 1 \
    --packing true \
    --eval_steps 200 \
    --save_steps 200 \
    --logging_steps 5 \
    --max_length 16384 \
    --warmup_ratio 0.05 \
    --dataloader_num_workers 8 \
    --dataset_num_proc 8 \
    --save_total_limit 2 \
    --save_only_model true \
    --output_dir output/Hunyuan-7B-Instruct \
    --deepspeed zero3 \
    --use_liger_kernel true

训练完成后,使用以下命令进行推理:

CUDA_VISIBLE_DEVICES=0 \
swift infer \
    --model output/vx-xxx/checkpoint-xxx \
    --stream true \
    --max_new_tokens 2048

推送模型到ModelScope:

swift export \
    --model output/vx-xxx/checkpoint-xxx \
    --push_to_hub true \
    --hub_model_id '<your-model-id>' \
    --hub_token '<your-sdk-token>'

点击链接,即可跳转模型合集~

https://modelscope.cn/organization/Tencent-Hunyuan?tab=model

Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐