๊ฐค๋ญ์ S24 ์๋ฆฌ์ฆ ์ถ์ ์ดํ๋ก On-Device AI๊ฐ ๊ตญ๋ด์์ ์ธ๊ธ๋๋ ๊ฒ์ ์ฌ๋ฌ ๋ฒ ๋ดค๋๋ฐ, ์๊ฐ์ด ์ข ์์ด์ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด ์์์ ๊ฒฝ๋ ๋ชจ๋ธ์ธ llama ์ธ์ด๋ชจ๋ธ์ ๊ฐ๋จํ๊ฒ ์คํํด๋ณด์๋ค. Ollama๋ฅผ ์ฌ์ฉํ์๋๋ฐ, Nexa SDK๋ Samsung One, Optimum... ๋ญ ์ฌ๋ฌ ํด์ด ์๋ ๊ฒ ๊ฐ๋ค.
- ์ฐธ๊ณ ๋ฌธํ์์๋ raspberry pi 4์ ์ค๋ฒํด๋ฌํน ์์ ์ ํ์ง๋ง, ์ ํ๊ณ ํ ์คํธ๋ฅผ ์ํํ๋ค.
- ์ค๋ฒํด๋ฌํน์ ํ๊ณ ์ ํ๋ฉด raspberry pi 4์ ๋ฐฉ์ดํ๊ณผ ํฌ์ ๋ถ์ฐฉํด์ผํ๋ค.
Swap ๋ฉ๋ชจ๋ฆฌ ํ์ฅ
- ์ค์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋๋ ค์ application ๊ฐ ์ถฉ๋์ ๋ฐฉ์งํ๋ค.
sudo fallocate -l 10G /swapfile # swap ๋ฉ๋ชจ๋ฆฌ 10G ํ ๋น sudo chmod 600 /swapfile # root ๊ถํ ์ค์ sudo mkswap /swapfile # ์์ฑ sudo swapon /swapfile # ํ์ฑํ
sudo swap --show # swap ํํฐ์ ๊ณผ ๋ฉ๋ชจ๋ฆฌ ํ์ธ sudo swapoff -a # swap ๋ฉ๋ชจ๋ฆฌ ๋นํ์ฑํ sudo rm /swapfile # swap file ์ญ์
Ollama ์ค์น
- Ollama๊ฐ port 11434๋ฅผ ์ฌ์ฉํ๋ฏ๋ก ํฌํธ๋ฅผ ๋ฏธ๋ฆฌ ์ด์ด ์ธ๋ฐ์ด๋ ์ฐ๊ฒฐ์ ํ์ฉํจ
# ufw ์ฌ์ฉ ๋ฐฉ๋ฒ sudo ufw allow 11434/tcp # ๋์ฒด - iptables sudo iptables -I INPUT 1 -p tcp --dport 11434 -j ACCEPT sudo iptables -nL # ํ์ธ
- ์ค์น
curl -fsSL https://ollama.com/install.sh | sh
- raspberry pi ์๋ ๊ธฐ๋ณธ์ ์ผ๋ก gpu๊ฐ ํ์ฌ๋์ด ์์ง ์์ผ๋ฏ๋ก cpu-only mode๋ก ์คํ๋๋ค.
ollama serve
๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํด์ ์์ํ ์ ์๋๋ฐ, ๊ธฐ๋ณธ์ ์ผ๋ก๋ ์๋น์ค๋ก ๋์ํ๋ค. serveํ์ ๋ ํฌํธ ๋ฐ์ธ๋๋์ด ์๋ค๊ณ ๋งํ๋ฉดsystemctl status ollama
๋ก ์ํ๋ฅผ ํ์ธํด๋ณด์. ์ด๋ฏธ ์คํ ์ค์ผ ์ ์๋ค.
๋ชจ๋ธ ๋ค์ด๋ก๋
- llama3.2:1b : 10์ต ๊ฐ ํ๋ผ๋ฏธํฐ, 1.3G
ollama pull llama3.2:1b
- llama3.2:3b : 30์ต ๊ฐ ํ๋ผ๋ฏธํฐ, 2G
ollama pull llama3.2:3b
๋ชจ๋ธ ์ฌ์ฉ
ollama run llama3.2:3b >> ...
ํ๊ธฐ
- ์๋ฌด๋๋ raspberry pi ์ ๋น์ฝํ cpu๋ง์ผ๋ก ์คํํ๊ธฐ ๋๋ฌธ์ ๋ชน์ ๋๋ฆฌ์ง๋ง, ๊ทธ๋๋ ์์๋ณด๋ค ํจ์ฌ ๊ด์ฐฎ์๋ค. 1b ๋ชจ๋ธ๋ณด๋ค๋ 3b ๋ชจ๋ธ์ด ํ์คํ ์ํฉ์ ๋ฐ๋ฅธ ์ ํํ ๋๋ต์ ๋ด๋๋ ๊ฒ์ ํ์ธํ ์ ์์๋ค.
- ex) ๋๋คํ sf ์ํ ํ๋๋ฅผ 3~4๊ฐ ์ํ์ค๋ก ์์ฝํด์ค.
- llama3.2:1b - 3~4๊ฐ์ sf ์ํ๋ฅผ ๊ฐ๊ฐ 1๊ฐ ์ํ์ค๋ก ์์ฝ
- llama3.2:3b - 1๊ฐ์ sf ์ํ๋ฅผ 4๊ฐ ์ํ์ค๋ก ์์ฝ
- ex) ๋๋คํ sf ์ํ ํ๋๋ฅผ 3~4๊ฐ ์ํ์ค๋ก ์์ฝํด์ค.
- ํ๊ตญ์ด๋ ์ง์์ด ์๋๋ค๊ณ ๋ด์ผํ๋ค.
- ์์ ์ธ๋ก ๊ฒฐ๊ณผ๊ฐ ์ข์๋ค. ๋ฒค์น๋งํฌ๋ก ๋ดค์ ๋๋ ํฌ๊ฒ ๊ธฐ๋ํ์ง ์์๋๋ฐ ์๋๋ง ์กฐ๊ธ ๋ ๋นจ๋ผ์ง๋ค๋ฉด ์ ์ฉํ๊ฒ ์ธ ์ ์์ ๊ฒ ๊ฐ๋ค. ๊ธฐํ๊ฐ ๋๋ค๋ฉด ๋ค๋ฅธ on-device ai ๋ชจ๋ธ์ ํ์ฉํ ํ๋ก์ ํธ๋ฅผ ์งํํด๋ด๋ ์ข์ ๊ฒ ๊ฐ๋ค.
How to install and Run Llama 3.2 1B and 3B Large Language Models (LLMs) on Raspberry Pi 4 and Linux Ubuntu – Fusion of Enginee
In this Large Language Model (LLM) and machine learning tutorial, we explain how to run Llama 3.2 1B and 3B LLMs on Raspberry Pi in Linux Ubuntu. In this tutorial, we use Raspberry Pi 4. However, the performance and speed of running the models will be bett
aleksandarhaber.com