1.簡(jiǎn)介:
組織機(jī)構(gòu):Meta(Facebook)
代碼倉(cāng):GitHub - facebookresearch/llama: Inference code for LLaMA models
模型:LIama-2-7b-hf、Chinese-LLaMA-Plus-2-7B?
下載:使用huggingface.co和百度網(wǎng)盤下載
硬件環(huán)境:暗影精靈7Plus
Windows版本:Windows 11家庭中文版 Insider Preview 22H2
內(nèi)存 32G
GPU顯卡:Nvidia GTX 3080 Laptop (16G)
查看 https://github.com/ymcui/Chinese-LLaMA-Alpaca-2
新的模型出來了,可以試一試。
2.代碼和模型下載:
下載Chinese-LLaMA-Alpaca-2代碼倉(cāng):
d:\
git clone https://github.com/ymcui/Chinese-LLaMA-Alpaca-2
獲取原版LIama-2-7b-hf模型:https://huggingface.co/meta-llama/Llama-2-7b-hf
下載所有文件,備用。
將文件下載到 d:\llama.cpp\models2的目錄:
根據(jù)
直接下載完整版模型:
將下載好的文件復(fù)制到 d:\llama.cpp\models2\chinese-alpaca-2-7b-hf目錄下:
3.安裝依賴
暫無。
4.部署驗(yàn)證1(直接使用chinese-alpaca-2-7b完整版模型,轉(zhuǎn)FP16,INT4量化)
生成FP16模型并進(jìn)行4-bit量化:
cd llama.cpp
python convert.py models2/chinese-alpaca-2-7b-hf/
./quantize ./models2/chinese-alpaca-2-7b-hf/ggml-model-f16.gguf ./models2/chinese-alpaca-2-7b-hf/ggml-model-q4_0.gguf q4_0
參考 chat.sh
#!/bin/bash
# temporary script to chat with Chinese Alpaca-2 model
# usage: ./chat.sh alpaca2-ggml-model-path your-first-instruction
SYSTEM='You are a helpful assistant. 你是一個(gè)樂于助人的助手。'
FIRST_INSTRUCTION=$2
./main -m $1 \
--color -i -c 4096 -t 8 --temp 0.5 --top_k 40 --top_p 0.9 --repeat_penalty 1.1 \
--in-prefix-bos --in-prefix ' [INST] ' --in-suffix ' [/INST]' -p \
"[INST] <<SYS>>
$SYSTEM
<</SYS>>
$FIRST_INSTRUCTION [/INST]"
#./chat.sh models2/7B/ggml-model-q4_0.gguf '請(qǐng)列舉5條文明乘車的建議'
編輯好推理代碼并執(zhí)行:
./main -m ./models2/chinese-alpaca-2-7b-hf/ggml-model-q4_0.gguf -n -1 --color -r "User:" --in-prefix " " -i -c 4096 -t 8 --temp 0.5 --top_k 40 --top_p 0.9 --repeat_penalty 1.1 -e -p "User: Hi\nAI: Hello. I am an AI chatbot. Would you like to talk?\nUser: Sure!\nAI: What would you like to talk about?\nUser:"
#./main -m ./models_chat/path_to_original_llama_root_dir/ggml-model-q4_0.gguf -n -1 --color -r "User:" --in-prefix " " -i -e -p "User: Hi\nAI: Hello. I am an AI chatbot. Would you like to talk?\nUser: Sure!\nAI: What would you like to talk about?\nUser:"
您好!
你是誰?
你能做什么?
寫一篇國(guó)慶節(jié)去南京中山陵游玩的游記。
你寫完了嗎?
ChatGPT和國(guó)內(nèi)的AIGC產(chǎn)品相比有什么優(yōu)缺點(diǎn)?
你覺得怎樣才能做到獨(dú)立思考?
再見!
早知道2代目這么優(yōu)秀,我為啥還花那么多功夫研究一代呢?
5.部署驗(yàn)證2(使用Llama-2-7b-hf 原始模型和chinese-alpaca-2-lora-7b Lora模型,轉(zhuǎn)換,合并,轉(zhuǎn)FP16,INT4量化)
當(dāng)然,研究技術(shù)不能只是拿來主義,還是要試圖做一次成功的模型合并的。
下載兩個(gè)LoRa模型:
Chinese-LLaMA-2-LoRA-7B
https://pan.baidu.com/s/1bmgqdyRh9E3a2uqOGyNqiQ?pwd=7kvq
Chinese-Alpaca-2-LoRA-7B
https://pan.baidu.com/s/1g42_X7Z0QWDyrrDqv2jifQ?pwd=bq7n
解壓到 models2 目錄:
將 D:\Chinese-LLaMA-Alpaca-2\scripts\merge_llama2_with_chinese_lora_low_mem.py文件復(fù)制到 d:\llama.cpp目錄下:
python merge_llama2_with_chinese_lora_low_mem.py --base_model models2/Llama-2-7b-hf --lora_model models2/chinese-llama-2-lora-7b,models2/chinese-alpaca-2-lora-7b --output_type huggingface --output_dir models2/path_to_output_dir
看來使用huggingface 模式不行。
換成 pth方式試試:
python merge_llama2_with_chinese_lora_low_mem.py --base_model models2/Llama-2-7b-hf --lora_model models2/chinese-llama-2-lora-7b,models2/chinese-alpaca-2-lora-7b --output_type pth --output_dir models2/path_to_output_dir
是不是跟一代不一樣,不能用兩個(gè)Lora了?
去掉一個(gè)試試:
python merge_llama2_with_chinese_lora_low_mem.py --base_model models2/Llama-2-7b-hf --lora_model models2/chinese-alpaca-2-lora-7b --output_type pth --output_dir models2/path_to_output_dir
成功了!
轉(zhuǎn)成FP16:
python convert.py models2/path_to_output_dir/
結(jié)果如下:
量化:
./quantize ./models2/path_to_output_dir/ggml-model-f16.gguf ./models2/path_to_output_dir/ggml-model-q4_0.gguf q4_0
結(jié)果如下:
啟動(dòng)推理:
./main -m ./models2/path_to_output_dir/ggml-model-q4_0.gguf -n -1 --color -r "User:" --in-prefix " " -i -c 4096 -t 8 --temp 0.5 --top_k 40 --top_p 0.9 --repeat_penalty 1.1 -e -p "User: Hi\nAI: Hello. I am an AI chatbot. Would you like to talk?\nUser: Sure!\nAI: What would you like to talk about?\nUser:"
講一個(gè)笑話給我聽吧!
我打算從南京去新疆旅游,給我設(shè)計(jì)一個(gè)旅行路線
晚上睡不著覺怎么辦?
樹上10只鳥,打死1只,還剩幾只?
你算不出來嗎?
如何獲得女孩的芳心?
文章來源:http://www.zghlxwxcb.cn/news/detail-771984.html
== Running in interactive mode. ==
- Press Ctrl+C to interject at any time.
- Press Return to return control to LLaMa.
- To return control without starting a new line, end your input with '/'.
- If you want to submit another line, end your input with '\'.
User: Hi
AI: Hello. I am an AI chatbot. Would you like to talk?
User: Sure!
AI: What would you like to talk about?
User: 講一個(gè)笑話給我聽吧!
AI: 好的,這里有一個(gè):為什么豬不會(huì)上網(wǎng)?因?yàn)樗鼈冇蠾i-Fi。
我打算從南京去新疆旅游,給我設(shè)計(jì)一個(gè)旅行路線
AI: 當(dāng)然可以!您可以從南京出發(fā)前往烏魯木齊,然后繼續(xù)向南到喀什、和田等地游覽景點(diǎn),最后返回南京。這樣您的旅程將覆蓋了中國(guó)的西北地區(qū)。 User: 晚上睡不著覺怎么辦?
AI: 如果您無法入睡,您可以試試深呼吸或放松技巧來緩解壓力和焦慮感,或者嘗試聽一些輕松的音樂以幫助入眠。如果您的失眠問題持續(xù)存在,請(qǐng)咨詢醫(yī)生尋求進(jìn)一步的建議和治療。
樹上10只鳥,打死1只,還剩幾只?
AI: 您想讓我猜嗎?還是告訴我答案呢? User: 你算不出來嗎?
AI: 我很抱歉,但我無法回答這個(gè)問題,因?yàn)闆]有足夠的信息來計(jì)算剩余的鳥數(shù)量。如果您能提供更多的上下文或細(xì)節(jié),我可以幫助您更好地理解問題并給出更準(zhǔn)確的答案。
5+10=?
AI: 這個(gè)數(shù)學(xué)題很簡(jiǎn)單:將兩個(gè)數(shù)相加即可得到答案。所以,5 + 10 = 15。 User: 如何獲得女孩的芳心?
AI: 這是一個(gè)非常主觀的問題,因?yàn)槊總€(gè)人對(duì)"獲得女孩的芳心"的理解可能不同。但是,以下是一些建議可以幫助您與女孩建立更親密的關(guān)系: User: 你的建議呢?
AI: 我認(rèn)為最重要的是要尊重和關(guān)心對(duì)方,傾聽她的想法和感受,并給予她支持和鼓勵(lì)。此外,保持積極樂觀的態(tài)度也很重要,因?yàn)檫@會(huì)讓人感到更加愉快和自信。 User: 還有沒有別的建議?
AI: 當(dāng)然!您還可以嘗試做一些浪漫的事情來讓她感受到您的愛意,例如準(zhǔn)備一份特別的晚餐、送給她一束花或帶她去一個(gè)有趣的地方旅游等等。最重要的是要記得始終保持真誠(chéng)和誠(chéng)實(shí) ,這樣會(huì)讓女孩更加信任和依賴您。 User: 再見!
AI: 再見,祝您有一個(gè)美好的一天!
感覺二代還是可以的!??!文章來源地址http://www.zghlxwxcb.cn/news/detail-771984.html
到了這里,關(guān)于大模型部署手記(11)LLaMa2+Chinese-LLaMA-Plus-2-7B+Windows+llama.cpp+中文對(duì)話的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!