目录
gongxiaochun12个月前4次提交

360Zhinao3 (360智脑)

🤗 Hugging Face   |    💬 WeChat (微信)  

欢迎访问360智脑官网 https://ai.360.com 体验更多更强大的功能。


模型介绍

🎉🎉🎉近日,奇虎360开源升级了自研的7B参数模型360Zhinao3-7B,现已上线Github开源社区 360zhinao3,可免费商用。模型各项能力得到全面提升,与10B以下的小参数量模型进行对比,360Zhinao3-7B在多个benchmark上,均取得第一的优异成绩。

开源模型包括:

  • 360Zhinao3-7B
  • 360Zhinao3-7B-Instruct
  • 360Zhinao3-7B-O1.5

360Zhinao3-7B 是在 360Zhinao2-7B 的基础上继续预训练了700B的高质量token,两者模型结构完全相同。模型效果上的提升,主要源于训练数据的质量的提升。


更新信息

  • [2025.04.14] 🔥🔥🔥我们发布了360Zhinao3系列模型,同时开放 360Zhinao3-7B、360Zhinao3-7B-Instruct 以及长思维链模型 360Zhinao3-7B-O1.5。
  • [2024.11.18] 我们发布了360Zhinao2-7B,同时开放Base模型和4K、32K、360K三种文本长度的Chat模型。
  • [2024.05.23] 我们发布了360Zhinao-search以及360Zhinao-1.8B-Reranking两个模型,分别在C-MTEB 榜单的Retrieval和Reranking任务上排名第一。
  • [2024.05.20] 我们将llama3的窗口长度扩展到360k并发布了llama3-8B-360Zhinao-360k-Instruct🤗
  • [2024.04.12] 我们发布了360Zhinao-7B 1.0版本,同时开放Base模型和4K、32K、360K三种文本长度的Chat模型。 技术报告详见arXiv

目录


下载地址

本次发布版本和下载链接见下表: | Size | Model | BF16 | |:-:|-|:-:| | 7B | 360Zhinao3-7B | 🤗 | | 7B | 360Zhinao3-7B-Instruct | 🤗 | | 7B | 360Zhinao3-7B-O1.5 | 🤗 |


模型评估

基础模型效果

我们使用了开源工具opencompass对模型进行多维度评估,模型的benchmark平均分在10B以下模型中排名第一,同尺寸具备竞争力。

TypeDatasetslanguageglm4-9bQwen2.5-7Binternlm2.5-7bYi1.5-9Bgemma2-9bLlama3.1-8B360Zhinao2-7B360Zhinao3-7B
Examcevalzh75.8381.4177.7173.5156.3651.6783.0484.7
mmluen75.575.571.5571.4372.2266.7567.8475.42
cmmluzh74.2481.7978.7774.258.8952.4973.882.17
ARC-cen94.928085.0887.4677.6380.6887.1288.14
ARC-een98.4184.8395.2494.5378.8489.7792.7794
LanguageWiCen51.5752.8250.7850.6350.475049.8450.31
WSCen68.2768.2769.2366.3568.2767.3165.3871.15
Knowledge BoolQen81.883.8889.5184.4685.682.288.2988.38
commonsense_qaen71.1773.2268.5571.5868.4771.2569.7871.33
Understanding C3zh91.519293.0485.8681.6483.5193.2692.77
race-middleen91.9991.0292.0691.1688.0981.6990.4690.04
race-highen90.7187.9190.0888.3482.0878.7386.7485.96
lcstszh18.2915.8215.9616.4910.6217.2918.6118.85
eprstmt-devzh91.8886.8891.2591.8848.1283.129092.50
lambadaen71.6771.1469.9870.6475.4374.2372.5668.17
Reasoning hellaswagen70.2572.7670.3871.5566.8374.6571.4973.61
siqaen81.7372.5278.9776.258.9664.1877.1279.02
bbhen73.6854.6359.4367.8668.4559.946.5473.74
Code humanevalen69.517560.3726.225.4927.4460.9864.63
mbppen606043.656.851.242.65467.80
Math mathen26.863827.1427.0628.5215.3238.3437.60
gsm8ken78.5479.7652.5471.1173.0956.2575.5178.77
Overall avg_zh70.3571.5871.3568.3951.1357.6271.7474.20
avg_all73.1171.7869.6068.8861.6062.3270.6174.83

Instruct模型效果

我们在IFEval、MT-bench、CF-Bench三个流行的评测上对360Zhinao3-7B-Instruct模型进行了评测比较,MT-bench 和CFBench均在同级别开源模型中排名第一,具备较强竞争力。在IFEval (prompt strict) 仅次于glm4-9b,在7B尺寸上得分最高:

Model MT-bench IFEval(strict prompt) CFBench(CSR,ISR,PSR)
Qwen2.5-7B-Instruct 8.07 0.556 0.81 0.46 0.57
Yi-9B-16k-Chat 7.44 0.455 0.75 0.4 0.52
GLM4-9B-Chat 8.08 0.634 0.82 0.48 0.61
InternLM2.5-7B-Chat 7.39 0.540 0.78 0.4 0.54
360Zhinao2-7B-Chat-4k 7.86 0.577 0.8 0.44 0.57
360Zhinao3-7B-Instruct 8.17 0.626 0.83 0.52 0.64

