探索 360 智脑3:人工智能新时代的领航者

在这里插入图片描述

在科技飞速发展的今天,人工智能(AI)已成为推动各行业变革的核心力量。其中,大语言模型作为 AI 领域的关键突破,正深刻改变着人们与机器交互、获取信息以及解决问题的方式。360 智脑,作为奇虎 360 公司精心打造的大型语言模型,凭借其卓越的性能、丰富的功能和广泛的应用场景,在众多同类产品中脱颖而出,成为人工智能领域的一颗璀璨明星。

介绍

🎉🎉🎉 近日,360集团开源并升级了其自研的7B参数模型360智脑3-7B。目前该模型已在Github开源社区360zhinao3上线,可免费商用。该模型能力全面提升,相比10B以下小参数模型,360智脑3-7B在多个基准测试中取得了第一名的优异表现。

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

我们360Zhinao3模型的显著特点是:

360Zhinao3-7B是在360Zhinao2-7B的基础上,使用7000亿高质量token进行持续预训练的。这两个模型的结构完全相同。模型性能的提升主要源于训练数据质量的提高。

下载链接

尺寸模型BF16
7B360Zhinao3-7B🤗
7B360Zhinao3-7B-Instruct🤗
7B360Zhinao3-7B-O1.5🤗

模型评估

基础模型

我们使用开源工具 OpenCompass 对模型进行了多维度的评估。该模型的基准平均得分在参数少于 100 亿的模型中排名第一。在同规模模型中具有竞争力。

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
KnowledgeBoolQen81.883.8889.5184.4685.682.288.2988.38
commonsense_qaen71.1773.2268.5571.5868.4771.2569.7871.33
UnderstandingC3zh91.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
Reasoninghellaswagen70.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
Codehumanevalen69.517560.3726.225.4927.4460.9864.63
mbppen606043.656.851.242.65467.80
Mathmathen26.863827.1427.0628.5215.3238.3437.60
gsm8ken78.5479.7652.5471.1173.0956.2575.5178.77
Overallavg_zh70.3571.5871.3568.3951.1357.6271.7474.20
avg_all73.1171.7869.6068.8861.6062.3270.6174.83

指导模型

我们已经在三个流行的评估中对360Zhinao3-7B-Instruct模型进行了评估和比较:IFEval、MT-bench和CF-Bench。MT-bench和CFBench在同级别的开源模型中均排名第一,具有很强的竞争力。在IFEval(严格提示)中,它仅次于glm4-9b,并且在7B尺寸中得分最高。

ModelMT-benchIFEval(strict prompt)CFBench(CSR,ISR,PSR)
Qwen2.5-7B-Instruct8.070.5560.810.460.57
Yi-9B-16k-Chat7.440.4550.750.40.52
GLM4-9B-Chat8.080.6340.820.480.61
InternLM2.5-7B-Chat7.390.5400.780.40.54
360Zhinao2-7B-Chat-4k7.860.5770.80.440.57
360Zhinao3-7B-Instruct8.170.6260.830.520.64

长链思维模型

我们使用了之前开源的Light-R1方法对360智脑3-7B-Instruct的长链思维模型进行了继续微调,同时也对RFT和GRPO进行了优化。虽然与最新的OpenThinker2-7B相比仍有一定差距,但它在基于通用Qwen2.5-7B-Instruct的所有先前模型上表现更优。

ModelDateBase ModelAIME24AIME25GPQA Diamond
OpenThinker2-7B25.4.3Qwen2.5-7B-Instruct5033.349.3
OpenThinker-7B25.1.28Qwen2.5-7B-Instruct31.323.342.4
360Zhinao3-7B-O1.525.4.14360Zhinao3-7B-Instruct54.236.340.0
OpenR1-Qwen-7B25.2.11Qwen2.5-Math-7B-Instruct48.734.721.2
DeepSeek-R1-Distill-Qwen-7B25.1.20Qwen2.5-Math-7B-Instruct57.333.347.3
Light-R1-7B-DS25.3.12DeepSeek-R1-Distill-Qwen-7B59.144.349.4
Areal-boba-RL-7B25.3.31DeepSeek-R1-Distill-Qwen-7B61.948.347.6

快速入门

一个简单的示例,展示如何快速使用360Zhinao3-7B、360Zhinao3-7B-Instruct和360Zhinao3-7B-O1.5与🤗Transformers

🤗 Transformers

基础模型推理演示

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))

指令模型推理演示

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 复制到你的 vLLM 安装目录(在 python/conda 环境中)的 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,而不是 repetition_penalty


模型微调

训练数据

训练数据:data/training_data_sample.json。此示例数据从multiturn_chat_0.8M中抽取了10,000行,并进行了格式转换。

数据格式:

[
  {
    "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 # Whether to concatenate to maximum length (MAX_LEN)

DATA_PATH="./data/training_data_sample.json"
MODEL_PATH="qihoo360/360Zhinao3-7B-Instruct"
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 在 zero1、zero2 和 zero3 之间切换。
  • fp16, bf16 可以配置混合精度训练。建议 bf16 与预训练模型保持一致。
  • is_concat 配置训练数据是否进行拼接。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值