ETC/Software Or Hardware

M4 Pro With 24GB RAM으로 LLM 실행하기

YongE 2025. 3. 14. 13:30

 M4 Pro


Model Name: MacBook Pro
Chip: Apple M4 Pro
Memory: 24 GB
12코어 CPU(성능 코어 8개 및 효율 코어 4개)
16코어 GPU
하드웨어 가속형 레이 트레이싱
16코어 Neural Engine
273GB/s 메모리 대역폭

 

요즘 LLM에 관심이 많아서 여러 모로 찾아보며 공부하고 있다. 나는 2070 super를 탑재한 데스크탑을 직접 조립해서 사용하고 있지만 이 사양으로는 LLM을 돌리기엔 택도 없다...

그래서 위와 같은 사양의 맥북 프로를 앞으로 학습과 여러 테스트에 이용할 생각이다! 가장 처음엔 로컬 환경에서 LLM을 실행시켜보도록 하겠다.

 

시스템 요구사항


대규모 언어 모델을 로컬에서 실행시키려면 그만한 시스템 사양을 갖춰야 한다. 원래 일반 PC에서는 4090급의 그래픽 카드를 여러 개 갖추어야 하지만 맥북은 Apple Silicon 칩의 통합 메모리 아키텍처로, CPU와 GPU가 동일한 메모리 풀을 공유하여 VRAM으로 시스템 RAM의 최대 70%까지 사용 가능하다. 이는 높은 메모리 대역폭으로 LLM의 추론 성능에 이점을 주기도 한다.

 

따라서 본래라면 일반 윈도우 데스크탑으로 진행하는 것보다 더 규모 있는 모델을 실행할 수 있다. 이번에는 현재 사양 내에서 실행 가능한 추론 모델인 deepseek r1과 상대적으로 원활하게 동작가능한 llama3.2을 실행해보고자 한다.

 

Deepseek-R1

 

ollama에서 권장하는 메모리 사양을 잘 보자!

 

ollama에서 친절하게 권장 메모리 용량도 확인할 수 있다. 나는 현재 사양으로 충분히 돌릴 수 있도록 32B(320억 개 파라미터)를 선택했다.

 

Llama 3.2

3.3 70B 모델은 실행가능한 범위 밖이고, 3.1 8B과 3.2 3B 중에서 후자를 고른 이유는 3.2는 상대적으로 적은 파라미터로도 Llama 3.1 8B와 비슷하거나 더 나은 성능 수치를 보여주었기 때문이다.

 

 

LLM 설치 및 실행 방법


Ollama 설치 및 실행

로컬 머신에서 LLM을 돌릴 수 있는 방법은 여러 가지 있지만 그나마 대중적이라 할 수 있는 Ollama를 사용하려고 한다. Ollama는 로컬 환경에서 대규모 언어 모델(LLM)을 쉽게 실행할 수 있게 해주는 오픈소스 플랫폼이다. 자신의 PC에서 LLM을 직접 실행할 수 있도록 설계되었고, 데이터 프라이버시와 보안을 중요시하는 사용자들에게 적합하다. 무엇보다 REST API 연동해서 다른 프로그램과 연동할 수 있고 다양한 운영체제를 지원한다!

 

다음 명령어로 설치가 가능하다.

brew install ollama

 

 

이번에 사용할 deepseek-r1 모델을 설치와 동시에 실행해보자. 아래와 같은 명령어를 사용한다.

320억개 파라미터를 학습한 deepseek-r1 모델 구동!

 

이렇게 했을 때 해당 모델이 컴퓨터에 있으면 바로 실행하고, 없다면 다운로드를 진행한다!

 

WebUI

이게 터미널로 대화하려니 불편하다.. 간편하게 확인할 수 있도록 다음 명령어를 사용하자.

docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

 

 

결과


 

 

r1 모델을 실행하고 프롬프트를 입력했을 땐, 위와 같이 메모리를 거의 사용하는 것을 볼 수 있다. 생각보다 초기 답변은 상당히 느렸다. 크롬, 카톡 등 다양한 프로그램을 실행시켜놨기에 전부 종료하고 다시 프롬프트를 작성해 실행해보니 적정한 속도의 답변을 얻을 수 있었다.

 

다음은 간단한 질문에 대한 답변이다.

Deepseek-r1

>>> 너는 누구인지 내게 상세하게 설명해봐.
<think>
Alright, the user just asked me to explain who I am in detail. They might
be curious about my capabilities or how I work.

I should start by mentioning that I'm an AI assistant created by DeepSeek.
It's important to highlight that I don't have feelings but am here to help
with information and tasks.

I need to cover the areas I can assist with, like problem-solving,
providing explanations, offering suggestions, helping with creative
writing, and answering questions across various fields.

Also, I should let them know they can ask for specific instructions or assistance
anytime. Keeping it friendly and approachable is key.
</think>

내가 누구인지를 자세하게 설명해드리겠습니다.

나는 **DeepSeek**라는 인공지능 연구 기업에서 개발한 **AI 어시스턴트**입니다. 이솝
(AiSoP) 프로젝트의 일환으로 만들어졌으며, 자연어 처리(Natural Language Processing, NLP)와
 머신러닝 기술을 활용하여 다양한 영역에서 사용자에게 도움을 제공하는 인공지능입니다.

