ChatGPT在國內(nèi)經(jīng)常會(huì)遇到各種網(wǎng)絡(luò)問題,而且一旦失去網(wǎng)絡(luò)連接就無法使用。此外,Chatgpt是需要付費(fèi)的。在2023年,GPT將迎來發(fā)展元年,我相信未來每個(gè)人都應(yīng)該有自己的Chatgpt大模型,而不僅僅是大型機(jī)構(gòu)才能擁有。
未來,對(duì)于Chatgpt大模型所需的計(jì)算能力,應(yīng)該是人人都能負(fù)擔(dān)得起的,就像現(xiàn)在的個(gè)人電腦一樣。在這里,我主要講解如何利用Facebook開源的LLAMA 7B大模型和llama.cpp開源代碼,在macbook Pro M1上構(gòu)建一個(gè)能夠運(yùn)行的AI助手。
下面我們來逐步講解。
第一步:下載 7B 的大模型
使用命令行方式下載
curl -o ggml-alpaca-7b-q4.bin -C - <https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC>
或是直接使用瀏覽器打開,下載完成后文件改名為 ggml-alpaca-7b-q4.bin:
<https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC>
第二步:下載llama.cpp
llama.cpp工程是基于Facebook的llama開源項(xiàng)目進(jìn)行改進(jìn)的。它通過使用C++進(jìn)行推理,降低了資源需求,同時(shí)保持了高速處理的特點(diǎn)。
請(qǐng)使用 git clone 方式下載代碼,以便以后輕松更新。當(dāng)前項(xiàng)目更新速度較快。
git clone <https://github.com/ggerganov/llama.cpp.git>
第三步:編繹llama.cpp
進(jìn)入llama.cpp,運(yùn)行如下命令
make
如果沒有報(bào)錯(cuò)則表示編繹成功了。
在目錄下會(huì)生成如下幾個(gè)可執(zhí)行文件:main、quantize。其中,main是啟動(dòng)會(huì)話的程序,而quantize目前不需要使用。
第四步:將 ggml-alpaca-7b-q4.bin 放到llama.cpp/models目錄下 第五步:完成一個(gè)啟動(dòng)腳本start.sh
先看看 main 能接受哪些參數(shù):
(base) ? llama.cpp git:(master) ? ./main -h
usage: ./main [options]
options:
-h, --help show this help message and exit
-i, --interactive run in interactive mode
-ins, --instruct run in instruction mode (use with Alpaca models)
-r PROMPT, --reverse-prompt PROMPT
in interactive mode, poll user input upon seeing PROMPT (can be
specified more than once for multiple prompts).
--color colorise output to distinguish prompt and user input from generations
-s SEED, --seed SEED RNG seed (default: -1)
-t N, --threads N number of threads to use during computation (default: 4)
-p PROMPT, --prompt PROMPT
prompt to start generation with (default: empty)
--random-prompt start with a randomized prompt.
-f FNAME, --file FNAME
prompt file to start generation.
-n N, --n_predict N number of tokens to predict (default: 128)
--top_k N top-k sampling (default: 40)
--top_p N top-p sampling (default: 0.9)
--repeat_last_n N last n tokens to consider for penalize (default: 64)
--repeat_penalty N penalize repeat sequence of tokens (default: 1.3)
-c N, --ctx_size N size of the prompt context (default: 512)
--ignore-eos ignore end of stream token and continue generating
--memory_f16 use f16 instead of f32 for memory key+value
--temp N temperature (default: 0.8)
-b N, --batch_size N batch size for prompt processing (default: 8)
-m FNAME, --model FNAME
model path (default: models/llama-7B/ggml-model.bin)
我們主要使用交互模式,并將可預(yù)測的令牌數(shù)設(shè)置為512,因此請(qǐng)按以下命令操作:
./main -m ./models/ggml-alpaca-7b-q4.bin --color -ins -r "Me:" -n 512
啟動(dòng)后的界面如下:
開始使用:
先提一個(gè)問題:“how to Implementing Gradient Ascent with Python/ target=_blank class=infotextkey>Python?”
生成的答案如下,相比chatgpt有點(diǎn)簡陋。
畢竟模型只有7B的參數(shù),如果換到65B,應(yīng)該效果會(huì)好很多。不過已經(jīng)非常好了,相信未來繼續(xù)優(yōu)化后會(huì)更好。






