首页 > 科技周边 > 人工智能 > Zephyr-7B的综合指南:功能,用法和微调

Zephyr-7B的综合指南:功能,用法和微调

Jennifer Aniston
发布: 2025-03-08 09:55:11
原创
671 人浏览过

探索Zephyr-7B:强大的开源LLM

> OpenAI LLM排行榜嗡嗡作响,旨在竞争GPT-4的新开源车型,而Zephyr-7B是一个出色的竞争者。本教程从WebPilot.ai探索了这种尖端语言模型,展示了它与变形金刚管道的使用,并在代理 - 教学数据集上进行了微调。 AI的新手? AI基础知识技能轨道是一个很好的起点。

了解Zephyr-7b

Zephyr系列的一部分

Zephyr-7b经过训练,可以充当有益的助手。它的优势在于生成连贯的文本,翻译语言,总结信息,情感分析和上下文感知的问题回答。

Zephyr-7b-β:微调的漫威

该系列中的第二个模型是 Zephyr-7b-β是一个微调的Mistral-7b模型。 在公共和合成数据集的混合物中,使用直接偏好优化(DPO)培训,它擅长解释复杂的查询并汇总冗长的文本。 在发行时,它在MT-Bench和Alpacaeval基准测试的7B聊天模型中排名第一。 通过Zephyr Chat上的免费演示测试其功能。

来自Zephyr Chat Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning

> >使用拥抱的脸型变压器访问Zephyr-7b

>本教程使用拥抱的脸部变压器来轻松访问。 (如果遇到加载问题,请咨询推理Kaggle笔记本。

>

安装库:

确保您有最新版本:>
  1. >导入库:
!pip install -q -U transformers
!pip install -q -U accelerate
!pip install -q -U bitsandbytes
登录后复制
登录后复制
  1. 创建管道:
import torch
from transformers import pipeline
登录后复制
登录后复制
利用多个GPU进行更快的生成。
    提供更快的计算和减少的内存使用情况(但精度略低)。>
  1. device_map="auto"torch.bfloat16生成文本:
  2. 下面的示例演示了生成python代码。
model_name = "HuggingFaceH4/zephyr-7b-beta"

pipe = pipeline(
    "text-generation",
    model=model_name,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)
登录后复制
登录后复制
prompt = "Write a Python function that can clean the HTML tags from the file:"

outputs = pipe(
    prompt,
    max_new_tokens=300,
    do_sample=True,
    temperature=0.7,
    top_k=50,
    top_p=0.95,
)
print(outputs[0]["generated_text"])
登录后复制
登录后复制
系统提示:

使用Zephyr-7B样式系统提示自定义响应:> Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning

  1. 自定义数据集上的微调Zephyr-7b
  2. >本节使用Kaggle的Free GPU(大约2小时)在自定义数据集上进行微调Zephyr-7b-Beta。 (有关故障排除的微调Kaggle笔记本。)
>

>设置并准备环境

  1. 安装库:
!pip install -q -U transformers
!pip install -q -U accelerate
!pip install -q -U bitsandbytes
登录后复制
登录后复制
  1. 导入模块:
import torch
from transformers import pipeline
登录后复制
登录后复制
  1. > kaggle秘密(对于kaggle笔记本):检索拥抱的脸和偏见和偏见API键。

  2. 拥抱面部和重量和偏见登录:>

model_name = "HuggingFaceH4/zephyr-7b-beta"

pipe = pipeline(
    "text-generation",
    model=model_name,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)
登录后复制
登录后复制

Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning

    定义模型和数据集名称:
  1. >
> Agentinstruct DataSet处理
prompt = "Write a Python function that can clean the HTML tags from the file:"

outputs = pipe(
    prompt,
    max_new_tokens=300,
    do_sample=True,
    temperature=0.7,
    top_k=50,
    top_p=0.95,
)
print(outputs[0]["generated_text"])
登录后复制
登录后复制

函数将数据集适应Zephyr-7b的及时样式。

format_prompt

messages = [
    {
        "role": "system",
        "content": "You are a skilled software engineer who consistently produces high-quality Python code.",
    },
    {
        "role": "user",
        "content": "Write a Python code to display text in a star pattern.",
    },
]

prompt = pipe.tokenizer.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)

outputs = pipe(
    prompt,
    max_new_tokens=300,
    do_sample=True,
    temperature=0.7,
    top_k=50,
    top_p=0.95,
)
print(outputs[0]["generated_text"])
登录后复制

Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning >加载和准备模型

具有4位精度的

>
    负载模型:
  1. 这对于有限的VRAM的GPU有效培训至关重要。
%%capture
%pip install -U bitsandbytes
%pip install -U transformers
%pip install -U peft
%pip install -U accelerate
%pip install -U trl
登录后复制
    >加载tokenizer:
# ... (Import statements as in original tutorial) ...
登录后复制
    添加适配器层(peft):
  1. >这允许仅通过更新适配器层中的参数来进行有效的微调。>
训练模型
!huggingface-cli login --token $secret_hf
# ... (wandb login as in original tutorial) ...
登录后复制

>
    培训参数:
  1. >配置超参数(请参阅微调千层面2教程)。
base_model = "HuggingFaceH4/zephyr-7b-beta"
dataset_name = "THUDM/AgentInstruct"
new_model = "zephyr-7b-beta-Agent-Instruct"
登录后复制
    SFT培训师:
  1. 使用拥抱Face的TRL库来创建教练。>
# ... (format_prompt function and dataset loading as in original tutorial) ...
登录后复制
开始训练:
# ... (bnb_config and model loading as in original tutorial) ...
登录后复制

Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning >保存和部署微调模型Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning

保存模型:
推到拥抱面线:
# ... (tokenizer loading and configuration as in original tutorial) ...
登录后复制
    >
# ... (peft_config and model preparation as in original tutorial) ...
登录后复制

测试微型模型Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning >用各种提示测试模型的性能。原始教程中提供了示例。

>

Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning Comprehensive Guide to Zephyr-7B: Features, Usage, and Fine-tuning

结论

> Zephyr-7b-beta表现出令人印象深刻的功能。本教程为即使在资源受限的GPU上,也提供了利用和微调这一强大的LLM的综合指南。 考虑大型语言模型(LLMS)概念课程,以了解更深的LLM知识。

以上是Zephyr-7B的综合指南:功能,用法和微调的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板