首頁 >科技週邊 >人工智慧 >Zephyr-7B的綜合指南:功能,用法和微調

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

Jennifer Aniston
Jennifer Aniston原創
2025-03-08 09:55:11679瀏覽

探索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