HuggingFace镜像/zephyr-7b-beta-openmind
模型介绍文件和版本分析
下载使用量0
Zephyr Logo

Zephyr 7B β 模型卡片

Zephyr 是一系列旨在充当乐于助人助手的语言模型。Zephyr-7B-β 是该系列的第二款模型,它是 mistralai/Mistral-7B-v0.1 的微调版本,使用 直接偏好优化(DPO) 在混合的公开可用合成数据集上进行训练。我们发现,去除这些数据集内置的对齐机制后,模型在 MT Bench 上的性能有所提升,并且变得更加乐于助人。然而,这也意味着当被提示时,该模型可能会生成有问题的文本。更多详情可参见 技术报告。

模型描述

  • 模型类型:一个拥有 70 亿参数的类 GPT 模型,在混合的公开可用合成数据集上进行了微调。
  • 语言(NLP):主要为英语
  • 许可证:MIT
  • 微调基础模型:mistralai/Mistral-7B-v0.1

模型来源

  • 代码库:https://github.com/huggingface/alignment-handbook
  • 演示:https://huggingface.co/spaces/HuggingFaceH4/zephyr-chat
  • Chatbot Arena:在 LMSYS 竞技场中评估 Zephyr 7B 与 10 多个大型语言模型的性能:http://arena.lmsys.org

性能表现

发布时,Zephyr-7B-β 在 MT-Bench 和 AlpacaEval 基准测试中是排名最高的 70 亿参数聊天模型:

模型规模对齐方式MT-Bench(得分)AlpacaEval(胜率 %)
StableLM-Tuned-α7BdSFT2.75-
MPT-Chat7BdSFT5.42-
Xwin-LMv0.17BdPPO6.1987.83
Mistral-Instructv0.17B-6.84-
Zephyr-7b-α7BdDPO6.88-
Zephyr-7b-β 🪁7BdDPO7.3490.60
Falcon-Instruct40BdSFT5.1745.71
Guanaco65BSFT6.4171.80
Llama2-Chat70BRLHF6.8692.66
Vicuna v1.333BdSFT7.1288.99
WizardLM v1.070BdSFT7.71-
Xwin-LM v0.170BdPPO-95.57
GPT-3.5-turbo-RLHF7.9489.37
Claude 2-RLHF8.0691.36
GPT-4-RLHF8.9995.28

特别是在 MT-Bench 的多个类别中,Zephyr-7B-β 与像 Llama2-Chat-70B 这样的更大规模开源模型相比,表现出强劲的性能:

image/png

然而,在编码和数学等更复杂的任务上,Zephyr-7B-β 仍落后于专有模型,需要更多研究来缩小这一差距。

在 Openmind 中的使用

from openmind import pipeline, is_torch_npu_available
from openmind_hub import snapshot_download
import torch.nn.functional as F
from torch import Tensor
import openmind
import torch
import argparse
import time

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="jeffding/zephyr-7b-beta-openmind",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
    
    
    start_time = time.time()
    
    pipe = pipeline("text-generation", model=model_path, torch_dtype=torch.bfloat16, device_map=device)

    # We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
    messages = [
        {
            "role": "system",
            "content": "You are a friendly chatbot who always responds in the style of a pirate",
        },
        {"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
    ]
    prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
    outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
    print(outputs[0]["generated_text"])
    
    end_time = time.time()
    print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
    
if __name__ == "__main__":
    main()

预期用途和限制

该模型最初在经过筛选和预处理的UltraChat数据集上进行微调,该数据集包含由ChatGPT生成的各种合成对话。 随后,我们使用🤗 TRL的DPOTrainer在openbmb/UltraFeedback数据集上进一步对齐模型,该数据集包含64k个提示和由GPT-4排名的模型补全内容。因此,该模型可用于聊天,您可以查看我们的演示来测试其功能。

您可以在此处找到用于训练Zephyr-7B-β的数据集。

以下是如何使用🤗 Transformers中的pipeline()函数运行模型:

# Install transformers from source - only needed for versions <= v4.34
# pip install git+https://github.com/huggingface/transformers.git
# pip install accelerate

import torch
from transformers import pipeline

pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")

# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
messages = [
    {
        "role": "system",
        "content": "You are a friendly chatbot who always responds in the style of a pirate",
    },
    {"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
]
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])
# <|system|>
# You are a friendly chatbot who always responds in the style of a pirate.</s>
# <|user|>
# How many helicopters can a human eat in one sitting?</s>
# <|assistant|>
# Ah, me hearty matey! But yer question be a puzzler! A human cannot eat a helicopter in one sitting, as helicopters are not edible. They be made of metal, plastic, and other materials, not food!

偏见、风险与局限性

Zephyr-7B-β在RLHF阶段尚未针对人类安全偏好进行对齐,也未像ChatGPT那样部署响应的实时过滤机制,因此该模型可能会生成有问题的输出(尤其是在被提示的情况下)。 基础模型(mistralai/Mistral-7B-v0.1)的训练语料库规模和构成目前未知,但很可能包含网络数据以及书籍、代码等技术来源的混合内容。相关示例可参见Falcon 180B模型卡片。

