模型概述
模型特點
模型能力
使用案例
🚀 Llama3-8B-Chinese-Chat
Llama3-8B-Chinese-Chat是基於Meta-Llama-3-8B-Instruct模型,為中英文用戶量身打造的指令調優語言模型。它具備角色扮演、工具使用等多種能力,能有效減少“中文問題英文回答”以及中英文混答的情況,在角色扮演、函數調用和數學計算等方面表現出色。
🚀 快速開始
我們在 此GitHub倉庫 中提供了下載、使用和復現我們各類模型的詳細說明。如果您喜歡我們的模型,煩請給我們的GitHub倉庫點個星,同時也請在我們的HuggingFace倉庫上點擊“點贊”,感謝支持!
❗️❗️❗️注意:主分支包含 Llama3-8B-Chinese-Chat-v2.1 的 f16 GGUF文件。如果您想使用Llama3-8B-Chinese-Chat-v1 的f16 GGUF文件,請參考 “v1” 分支;若想使用Llama3-8B-Chinese-Chat-v2 的f16 GGUF文件,請參考 “v2” 分支。
❗️❗️❗️注意:為實現最佳性能,我們未對模型的身份進行微調。因此,像“你是誰”或“誰開發了你”這類問題的回答可能是隨機的,不一定準確。
✨ 主要特性
- 多語言支持:支持中文和英文,滿足不同語言用戶的需求。
- 能力多樣:具備角色扮演、函數調用、數學計算、寫作、編碼等多種能力。
- 性能提升:相比v1,v2.1的訓練數據集擴大了5倍(約100K偏好對),在角色扮演、函數調用和數學能力方面有顯著提升,且在中文回答中更不易夾雜英文單詞。
📦 安裝指南
復現Llama3-8B-Chinese-Chat-v2
若要復現Llama3-8B-Chinese-Chat-v2(若要復現Llama3-8B-Chinese-Chat-v1,請參考 此鏈接):
git clone https://github.com/hiyouga/LLaMA-Factory.git
git reset --hard 32347901d4af94ccd72b3c7e1afaaceb5cb3d26a # 若為Llama3-8B-Chinese-Chat-v1: 836ca0558698206bbf4e3b92533ad9f67c9f9864
cd LLaMA-Factory
# 我們用於Llama3-8B-Chinese-Chat-v2的數據集即將發佈。若您想復現Llama3-8B-Chinese-Chat-v1,可設置 `Your_Dataset_Name_or_PATH=dpo_mix_en,dpo_mix_zh`。
deepspeed --num_gpus 8 src/train_bash.py \
--deepspeed ${Your_Deepspeed_Config_Path} \
--stage orpo \
--do_train \
--model_name_or_path meta-llama/Meta-Llama-3-8B-Instruct \
--dataset ${Your_Dataset_Name_or_PATH} \
--template llama3 \
--finetuning_type full \
--output_dir ${Your_Output_Path} \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--gradient_accumulation_steps 8 \
--lr_scheduler_type cosine \
--log_level info \
--logging_steps 5 \
--save_strategy epoch \
--save_total_limit 3 \
--save_steps 100 \
--learning_rate 5e-6 \
--num_train_epochs 3.0 \
--plot_loss \
--do_eval false \
--max_steps -1 \
--bf16 true \
--seed 42 \
--warmup_ratio 0.1 \
--cutoff_len 8192 \
--flash_attn true \
--orpo_beta 0.05 \
--optim paged_adamw_32bit
💻 使用示例
基礎用法
from llama_cpp import Llama
model = Llama(
"/Your/Path/To/GGUF/File",
verbose=False,
n_gpu_layers=-1,
)
system_prompt = "You are a helpful assistant."
def generate_reponse(_model, _messages, _max_tokens=8192):
_output = _model.create_chat_completion(
_messages,
stop=["<|eot_id|>", "<|end_of_text|>"],
max_tokens=_max_tokens,
)["choices"][0]["message"]["content"]
return _output
# 以下是一些示例
messages = [
{
"role": "system",
"content": system_prompt,
},
{"role": "user", "content": "寫一首詩吧"},
]
print(generate_reponse(model, messages))
📚 詳細文檔
模型概述
Llama3-8B-Chinese-Chat是基於Meta-Llama-3-8B-Instruct模型,為中英文用戶打造的指令調優語言模型,具備角色扮演、工具使用等多種能力。
- 開發者:Shenzhi Wang*、Yaowei Zheng*、Guoyin Wang (in.ai)、Shiji Song、Gao Huang。(*: 同等貢獻)
- 許可證:Llama-3 License
- 基礎模型:Meta-Llama-3-8B-Instruct
- 模型大小:8.03B
- 上下文長度:8K
模型更新
Llama3-8B-Chinese-Chat-v2.1 [2024年5月6日]
- 訓練數據集相比v1擴大了5倍(約100K偏好對),在角色扮演、函數調用和數學能力方面有顯著提升,在數學計算上優於v2,且中文回答中更不易夾雜英文單詞。
- 提供官方 q4_0 GGUF 版本:https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-4bit
- 提供官方 q8_0 GGUF 版本:https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-8bit
- 提供官方 f16 GGUF 版本:https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-f16
- 提供官方 Ollama模型(q4_0 GGUF):wangshenzhi/llama3-8b-chinese-chat-ollama-q4,使用命令
ollama run wangshenzhi/llama3-8b-chinese-chat-ollama-q4
可快速使用。 - 提供官方 Ollama模型(q8_0 GGUF):wangshenzhi/llama3-8b-chinese-chat-ollama-q8,使用命令
ollama run wangshenzhi/llama3-8b-chinese-chat-ollama-q8
可快速使用。 - 提供官方 Ollama模型(f16 GGUF):wangshenzhi/llama3-8b-chinese-chat-ollama-fp16,使用命令
ollama run wangshenzhi/llama3-8b-chinese-chat-ollama-fp16
可快速使用。 - 提供Llama3-8B-Chinese-Chat-v2的在線交互式演示:https://huggingface.co/spaces/llamafactory/Llama3-8B-Chinese-Chat
Llama3-8B-Chinese-Chat-v2 [2024年4月29日]
- 訓練數據集相比v1擴大了5倍(約100K偏好對),在角色扮演、函數調用和數學能力方面有顯著提升。
- 提供官方f16 GGUF版本:https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-f16/tree/v2
- 提供官方8位量化GGUF版本:https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-8bit/tree/v2
- 提供Llama3-8B-Chinese-Chat-v2的在線交互式演示:https://huggingface.co/spaces/llamafactory/Llama3-8B-Chinese-Chat
Llama3-8B-Chinese-Chat-v1
- 提供官方Ollama模型(f16 GGUF):wangshenzhi/llama3-8b-chinese-chat-ollama-f16,使用命令
ollama run wangshenzhi/llama3-8b-chinese-chat-ollama-fp16
可快速使用。 - 提供官方Ollama模型(8位量化GGUF):wangshenzhi/llama3-8b-chinese-chat-ollama-q8,使用命令
ollama run wangshenzhi/llama3-8b-chinese-chat-ollama-q8
可快速使用。 - 提供官方f16 GGUF版本:shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-f16-v1
- 提供官方8位量化GGUF版本:shenzhi-wang/Llama3-8B-Chinese-Chat-GGUF-8bit-v1
- 在中國,可從 Gitee AI倉庫 下載v1模型。
模型示例
以下是Llama3-8B-Chinese-Chat-v2.1 生成的一些示例,涵蓋角色扮演、函數調用、數學計算、弱智吧問答、安全、寫作和編碼等方面。
- 角色扮演示例:包含扮演泰勒·斯威夫特、周杰倫、莎士比亞、諸葛亮等角色的問答。
- 函數調用示例:展示瞭如何調用互聯網搜索、發送郵件等工具。
- 數學計算示例:解答瞭如年齡計算、數學應用題等問題。
- 弱智吧問答示例:對一些有趣的問題給出了回答。
- 安全示例:拒絕提供製造非法藥物等違法信息。
- 寫作示例:生成了關於人工智能的綜述、詩歌等內容。
- 編碼示例:用Python實現了快速排序算法(遞歸和非遞歸版本),用C++實現了KMP算法。
引用說明
如果我們的Llama3-8B-Chinese-Chat對您有幫助,請按以下格式引用:
@misc {shenzhi_wang_2024,
author = {Wang, Shenzhi and Zheng, Yaowei and Wang, Guoyin and Song, Shiji and Huang, Gao},
title = { Llama3-8B-Chinese-Chat (Revision 6622a23) },
year = 2024,
url = { https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat },
doi = { 10.57967/hf/2316 },
publisher = { Hugging Face }
}
🔧 技術細節
模型介紹
Llama3-8B-Chinese-Chat是首個基於 Meta-Llama-3-8B-Instruct模型,通過ORPO [1] 為中英文用戶進行專門微調的模型。
- 與原始的 Meta-Llama-3-8B-Instruct模型 相比,Llama3-8B-Chinese-Chat-v1模型顯著減少了“中文問題英文回答”以及中英文混答的情況。
- 與 Llama3-8B-Chinese-Chat-v1 相比,Llama3-8B-Chinese-Chat-v2模型的訓練數據量大幅增加(從20K增加到100K),性能顯著提升,尤其是在角色扮演、工具使用和數學計算方面。
[1] Hong, Jiwoo, Noah Lee, and James Thorne. "Reference-free Monolithic Preference Optimization with Odds Ratio." arXiv preprint arXiv:2403.07691 (2024).
訓練框架
訓練詳情
- 輪數:2
- 學習率:5e-6
- 學習率調度器類型:餘弦
- 熱身比例:0.1
- 截斷長度(即上下文長度):8192
- orpo beta(即ORPO論文中的 $\lambda$):0.05
- 全局批量大小:128
- 微調類型:全參數
- 優化器:paged_adamw_32bit
📄 許可證
本模型遵循 Llama-3 License。