长思维链模型效果

我们用之前智脑开源的 Light-R1 方法对360Zhinao3-7B-Instruct进行了长思维链的继续微调和RFT,GRPO。与最新的OpenThinker2-7B有一定差距,超越了之前的所有以通用Qwen2.5-7B-Instruct为基座的模型。

Model Date Base Model AIME24 AIME25 GPQA Diamond
OpenThinker2-7B 25.4.3 Qwen2.5-7B-Instruct 50 33.3 49.3
OpenThinker-7B 25.1.28 Qwen2.5-7B-Instruct 31.3 23.3 42.4
360Zhinao3-7B-O1.5 25.4.14 360Zhinao3-7B-Instruct 54.2 36.3 40.0
OpenR1-Qwen-7B 25.2.11 Qwen2.5-Math-7B-Instruct 48.7 34.7 21.2
DeepSeek-R1-Distill-Qwen-7B 25.1.20 Qwen2.5-Math-7B-Instruct 57.3 33.3 47.3
Light-R1-7B-DS 25.3.12 DeepSeek-R1-Distill-Qwen-7B 59.1 44.3 49.4
Areal-boba-RL-7B 25.3.31 DeepSeek-R1-Distill-Qwen-7B 61.9 48.3 47.6

快速开始

简单的示例来说明如何利用 🤗Transformers 快速使用 360Zhinao3-7B、360Zhinao3-7B-Instruct 以及 360Zhinao3-7B-O1.5

🤗Transformers

Base模型推理

此代码演示使用transformers快速使用360Zhinao2-7B-Base模型进行推理

from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers.generation import GenerationConfig

MODEL_NAME_OR_PATH = "qihoo360/360Zhinao3-7B"

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

model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME_OR_PATH,
    trust_remote_code=True).cuda()

generation_config = GenerationConfig.from_pretrained(
    MODEL_NAME_OR_PATH,
    trust_remote_code=True)
generation_config.max_new_tokens = 1024

inputs = tokenizer('中国二十四节气\n1. 立春\n2. 雨水\n3. 惊蛰\n4. 春分\n5. 清明\n', return_tensors='pt')
inputs = inputs.to(model.device)

pred = model.generate(input_ids=inputs["input_ids"], generation_config=generation_config)
print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))

Instruct模型推理

此代码演示使用 🤗Transformers 快速使用 360Zhinao3-7B-Instruct 模型进行推理

from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers.generation import GenerationConfig

MODEL_NAME_OR_PATH = "qihoo360/360Zhinao3-7B-Instruct"

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

model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME_OR_PATH,
    trust_remote_code=True).cuda()

generation_config = GenerationConfig.from_pretrained(
    MODEL_NAME_OR_PATH,
    trust_remote_code=True)
generation_config.max_new_tokens = 2048

messages = []

#round-1
print(f"user: 简单介绍一下刘德华")
messages.append({"role": "user", "content": "简单介绍一下刘德华"})
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
pred = model.generate(input_ids=input_ids, generation_config=generation_config)
response = tokenizer.decode(pred.cpu()[0][len(input_ids[0]):], skip_special_tokens=True)
messages.append({"role": "assistant", "content": response})
print(f"gpt: {response}")


#round-1
print(f"user: 他有什么代表作?")
messages.append({"role": "user", "content": "他有什么代表作?"})
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
pred = model.generate(input_ids=input_ids, generation_config=generation_config)
response = tokenizer.decode(pred.cpu()[0][len(input_ids[0]):], skip_special_tokens=True)
messages.append({"role": "assistant", "content": response})
print(f"gpt: {response}")

长思维链模型推理

import re
import json
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers.generation import GenerationConfig

MODEL_NAME_OR_PATH = "qihoo360/360Zhinao3-7B-O1.5"

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

model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME_OR_PATH,
    trust_remote_code=True).cuda()

generation_config = GenerationConfig.from_pretrained(
    MODEL_NAME_OR_PATH,
    trust_remote_code=True)
generation_config.max_new_tokens = 2048


def extract_thinking_and_answer(input_string):
    thinking, answer = "", ""
    # 提取答案
    pattern_answer = r'.*</think>(.*)
    match_answer = re.search(pattern_answer, input_string, re.S)
    if match_answer:
        answer = match_answer.group(1)
    else:
        return thinking, input_string

    # 提取思考过程
    pattern_thinking = r'<think>(.*?)</think>'
    match_thinking = re.search(pattern_thinking, input_string, re.S)
    if match_thinking:
        thinking = match_thinking.group(1)

    return thinking, answer


messages = []
messages.append({"role": "user", "content": "现有一笼子,里面有鸡和兔子若干只,数一数,共有头14个,腿38条,求鸡和兔子各有多少只?"})
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
pred = model.generate(input_ids=input_ids, generation_config=generation_config)
response = tokenizer.decode(pred.cpu()[0][len(input_ids[0]):], skip_special_tokens=True)
thinking, answer = extract_thinking_and_answer(response)
messages.append({"role": "assistant", "content": answer, "reasoning_content": thinking})
print(json.dumps(messages, ensure_ascii=False, indent=4))

