一 LLama.cpp
github下載llama.cpp
https://github.com/ggerganov/llama.cpp.git
2. gem5支持arm架構(gòu)比較好,所以我們使用編譯LLama.cpp。
以下是我對(duì)Makefile的修改
開始編譯:
make UNAME_M=aarch64
編譯會(huì)使用到aarch64-linux-gnu-gcc-10,編譯成功可以生成一個(gè)main 文件,這里我把main重命名成main_arm_backup了。
可以使用file main查看一下文件:
3. 下載一個(gè)大模型的model到llama.cpp/models的目錄下,這里我下載了llama-2-7b-chat.Q2_K.gguf。
這個(gè)模型2bit量化,跑起來(lái)不到3G的內(nèi)存。
GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw)
4.此時(shí)我們可以本地運(yùn)行以下main和模型,我的prompt是How are you
./main -m ./models/llama-2-7b-chat.Q2_K.gguf -p "How are you"-n 16
下圖最下面一行就是模型自動(dòng)生成的
二 gem5
gem5下載編譯好后,我們可以使用gem5.fast運(yùn)行模型了。
build/ARM/gem5.fast
--outdir=./m5out/llm_9
./configs/example/se.py -c
$LLAMA_path/llama.cpp/main-arm
'--options=-m $LLAMA_path/llama-2-7b-chat.Q2_K.gguf -p Hi -n 16'
--cpu-type=ArmAtomicSimpleCPU --mem-size=8GB -n 8
此時(shí)我的prompt是Hi,預(yù)期是n=8,跑8核。
上圖是gem5運(yùn)行大模型時(shí)生成的simout,我增加了AtomicCPU 運(yùn)行指令數(shù)量的打印,這是在gem5的改動(dòng)。
如果你下載的是gem5的源碼,那么現(xiàn)在運(yùn)行起來(lái)應(yīng)該只是最前面大模型的輸出。
模型的回答是Hi,I'm a30-year-old male, and 但是我預(yù)期的是8核,實(shí)際上運(yùn)行起來(lái):
可以看出來(lái),實(shí)際上只跑起來(lái)4核,定位后發(fā)現(xiàn),模型默認(rèn)是4核,需要增加-t 8選項(xiàng),即threadnumber設(shè)置成8,下面的紅色標(biāo)注的command.
build/ARM/gem5.fast
--outdir=./m5out/llm_9
./configs/example/se.py -c
$LLAMA_path/llama.cpp/main-arm
'--options=-m$LLAMA_path/llama-2-7b-chat.Q2_K.gguf -p Hi -n 16 -t 8'
--cpu-type=ArmAtomicSimpleCPU --mem-size=8GB -n8
如上圖所示,8核都跑起來(lái)了,處理到Hi這個(gè)token的時(shí)候,CPU0執(zhí)行了2.9 Billion指令,相對(duì)于4核時(shí)的5.4 Billion約減少了一半。
審核編輯:劉清
-
ARM
+關(guān)注
關(guān)注
134文章
9176瀏覽量
369324 -
gpu
+關(guān)注
關(guān)注
28文章
4783瀏覽量
129382 -
Linux系統(tǒng)
+關(guān)注
關(guān)注
4文章
596瀏覽量
27521 -
大模型
+關(guān)注
關(guān)注
2文章
2567瀏覽量
3190
原文標(biāo)題:大模型筆記【3】 gem5 運(yùn)行模型框架LLama
文章出處:【微信號(hào):處理器與AI芯片,微信公眾號(hào):處理器與AI芯片】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論