一 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量化,跑起來不到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)行起來應(yīng)該只是最前面大模型的輸出。
模型的回答是Hi,I'm a30-year-old male, and 但是我預(yù)期的是8核,實(shí)際上運(yùn)行起來:
可以看出來,實(shí)際上只跑起來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核都跑起來了,處理到Hi這個(gè)token的時(shí)候,CPU0執(zhí)行了2.9 Billion指令,相對(duì)于4核時(shí)的5.4 Billion約減少了一半。
審核編輯:劉清
-
ARM
+關(guān)注
關(guān)注
134文章
9312瀏覽量
375168 -
gpu
+關(guān)注
關(guān)注
28文章
4912瀏覽量
130681 -
Linux系統(tǒng)
+關(guān)注
關(guān)注
4文章
603瀏覽量
28321 -
大模型
+關(guān)注
關(guān)注
2文章
3033瀏覽量
3839
原文標(biāo)題:大模型筆記【3】 gem5 運(yùn)行模型框架LLama
文章出處:【微信號(hào):處理器與AI芯片,微信公眾號(hào):處理器與AI芯片】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
RISC-V 跑大模型(三):LLaMA中文擴(kuò)展

【飛騰派4G版免費(fèi)試用】仙女姐姐的嵌入式實(shí)驗(yàn)室之五~LLaMA.cpp及3B“小模型”O(jiān)penBuddy-StableLM-3B
無法在OVMS上運(yùn)行來自Meta的大型語言模型 (LLM),為什么?
在gem5中支持Arm TME的工作資料推薦
SECS/GEM標(biāo)準(zhǔn)模型分析及應(yīng)用

Gem5 Arm Fullsystem仿真
Meta發(fā)布開源大模型Code Llama 70B
Meta Llama 3基礎(chǔ)模型現(xiàn)已在亞馬遜云科技正式可用
英偉達(dá)發(fā)布AI模型 Llama-3.1-Nemotron-51B AI模型
亞馬遜云科技正式上線Meta Llama 3.2模型
亞馬遜云科技上線Meta Llama 3.2模型
Llama 3 語言模型應(yīng)用
Llama 3 模型訓(xùn)練技巧
用Ollama輕松搞定Llama 3.2 Vision模型本地部署

評(píng)論