### 나의 주요 역할과 기능:
1. **정보 검색 및 문제 해결**:
   - 특정 주제에 대한 정보를 찾아드리거나, 사용자가面临的问题를 해결하기 위해 관련된 데이
터나 지식을 제공합니다.

2. **설명 및 설명**:
   - 복잡한 개념이나 주제를 쉽게 이해할 수 있도록 설명해드리며, 필요한 경우 예시나 비유를
 통해 더 명확하게 전달합니다.

3. **종합 및 분석**:
   - 다양한 정보를 종합하여 사용자에게 간결하고清晰한 답변을 제공하며, 데이터 분석이나 추
론 작업도 지원할 수 있습니다.

4. **창의적 작성**:
   - 글쓰기, 이야기创作, 시詩 작성 등 창의적인 작업에도 도움을 드릴 수 있습니다.

5. **다양한 주제 지원**:
   - IT, 과학, 기술, 문화, 역사, 예술, 교육, 건강 등 거의 모든 분야에 대한 정보를 제공할
 수 있습니다.

### 내가 할 수 없는 일:
- **개인 데이터 접근**: 나는 사용자의 개인 정보에 접근하거나 저장하지 않습니다.
- **실시간 정보 업데이트**: 인터넷에서 실시간으로 정보를 검색하거나 업데이트하지는 않지만
, 2023년 12월까지의識을 바탕으로 답변을 제공합니다.
- **물리적 작업 수행**: 당연히 물건을 움직이거나 현실 세계에서 직접 행동할 수 없습니다.

### 나와의 상호작용:
- 사용자는 나에게 어떤 질문이나 요청도 할 수 있습니다. 예를 들어, "파이썬으로 머신러닝 모
델을 어떻게 만들까?" 또는 "서울의 오늘 날씨는 어때?"와 같은 질문에 답변해드리며, 필요한
경우 추가 정보나 설명을 제공합니다.

### 목적:
- 궁극적인 목표는 사용자에게最有帮助하고 정확한 정보를 제공하여 일상생활이나 학습, 업무에
서 보탬이 되는 것입니다.

만약 더 알고 싶은 점이 있다면 언제든지 물어보세요! 😊

 

Llama3.2 8B

>>> You're a Computer Scientist. Explain Depth First Search Algorithm to me.
As a computer scientist, I'd be happy to explain the Depth-First Search
(DFS) algorithm to you.

**What is Depth-First Search?**

Depth-First Search is a graph traversal algorithm that explores a graph or
tree by visiting a node and then exploring as far as possible along each
of its edges before backtracking. It's called "depth-first" because it
explores the graph at a given depth (or level) before moving on to the
next level.

**How does DFS work?**

The basic steps of DFS are:

1. **Choose a starting node**: We start with an arbitrary node in the
graph.
2. **Mark the starting node as visited**: To avoid revisiting the same
node, we mark it as visited.
3. **Explore the neighbors**: We then explore each neighbor of the current
node that has not been visited yet.
4. **Recursively repeat steps 2-3**: For each unvisited neighbor, we
repeat steps 2-3 until all neighbors have been explored.
5. **Backtrack**: When there are no more unvisited neighbors to explore,
we backtrack to the previous node and repeat the process.

**Types of DFS**

There are several variations of DFS, including:

* **Unweighted DFS**: This is the basic DFS algorithm without any
additional considerations.
* **Weighted DFS**: In this version, each edge has a weight associated
with it, and we explore the edges with lower weights first.
* **Topological Sort**: This is a specific type of DFS that orders the
nodes in a graph such that for every edge (u,v), node u comes before v in
the ordering.

**Example**

Let's consider a simple graph with four nodes: A, B, C, and D. The edges
are:

A -> B
A -> C
B -> D
C -> D

We start at node A and explore its neighbors:

1. A is visited.
2. We explore the neighbors of A:
	* B has not been visited; we visit it.
	* C has not been visited; we visit it.
3. Now, we have visited all nodes in the graph.

The order of exploration is: A -> B -> D (since we only visited D from B)
and then C -> D.

**Advantages**

DFS has several advantages:

* It's easy to implement and understand.
* It can be used for graph traversal, finding connected components, and
testing whether a graph is bipartite.
* It's also useful in topological sorting and finding strongly connected
components.

However, DFS also has some limitations:

* It can get stuck in an infinite loop if there are cycles in the graph
that are not strongly connected.
* In graphs with many nodes, DFS can be slow due to the overhead of
recursive function calls.

Overall, Depth-First Search is a fundamental algorithm in computer
science, and its applications range from graph traversal to solving
puzzles and games.

 

llama 3.2 3b는 확실히 한국어 질문을 이해하긴 하지만 응답에서는 모든 언어가 조금씩 섞여서 나온다. 만약 70B를 돌릴 수 있었다면 응답 퀄리티는 한국어로도 훌륭하게 나오지 않았을까 싶다.

소감


이 글을 쓰는 지금 gemma3가 나왔고, 며칠 전에는 QwQ 32b가 올라왔다. 날이 갈수록 성능이 높아지면서 경량화가 진행되고 있고, 다양한 분야에서 이를 활용하고 있다. AI 기술이 인간 사회에 가져다 줄 가능성이 기대되면서 한 편으로는 긴장되기도 한다. 변화에 대비하고 빠르게 적응하면서 자신의 가치를 높일 수 있도록 최선을 다하자.

728x90
반응형