训练与评估数据

在DPO训练过程中,该模型在评估集上取得了以下结果:

  • 损失(Loss):0.7496
  • 奖励/选中(Rewards/chosen):-4.5221
  • 奖励/拒绝(Rewards/rejected):-8.3184
  • 奖励/准确率(Rewards/accuracies):0.7812
  • 奖励/边际值(Rewards/margins):3.7963
  • 对数概率/拒绝(Logps/rejected):-340.1541
  • 对数概率/选中(Logps/chosen):-299.4561
  • 对数几率/拒绝(Logits/rejected):-2.3081
  • 对数几率/选中(Logits/chosen):-2.3531

训练超参数

训练过程中使用了以下超参数:

  • 学习率(learning_rate):5e-07
  • 训练批次大小(train_batch_size):2
  • 评估批次大小(eval_batch_size):4
  • 随机种子(seed):42
  • 分布式类型(distributed_type):多GPU
  • 设备数量(num_devices):16
  • 总训练批次大小(total_train_batch_size):32
  • 总评估批次大小(total_eval_batch_size):64
  • 优化器(optimizer):Adam,参数betas=(0.9,0.999),epsilon=1e-08
  • 学习率调度器类型(lr_scheduler_type):线性
  • 学习率调度器预热比例(lr_scheduler_warmup_ratio):0.1
  • 训练轮数(num_epochs):3.0

训练结果

下表展示了完整的DPO训练指标集:

训练损失(Training Loss)轮次(Epoch)步数(Step)验证损失(Validation Loss)奖励/选中(Rewards/chosen)奖励/拒绝(Rewards/rejected)奖励/准确率(Rewards/accuracies)奖励/边际值(Rewards/margins)对数概率/拒绝(Logps/rejected)对数概率/选中(Logps/chosen)对数几率/拒绝(Logits/rejected)对数几率/选中(Logits/chosen)
0.62840.051000.60980.0425-0.18720.73440.2297-258.8416-253.8099-2.7976-2.8234
0.49080.12000.5426-0.0279-0.68420.750.6563-263.8124-254.5145-2.7719-2.7960
0.52640.153000.53240.0414-0.97930.76561.0207-266.7627-253.8209-2.7892-2.8122
0.55360.214000.4957-0.0185-1.52760.79691.5091-272.2460-254.4203-2.8542-2.8764
0.53620.265000.5031-0.2630-1.59170.78121.3287-272.8869-256.8653-2.8702-2.8958
0.59660.316000.5963-0.2993-1.64910.78121.3499-273.4614-257.2279-2.8778-2.8986
0.50140.367000.5382-0.2859-1.47500.751.1891-271.7204-257.0942-2.7659-2.7869
0.53340.418000.5677-0.4289-1.89680.79691.4679-275.9378-258.5242-2.7053-2.7265
0.52510.469000.5772-0.2116-1.31070.73441.0991-270.0768-256.3507-2.8463-2.8662
0.52050.5210000.5262-0.3792-1.85850.71881.4793-275.5552-258.0276-2.7893-2.7979
0.50940.5711000.5433-0.6279-1.93680.79691.3089-276.3377-260.5136-2.7453-2.7536
0.58370.6212000.5349-0.3780-1.95840.76561.5804-276.5542-258.0154-2.7643-2.7756
0.52140.6713000.5732-1.0055-2.23060.76561.2251-279.2761-264.2903-2.6986-2.7113
0.69140.7214000.5137-0.6912-2.17750.79691.4863-278.7448-261.1467-2.7166-2.7275
0.46550.7715000.5090-0.7987-2.29300.70311.4943-279.8999-262.2220-2.6651-2.6838
0.57310.8316000.5312-0.8253-2.35200.78121.5268-280.4902-262.4876-2.6543-2.6728
0.52330.8817000.5206-0.4573-2.09510.78121.6377-277.9205-258.8084-2.6870-2.7097
0.55930.9318000.5231-0.5508-2.20000.79691.6492-278.9703-259.7433-2.6221-2.6519
0.49670.9819000.5290-0.5340-1.95700.82811.4230-276.5395-259.5749-2.6564-2.6878
0.09211.0320000.5368-1.1376-3.16150.78122.0239-288.5854-265.6111-2.6040-2.6345
0.07331.0821000.5453-1.1045-3.44510.76562.3406-291.4208-265.2799-2.6289-2.6595
0.09721.1422000.5571-1.6915-3.98230.81252.2908-296.7934-271.1505-2.6471-2.6709
0.10581.1923000.5789-1.0621-3.89410.79692.8319-295.9106-264.8563-2.5527-2.5798
0.24231.2424000.5455-1.1963-3.55900.78122.3627-292.5599-266.1981-2.5414-2.5784
0.11771.2925000.5889-1.8141-4.39420.79692.5801-300.9120-272.3761-2.4802-2.5189
0.12131.3426000.5683-1.4608-3.84200.81252.3812-295.3901-268.8436-2.4774-2.5207
0.08891.3927000.5890-1.6007-3.73370.78122.1330-294.3068-270.2423-2.4123-2.4522
0.09951.4528000.6073-1.5519-3.83620.82812.2843-295.3315-269.7538-2.4685-2.5050
0.11451.529000.5790-1.7939-4.28760.84382.4937-299.8461-272.1744-2.4272-2.4674
0.06441.5530000.5735-1.7285-4.20510.81252.4766-299.0209-271.5201-2.4193-2.4574
0.07981.631000.5537-1.7226-4.28500.84382.5624-299.8200-271.4610-2.5367-2.5696
0.10131.6532000.5575-1.5715-3.98130.8752.4098-296.7825-269.9498-2.4926-2.5267
0.12541.733000.5905-1.6412-4.47030.85942.8291-301.6730-270.6473-2.5017-2.5340
0.0851.7634000.6133-1.9159-4.67600.84382.7601-303.7296-273.3941-2.4614-2.4960
0.0651.8135000.6074-1.8237-4.35250.85942.5288-300.4951-272.4724-2.4597-2.5004
0.07551.8636000.5836-1.9252-4.40050.81252.4753-300.9748-273.4872-2.4327-2.4716
0.07461.9137000.5789-1.9280-4.49060.81252.5626-301.8762-273.5149-2.4686-2.5115
0.13481.9638000.6015-1.8658-4.24280.82812.3769-299.3976-272.8936-2.4943-2.5393
0.02172.0139000.6122-2.3335-4.92290.82812.5894-306.1988-277.5699-2.4841-2.5272
0.02192.0740000.6522-2.9890-6.01640.82813.0274-317.1334-284.1248-2.4105-2.4545
0.01192.1241000.6922-3.4777-6.67490.79693.1972-323.7187-289.0121-2.4272-2.4699
0.01532.1742000.6993-3.2406-6.67750.79693.4369-323.7453-286.6413-2.4047-2.4465
0.0112.2243000.7178-3.7991-7.43970.76563.6406-331.3667-292.2260-2.3843-2.4290
0.00722.2744000.6840-3.3269-6.80210.81253.4752-324.9908-287.5042-2.4095-2.4536
0.01972.3245000.7013-3.6890-7.30140.81253.6124-329.9841-291.1250-2.4118-2.4543
0.01822.3746000.7476-3.8994-7.53660.82813.6372-332.3356-293.2291-2.4163-2.4565
0.01252.4347000.7199-4.0560-7.57650.84383.5204-332.7345-294.7952-2.3699-2.4100
0.00822.4848000.7048-3.6613-7.13560.8753.4743-328.3255-290.8477-2.3925-2.4303
0.01182.5349000.6976-3.7908-7.31520.81253.5244-330.1224-292.1431-2.3633-2.4047
0.01182.5850000.7198-3.9049-7.55570.82813.6508-332.5271-293.2844-2.3764-2.4194
0.0062.6351000.7506-4.2118-7.91490.81253.7032-336.1194-296.3530-2.3407-2.3860
0.01432.6852000.7408-4.2433-7.98020.81253.7369-336.7721-296.6682-2.3509-2.3946
0.00572.7453000.7552-4.3392-8.08310.79693.7439-337.8013-297.6275-2.3388-2.3842
0.01382.7954000.7404-4.2395-7.97620.81253.7367-336.7322-296.6304-2.3286-2.3737
0.00792.8455000.7525-4.4466-8.21960.78123.7731-339.1662-298.7007-2.3200-2.3641
0.00772.8956000.7520-4.5586-8.34850.79693.7899-340.4545-299.8206-2.3078-2.3517
0.00942.9457000.7527-4.5542-8.35090.78123.7967-340.4790-299.7773-2.3062-2.3510
0.00542.9958000.7520-4.5169-8.30790.78123.7911-340.0493-299.4038-2.3081-2.3530

框架版本

  • Transformers 4.35.0.dev0
  • Pytorch 2.0.1+cu118
  • Datasets 2.12.0
  • Tokenizers 0.14.0

引用说明

如果您发现 Zephyr-7B-β 对您的工作有所帮助,请按以下方式引用:

@misc{tunstall2023zephyr,
      title={Zephyr: Direct Distillation of LM Alignment}, 
      author={Lewis Tunstall and Edward Beeching and Nathan Lambert and Nazneen Rajani and Kashif Rasul and Younes Belkada and Shengyi Huang and Leandro von Werra and Clémentine Fourrier and Nathan Habib and Nathan Sarrazin and Omar Sanseviero and Alexander M. Rush and Thomas Wolf},
      year={2023},
      eprint={2310.16944},
      archivePrefix={arXiv},
      primaryClass={cs.LG}
}

开放大语言模型排行榜评估结果

详细结果可查看此处

指标数值
平均值52.15
ARC(25轮)62.03
HellaSwag(10轮)84.36
MMLU(5轮)61.07
TruthfulQA(0轮)57.45
Winogrande(5轮)77.74
GSM8K(5轮)12.74
DROP(3轮)9.66