未来,对付Chatgpt大模型所需的打算能力,该当是大家都能包袱得起的,就像现在的个人电脑一样。在这里,我紧张讲解如何利用Facebook开源的LLAMA 7B大模型和llama.cpp开源代码,在Macbook Pro M1上构建一个能够运行的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开源项目进行改进的。它通过利用C++进行推理,降落了资源需求,同时保持了高速处理的特点。
请利用 git clone 办法下载代码,以便往后轻松更新。当前项目更新速率较快。
git clone <https://github.com/ggerganov/llama.cpp.git>
第三步:编绎llama.cpp
进入llama.cpp,运行如下命令
make
如果没有报错则表示编绎成功了。
在目录下会天生如下几个可实行文件:main、quantize。个中,main是启动会话的程序,而quantize目前不须要利用。
第四步:将 ggml-alpaca-7b-q4.bin 放到llama.cpp/models目录下 第五步:完成一个启动脚本start.sh
先看看 main 能接管哪些参数:
(base) ➜ llama.cpp git:(master) ✗ ./main -husage: ./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)
我们紧张利用交互模式,并将可预测的令牌数设置为512,因此请按以下命令操作:
./main -m ./models/ggml-alpaca-7b-q4.bin --color -ins -r "Me:" -n 512
启动后的界面如下:
开始利用:
先提一个问题:“how to Implementing Gradient Ascent with python?”
天生的答案如下,比较chatgpt有点简陋。
毕竟模型只有7B的参数,如果换到65B,该当效果会好很多。不过已经非常好了,相信未来连续优化后会更好。