模型概述
模型特點
模型能力
使用案例
🚀 神經聊天模型v3-3(Neural-Chat-v3-3)
神經聊天模型v3-3是一款基於英特爾Gaudi 2處理器微調的70億參數大語言模型,它在數學問答等語言相關任務上表現出色,為用戶提供高效準確的語言處理能力。
🚀 快速開始
模型復現
以下是復現模型的示例代碼鏈接:GitHub示例代碼。以下是復現構建模型的文檔步驟:
git clone https://github.com/intel/intel-extension-for-transformers.git
cd intel-extension-for-transformers
docker build --no-cache ./ --target hpu --build-arg REPO=https://github.com/intel/intel-extension-for-transformers.git --build-arg ITREX_VER=main -f ./intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbot_finetuning:latest
docker run -it --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --net=host --ipc=host chatbot_finetuning:latest
# 進入docker容器後
cd examples/finetuning/finetune_neuralchat_v3
我們選擇最新的預訓練模型mistralai/Mistral-7B-v0.1
和開源數據集Open-Orca/SlimOrca
進行實驗。
以下腳本使用deepspeed zero2
在8張Gaudi2卡上啟動訓練。在finetune_neuralchat_v3.py
中,默認設置為use_habana=True, use_lazy_mode=True, device="hpu"
以適配Gaudi2。如果你想在NVIDIA GPU上運行,可以將它們設置為use_habana=False, use_lazy_mode=False, device="auto"
。
deepspeed --include localhost:0,1,2,3,4,5,6,7 \
--master_port 29501 \
finetune_neuralchat_v3.py
合併LoRA權重:
python apply_lora.py \
--base-model-path mistralai/Mistral-7B-v0.1 \
--lora-model-path finetuned_model/ \
--output-path finetuned_model_lora
模型使用
FP32推理(使用Transformers)
import transformers
model_name = 'Intel/neural-chat-7b-v3-3'
model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
def generate_response(system_input, user_input):
# 使用提供的模板格式化輸入
prompt = f"### System:\n{system_input}\n### User:\n{user_input}\n### Assistant:\n"
# 對提示進行分詞和編碼
inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False)
# 生成響應
outputs = model.generate(inputs, max_length=1000, num_return_sequences=1)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# 僅提取助手的響應
return response.split("### Assistant:\n")[-1]
# 示例用法
system_input = "You are a math expert assistant. Your mission is to help users understand and solve various math problems. You should provide step-by-step solutions, explain reasonings and give the correct answer."
user_input = "calculate 100 + 520 + 60"
response = generate_response(system_input, user_input)
print(response)
# 預期響應
"""
To calculate the sum of 100, 520, and 60, we will follow these steps:
1. Add the first two numbers: 100 + 520
2. Add the result from step 1 to the third number: (100 + 520) + 60
Step 1: Add 100 and 520
100 + 520 = 620
Step 2: Add the result from step 1 to the third number (60)
(620) + 60 = 680
So, the sum of 100, 520, and 60 is 680.
"""
BF16推理(使用英特爾Transformers擴展和英特爾PyTorch擴展)
from transformers import AutoTokenizer, TextStreamer
import torch
from intel_extension_for_transformers.transformers import AutoModelForCausalLM
import intel_extension_for_pytorch as ipex
model_name = "Intel/neural-chat-7b-v3-3"
prompt = "Once upon a time, there existed a little girl,"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
inputs = tokenizer(prompt, return_tensors="pt").input_ids
streamer = TextStreamer(tokenizer)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
model = ipex.optimize(model.eval(), dtype=torch.bfloat16, inplace=True, level="O1", auto_kernel_selection=True)
outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
INT4推理(使用Transformers和英特爾Transformers擴展)
from transformers import AutoTokenizer, TextStreamer
from intel_extension_for_transformers.transformers import AutoModelForCausalLM, WeightOnlyQuantConfig
model_name = "Intel/neural-chat-7b-v3-3"
# 對於int8,應設置weight_dtype="int8"
config = WeightOnlyQuantConfig(compute_dtype="bf16", weight_dtype="int4")
prompt = "Once upon a time, there existed a little girl,"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
inputs = tokenizer(prompt, return_tensors="pt").input_ids
streamer = TextStreamer(tokenizer)
model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=config)
outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
✨ 主要特性
- 微調優化:該模型是在英特爾Gaudi 2處理器上,基於
Intel/neural-chat-7b-v3-1
在meta-math/MetaMathQA
數據集上進行微調得到的。 - 對齊方法:使用直接性能優化(DPO)方法,結合
Intel/orca_dpo_pairs
數據集進行對齊。 - 廣泛應用:可用於多種語言相關任務,如文本生成、問答等。
📚 詳細文檔
模型詳情
屬性 | 詳情 |
---|---|
模型作者 - 公司 | Intel。NeuralChat團隊,成員來自DCAI/AISE/AIPT。核心團隊成員:Kaokao Lv、Liang Lv、Chang Wang、Wenxin Zhang、Xuhui Ren和Haihao Shen。 |
日期 | 2023年12月 |
版本 | v3 - 3 |
類型 | 70億參數大語言模型 |
論文或其他資源 | Medium博客 |
許可證 | Apache 2.0 |
問題或評論 | 社區板塊和英特爾開發者Discord |
預期用途
預期用途 | 描述 |
---|---|
主要預期用途 | 你可以將微調後的模型用於多個與語言相關的任務。查看大語言模型排行榜,瞭解該模型的表現。 |
主要預期用戶 | 任何進行與語言相關任務推理的人。 |
超出範圍的用途 | 在大多數情況下,該模型需要針對你的特定任務進行微調。該模型不應被用於故意為人們創造敵對或排斥的環境。 |
影響因素
因素 | 描述 |
---|---|
數據集 | 關於數據集和註釋的更多詳細信息可在meta-math/MetaMathQA、項目頁面https://meta-math.github.io/ 以及相關論文https://arxiv.org/abs/2309.12284 中找到。 |
輸入影響 | 模型的性能可能會因輸入的不同而有所變化。在這種情況下,提供的提示可能會極大地改變語言模型的預測。 |
訓練環境 | 該模型在英特爾Gaudi 2處理器(8張卡)上進行訓練。 |
硬件軟件影響 | 在其他硬件和軟件上部署模型會改變模型性能。模型評估因素來自Hugging Face大語言模型排行榜:ARC、HellaSwag、MMLU、TruthfulQA、Winogrande和GSM8K(見下面的定量分析)。 |
評估指標
指標 | 描述 |
---|---|
模型性能衡量 | 根據大語言模型排行榜上的指標,將該模型的性能與其他大語言模型進行評估。這些指標已成為大語言模型性能的標準。 |
決策閾值 | 未使用決策閾值。 |
不確定性和可變性處理方法 | - |
訓練和評估數據
數據類型 | 描述 |
---|---|
數據集 | 訓練數據來自meta-math/MetaMathQA,該數據集是從GSM8k和MATH訓練集增強而來。訓練過程中未使用GSM8k測試集,因此不存在數據汙染問題。 |
動機 | - |
預處理 | - |
🔧 技術細節
該模型基於mistralai/Mistral-7B-v0.1
進行微調,使用英特爾Gaudi 2處理器進行訓練。在微調過程中,採用了直接性能優化(DPO)方法,並結合Intel/orca_dpo_pairs
數據集進行對齊。更多信息請參考博客The Practice of Supervised Fine-tuning and Direct Preference Optimization on Intel Gaudi2。
Photo by Google DeepMind on Unsplash
📊 定量分析
開放大語言模型排行榜的結果可在此處查看。各項指標結果如下:
指標 | 數值 |
---|---|
平均值 | 69.83 |
ARC(25次少樣本學習) | 66.89 |
HellaSwag(10次少樣本學習) | 85.26 |
MMLU(5次少樣本學習) | 63.07 |
TruthfulQA(0次少樣本學習) | 63.01 |
Winogrande(5次少樣本學習) | 79.64 |
GSM8K(5次少樣本學習) | 61.11 |
⚠️ 倫理考量與侷限性
neural-chat-7b-v3-3
可能會產生事實錯誤的輸出,因此不應依賴它來提供事實準確的信息。由於預訓練模型和微調數據集的侷限性,該模型有可能生成低俗、有偏見或其他冒犯性的輸出。
因此,在部署neural-chat-7b-v3-3
的任何應用之前,開發者應進行安全測試。
💡 注意事項與建議
用戶(直接用戶和下游用戶)應瞭解該模型的風險、偏見和侷限性。
以下是一些瞭解英特爾AI軟件的有用鏈接:
📄 免責聲明
該模型的許可證不構成法律建議。我們不對使用該模型的第三方的行為負責。在將該模型用於商業目的之前,請諮詢律師。
開放大語言模型排行榜評估結果
詳細結果可在此處查看。
指標 | 數值 |
---|---|
平均值 | 69.83 |
AI2推理挑戰(25次少樣本學習) | 66.89 |
HellaSwag(10次少樣本學習) | 85.26 |
MMLU(5次少樣本學習) | 63.07 |
TruthfulQA(0次少樣本學習) | 63.01 |
Winogrande(5次少樣本學習) | 79.64 |
GSM8k(5次少樣本學習) | 61.11 |