模型推理

模型部署

vLLM安装环境

如希望部署及加速推理,我们建议你使用 vllm==0.6.0

如果你使用CUDA 12.1和PyTorch 2.1,可以直接使用以下命令安装vLLM。

pip install vllm==0.6.0

否则请参考vLLM官方的安装说明

安装完成后,还需要以下操作~

  1. 把vllm/zhinao.py文件复制到env环境对应的vllm/model_executor/models目录下。

  2. 然后在vllm/model_executor/models/__init__.py文件增加一行代码

    "ZhinaoForCausalLM": ("zhinao", "ZhinaoForCausalLM"),

vLLM服务启动

启动服务

python -m vllm.entrypoints.openai.api_server \
    --model qihoo360/360Zhinao3-7B-O1.5 \
    --served-model-name 360Zhinao3-7B-O1.5 \
    --port 8360 \
    --host 0.0.0.0 \
    --dtype bfloat16 \
    --tensor-parallel-size 4 \
    --gpu-memory-utilization 0.8 \
    --trust-remote-code

使用curl请求服务

curl http://localhost:8360/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
    "model": "360Zhinao3-7B-O1.5",
    "max_tokens": 200,
    "top_k": -1,
    "top_p": 0.8,
    "temperature": 1.0,
    "presence_penalty": 0.0,
    "frequency_penalty": 0.0,
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "你好"}
    ],
    "stop": [
        "<eod>",
        "<|im_end|>",
        "<|im_start|>"
    ]
}'

使用python请求服务

from openai import OpenAI
# Set OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8360/v1"

client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

chat_response = client.chat.completions.create(
    model="360Zhinao3-7B-O1.5",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "你好"},
    ],
    stop=[
        "<eod>",
        "<|im_end|>",
        "<|im_start|>"
    ],
    presence_penalty=0.0,
    frequency_penalty=0.0
)
print("Chat response:", chat_response)

注意:如需要开启重复惩罚,建议使用 presence_penaltyfrequency_penalty 参数。


模型微调

训练数据

我们提供了微调训练样例数据 data/test.json,该样例数据是从 multiturn_chat_0.8M 采样出 1 万条,并且做了格式转换。

数据格式:

[
  {
    "id": 1,
    "conversations": [
        {
            "from": "system",
            "value": "You are a helpful assistant."
        },
        {
            "from": "user",
            "value": "您好啊"
        },
        {
            "from": "assistant",
            "value": "你好!我今天能为您做些什么?有什么问题或需要帮助吗? 我在这里为您提供服务。"
        }
    ]
  }
]

微调训练

训练脚本如下:

set -x

HOSTFILE=hostfile
DS_CONFIG=./finetune/ds_config_zero2.json

# PARAMS
LR=5e-6
EPOCHS=3
MAX_LEN=32768
BATCH_SIZE=4
NUM_NODES=1
NUM_GPUS=8
MASTER_PORT=29500

IS_CONCAT=False # 是否数据拼接到最大长度(MAX_LEN)

DATA_PATH="./data/training_data_sample.json"
MODEL_PATH="qihoo360/360Zhinao3-7B"
OUTPUT_DIR="./outputs/"

deepspeed --hostfile ${HOSTFILE} \
        --master_port ${MASTER_PORT} \
        --num_nodes ${NUM_NODES} \
        --num_gpus ${NUM_GPUS} \
        finetune.py \
        --report_to "tensorboard" \
        --data_path ${DATA_PATH} \
        --model_name_or_path ${MODEL_PATH} \
        --output_dir ${OUTPUT_DIR} \
        --model_max_length ${MAX_LEN} \
        --num_train_epochs ${EPOCHS} \
        --per_device_train_batch_size ${BATCH_SIZE} \
        --gradient_accumulation_steps 1 \
        --save_strategy steps \
        --save_steps 200 \
        --learning_rate ${LR} \
        --lr_scheduler_type cosine \
        --adam_beta1 0.9 \
        --adam_beta2 0.95 \
        --adam_epsilon 1e-8 \
        --max_grad_norm 1.0 \
        --weight_decay 0.1 \
        --warmup_ratio 0.01 \
        --gradient_checkpointing True \
        --bf16 True \
        --tf32 True \
        --deepspeed ${DS_CONFIG} \
        --is_concat ${IS_CONCAT} \
        --logging_steps 1 \
        --log_on_each_node False
bash finetune/ds_finetune.sh
  • 可通过配置hostfile,实现单机、多机训练。
  • 可通过配置ds_config,实现zero2、zero3。
  • 可通过配置fp16、bf16实现混合精度训练,建议使用bf16,与预训练模型保持一致。
  • 可通过配置is_concat参数,控制训练数据是否拼接,当训练数据量级较大时,可通过拼接提升训练效率。

许可证

本仓库源码遵循开源许可证Apache 2.0。

360智脑开源模型支持免费商用,无需向我们进行特殊申请。

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号