728x90
반응형

 

이번 수요일(2025년 3월 12일)에 발표되었습니다. 1B, 4B, 12B, 27B의 4가지 크기로 출시되었으며, 사전 학습된 버전과 지침 미세 조정된 버전이 있습니다. 모델 4B, 12B, 27B는 확장된 컨텍스트 창(최대 128K)과 다중 모달리티를 제공합니다.

 

Macbook M1 + Ollama + gemma3 로 Multimodal 이미지 처리를 테스트해보겠습니다

 

Ollama Gemma3

 

Gemma is a lightweight, family of models from Google built on Gemini technology. The Gemma 3 models are multimodal—processing text and images—and feature a 128K context window with support for over 140 languages. Available in 1B, 4B, 12B, and 27B parameter sizes, they excel in tasks like question answering, summarization, and reasoning, while their compact design allows deployment on resource-limited devices.

 

Gemma는 Google이 Gemini 기술을 기반으로 개발한 경량 모델 계열입니다. Gemma 3 모델은 멀티모달 모델로, 텍스트와 이미지를 처리할 수 있으며 128K 컨텍스트 윈도우를 제공하고 140개 이상의 언어를 지원합니다. 1B, 4B, 12B, 27B 파라미터 크기로 제공되며, 질문 응답, 요약, 추론과 같은 작업에서 뛰어난 성능을 발휘합니다. 또한, 컴팩트한 설계로 인해 자원이 제한된 장치에서도 실행할 수 있습니다.

 

더욱 상세한 모델 설명을 보고자 한다면 "Gemma 3 기술 보고서 ​​PDF"를 참고하세요.

 

Models

 

Text

- 1B parameter model (32k context window)

Multimodal (Vision)

- 4B parameter model (128k context window)

- 12B parameter model (128k context window)

- 27B parameter model (128k context window)

 

Default 모델은 4B 모델이고 1B는 text 이고 4B 사이즈부터 Multimodal 모델입니다. 4B 모델을 받습니다.

 

ollama run gemma3:4b

dongsik@dongsikleeui-MacBookPro % ollama run gemma3:4b
pulling manifest
pulling 377655e65351... 100% ▕█████████████████████████████████████████████████▏ 3.3 GB
pulling e0a42594d802... 100% ▕█████████████████████████████████████████████████▏  358 B
pulling dd084c7d92a3... 100% ▕█████████████████████████████████████████████████▏ 8.4 KB
pulling 0a74a8735bf3... 100% ▕█████████████████████████████████████████████████▏   55 B
pulling ffae984acbea... 100% ▕█████████████████████████████████████████████████▏  489 B
verifying sha256 digest
writing manifest
success
>>> Send a message (/? for help)

 

설치 확인

dongsik@dongsikleeui-MacBookPro % ollama --version
ollama version is 0.6.0
dongsik@dongsikleeui-MacBookPro % ollama list
NAME                        ID              SIZE      MODIFIED
gemma3:4b                   c0494fe00251    3.3 GB    41 minutes ago
dongsik@dongsikleeui-MacBookPro %

 

첫번째 이미지 분석입니다. 

 

멋지고 쿨한 선글라스를 쓴 3마리 고양이입니다.

사진에서 어떤 설명을 하는지 먼저 볼까요? 우선 영어로 질문해보겠습니다 "Describe what you see in this picture"

안경을 쓴 멋진 고양이 3마리 - 출처:  vecteezy 의 yganko

 

dongsik@dongsikleeui-MacBookPro % ollama run gemma3:4b
>>> Describe what you see in this picture vecteezy_three-cool-cats.jpg
Okay, I've analyzed the image vecteezy_three-cool-cats.jpg. Here's a description of what I see:

**Overall Impression:**

The image is a playful and vibrant digital illustration featuring three stylized cats.
It has a cartoonish, slightly retro feel, likely intended for a fun or whimsical design.

**Detailed Description:**

*   **Subject:** There are three cats, each with a distinct style.
    *   **Cat 1 (Left):** This cat is a bright, almost neon blue with a sleek, modern design.
        It has large, expressive eyes and a confident pose, looking directly at the viewer.   
    *   **Cat 2 (Center):** This cat is a vibrant pink with a more rounded, friendly appearance.
        It has a slightly mischievous expression and is playfully leaning forward.
    *   **Cat 3 (Right):** This cat is a bright yellow with a more geometric, almost robotic-looking 
        design. It has a slightly tilted head and a curious expression.

*   **Style:** The illustration is clearly digital and stylized. 
    The lines are clean and bold, and the colors are saturated. 
    It resembles a vector graphic, which means it can be scaled up or down without losing quality.

*   **Background:** The background is a solid, dark gray, which helps the bright colors of the cats 
    to pop.

*   **Composition:** The cats are arranged in a horizontal line, with the central cat slightly closer
    to the viewer.

*   **Overall Tone:** The image has a cheerful and energetic tone. It's designed to be appealing and fun.

**In essence, it's a cute and colorful digital illustration of three stylized cats, 
  likely intended for use in a graphic design project.**

Would you like me to focus on a specific aspect of the image, such as the style, color palette, 
or potential uses for this illustration?

>>> Send a message (/? for help)

 

Macbook M1에서 처리속도는 꽤 빠릅니다. 최초 질문에 응답하는데 20초 정도에 위 설명을 마쳤습니다.

>>> 이 그림에서 보이는 것을 한글로 설명하세요 vecteezy_three-cool-cats.jpg
네, vecteezy_three-cool-cats.jpg 그림에 보이는 것을 설명해 드리겠습니다.

이 그림은 세 마리의 귀여운 고양이 그림입니다. 각 고양이는 다른 색깔과 스타일을 가지고 있습니다.

*   **왼쪽 고양이:** 밝은 파란색으로, 세련되고 현대적인 느낌을 줍니다. 눈이 크고 자신감 있는 표정을 짓고 있습니다.
*   **중간 고양이:** 밝은 분홍색으로, 둥글고 친근한 느낌을 줍니다. 장난기 넘치는 표정으로 앞으로 기대어 있습니다.
*   **오른쪽 고양이:** 밝은 노란색으로, 기하학적인 디자인을 하고 있습니다. 머리를 살짝 기울여 호기심 있는 표정을 짓고 있습니다.

전체적으로 디지털 그림이며, 선이 깔끔하고 색상이 강렬하게 표현되어 있습니다. 배경은 어두운 회색으로, 고양이들의 색깔을 더욱 돋보이게 합니다.

전반적으로 귀엽고 활기찬 느낌을 주는 그림입니다.

혹시 그림의 특정 부분에 대해 더 자세한 설명을 원하시면 말씀해주세요.

>>> Send a message (/? for help)

 

오른쪽 고양이의 썬글라스 색을 물어봤는데 제눈에는 노란색으로 보입니다. gemma3는 밝은 금색(Gold) 라고 합니다.

아마 저색이 금색이겠죠?

>>> 이 그림에서 오른쪽 고양이의 썬글라스 색깔을 알려주세요 vecteezy_three-cool-cats.jpg
오른쪽 고양이의 썬글라스 색깔은 **금색 (Gold)** 입니다.

사진을 자세히 살펴보니, 썬글라스 렌즈와 프레임이 모두 밝은 금색으로 되어 있습니다.

>>> Send a message (/? for help)

>>> Please tell me the color of the sunglasses on the cat on the right in this picture. vecteezy_three-cool-cats.jpg
The sunglasses on the cat on the right are **gold**. They have a bright, metallic gold color.

>>>

 

이번엔 표가 있는 이미지를 가지고 테스트 해보겠습니다.

 

>>> Describe the content of the given image ~/gemma3_prerequisites.jpeg
Added image '/Users/dongsik/workspace/ekyc/gemma3_prerequisites.jpeg'
The image is a table outlining the recommended GPU requirements for different model sizes (in billions of parameters) for a Text-to-Text model.
Here’s a breakdown of the information presented:

*   **Parameters (Billion):** The table lists the model size in billions of parameters (1B, 4B, 12B, 27B).
*   **VRAM Requirement (Text-to-Text):** This column specifies the amount of VRAM (Video RAM) needed to run the model for Text-to-Text tasks.
*   **VRAM Requirement (Image-to-Text):** This column specifies the amount of VRAM needed to run the model for Image-to-Text tasks.
*   **Recommended GPU:** This column lists the recommended GPU based on the VRAM requirement.

Essentially, it’s a chart showing the relationship between model size, VRAM requirements, and the corresponding GPU needed to run the model
effectively.

Do you want me to elaborate on any specific aspect of this table, such as the VRAM requirements for a particular model size or the GPU
recommended for a specific task?

>>>

 

>>> 주어진 이미지의 내용을 설명하세요. /Users/dongsik/workspace/ekyc/gemma3_prerequisites.jpeg
Added image '/Users/dongsik/workspace/ekyc/gemma3_prerequisites.jpeg'
다음은 이미지의 내용에 대한 설명입니다.

**표는 텍스트-투-텍스트 및 이미지-투-텍스트 작업에 필요한 GPU 사양을 나타냅니다.**

*   **Parameters (Billions):** 모델의 파라미터 수를 나타냅니다.
*   **VRAM Requirement (Text-to-Text):** 텍스트-투-텍스트 작업에 필요한 VRAM(비디오 RAM)의 양을 나타냅니다.
*   **VRAM Requirement (Image-to-Text):** 이미지-투-텍스트 작업에 필요한 VRAM의 양을 나타냅니다.
*   **Recommended GPU:** 주어진 파라미터 수에 맞는 VRAM 요구 사항을 충족하는 데 권장되는 GPU 모델을 나열합니다.

**주요 관찰 사항:**

*   파라미터 수가 증가함에 따라 텍스트-투-텍스트 및 이미지-투-텍스트 작업 모두에 필요한 VRAM 요구 사항이 크게 증가합니다.
*   더 큰 모델은 효율적으로 작동하기 위해 훨씬 더 많은 VRAM이 필요합니다.

이 표가 도움이 되었기를 바랍니다!

>>>

 

그럼 마지막으로 이미지에서 답을 찾아오는 질문을 해보겠습니다,

"그림에서 4B 모델을 image to text 하기위해 필요한 VRAM은 은 얼마인가요?"  네, 답은 10.4B 입니다.

 

결과를 보시죠.

>>> 그림에서 4B 모델을 image to text 하기위해 필요한 VRAM은 은 얼마인가요?
그림에 따르면 4B 모델을 image to text 하기 위해 필요한 VRAM은 10.4 GB입니다.

>>>

 

오....!!!

728x90
반응형
728x90
반응형

Gemma - Run with Ollama (with Colab)

Google Colab에서 Ollama로 Gemma 실행하기

이 노트북은 Ollama를 사용하여 Gemma 모델에서 추론을 실행하는 방법을 보여줍니다 . Ollama는 로컬에서 LLM을 실행하기 위한 사용하기 쉬운 솔루션이며 Gemma가 기본으로 지원됩니다.

 

Gemma는 Google DeepMind에서 구축한 경량의 최첨단 개방형 모델 제품군입니다. 버전 1.1로 업데이트되었습니다.

Gemma는 2b 및 7b 매개변수 크기로 제공됩니다.

  • ollama run gemma:2b
  • ollama run gemma:7b (default)

gemma 모델정보 확인

gemma 7b

 


gemma 2b

 

Colab 링크

Ollama 설치

공식 설치 스크립트를 통해 Ollama를 설치합니다.

!curl -fsSL https://ollama.com/install.sh | sh
!curl -fsSL https://ollama.com/install.sh | sh
>>> Installing ollama to /usr/local
>>> Downloading Linux amd64 bundle
############################################################################################# 100.0%
>>> Creating ollama user...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
WARNING: Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.

 

Ollama 시작 (실행)

nohup을 사용하여 백그라운드에서 Ollama를 시작합니다. API 서비스 포트는 11434 입니다.

!nohup ollama serve > ollama.log &
nohup: redirecting stderr to stdout

 

Ollama 모델 목록 확인

!ollama list
NAME    ID    SIZE    MODIFIED

 

추론

명령행(command line)을 이용해서 gemma 7B 모델을 받고 추론을 실행 

!ollama run gemma:7b "대한민국의 수도는 어디야?" 2> ollama.log
대한민국의 수도는 서울입니다.</end_of_turn>

 

영어로 질문해봅니다.

ollama run gemma:7b "What is the capital of Korea?" 2> ollama.log
The capital of Korea is **Seoul**. It is the largest and most populous city in the country.

 

실행한 모델 확인

!ollama list
NAME        ID              SIZE      MODIFIED       
gemma:7b    a72c7f4d0a15    5.0 GB    41 seconds ago

 

REST 엔드포인트를 통해 응답 생성

!curl http://localhost:11434/api/generate -d '{ \
  "model": "gemma:7b", \
  "prompt":"프랑스의 수도는 어디야?" \
}'
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.191815259Z","response":"프","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.238195689Z","response":"랑","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.284446079Z","response":"스","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.330415772Z","response":"의","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.376395312Z","response":" 수","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.404399661Z","response":"도","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.431299982Z","response":"는","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.45782401Z","response":" 파","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.487122476Z","response":"리","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.514609513Z","response":"(","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.540247914Z","response":"Paris","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.565826889Z","response":")","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.592181701Z","response":"입니다","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.619404725Z","response":".","done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:43:59.646506512Z","response":"","done":true,"done_reason":"stop","context":[968,2997,235298,559,235298,15508,235313,1645,108,237964,239566,236354,236137,22618,236840,236214,53355,238173,238305,181537,615,235298,559,235298,15508,235313,108,235322,2997,235298,559,235298,15508,235313,2516,108,237964,239566,236354,236137,22618,236840,236214,59994,236432,235278,29437,235275,47555,235265],"total_duration":650239442,"load_duration":39196479,"prompt_eval_count":37,"prompt_eval_duration":114387000,"eval_count":15,"eval_duration":454674000}

 

REST 엔드포인트를 통해 Gemma와 채팅

!curl http://localhost:11434/api/chat -d '{ \
  "model": "gemma:7b", \
  "messages": [ \
    { "role": "user", "content": "스페인의 수도는 어디야?" } \
  ] \
}'
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.627626051Z","message":{"role":"assistant","content":"스"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.673755341Z","message":{"role":"assistant","content":"페"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.719617417Z","message":{"role":"assistant","content":"인"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.765324012Z","message":{"role":"assistant","content":"의"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.810472803Z","message":{"role":"assistant","content":" 수"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.842618919Z","message":{"role":"assistant","content":"도"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.865453528Z","message":{"role":"assistant","content":"는"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.892675721Z","message":{"role":"assistant","content":" 마"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.922734686Z","message":{"role":"assistant","content":"드"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.94894934Z","message":{"role":"assistant","content":"리"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:05.974847995Z","message":{"role":"assistant","content":"드"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:06.000792996Z","message":{"role":"assistant","content":"입니다"},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:06.027347034Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"gemma:7b","created_at":"2024-09-20T07:44:06.054820407Z","message":{"role":"assistant","content":""},"done_reason":"stop","done":true,"total_duration":612398322,"load_duration":38850549,"prompt_eval_count":37,"prompt_eval_duration":104264000,"eval_count":14,"eval_duration":427080000}
 
728x90
반응형
728x90
반응형

설정

Colab 런타임 선택

Gemma 모델을 실행하기에 충분한 리소스가 포함된 Colab 런타임이 필요합니다. 이 경우 T4 GPU를 사용할 수 있습니다.

  1. Colab 창 오른쪽 상단에서 ▾(추가 연결 옵션)을 선택합니다.
  2. "런타임 유형 변경"을 선택합니다.
  3. 하드웨어 가속기에서 T4 GPU를 선택합니다.
런타임 유형 변경

T4 GPU 선택

 


런타임 유형 T4 선택완료

 

Gemma setup

Gemma 설정의 설정 지침을 완료해야 합니다. Gemma 설정 지침은 다음을 수행하는 방법을 보여줍니다.

  • kaggle.com에서 Gemma에 액세스하세요.
  • Gemma 2B 모델을 실행하기에 충분한 리소스가 있는 Colab 런타임을 선택하세요.
  • Kaggle 사용자 이름과 API 키를 Colab 비밀로 생성하고 구성합니다.

Gemma 설정을 완료한 후 다음 섹션으로 이동하여 Colab 환경에 대한 환경 변수를 설정합니다.

 

 

Kaggle API Key 생성

 

1. Kaggle에 로그인한후 Your Profile 선택

My Pofile

2. Settings 클릭해서 이동

3. API 항목중 Create New Token 클릭

4. 로걸에 다운로드된 kaggle.json 파일에서 username과 key값을 저장합니다.

 

{"username":"dongshik","key":"4a566********************9a7be40"}

 

 

자격 증명(credentials) 구성

Kaggle 자격 증명을 Colab Secrets 관리자에 추가하여 안전하게 저장합니다.

 

  1. Google Colab 노트북을 열고 왼쪽 패널에서 🔑 Secrets 탭을 클릭합니다.
  2. 새 비밀번호 만들기 (+새 보안 비밀 추가) : KAGGLE_USERNAME 및 KAGGLE_KEY
  3. 사용자 이름을 KAGGLE_USERNAME에 복사하여 붙여넣으세요.
  4. KAGGLE_KEY에 키를 복사하여 붙여넣으세요.
  5. secret 에 대한 "노트북 액세스"를 허용하려면 왼쪽에 있는 버튼을 전환하세요.
Kaggle API Key 설정

 

Python에서 Kaggel Cerdential key 가져오기

import os
from google.colab import userdata

# Note: `userdata.get` is a Colab API. If you're not using Colab, set the env
# vars as appropriate for your system.
os.environ["KAGGLE_USERNAME"] = userdata.get("KAGGLE_USERNAME")
os.environ["KAGGLE_KEY"] = userdata.get("KAGGLE_KEY")

 

실행했을때 403 Client Error 발생하는경우 kaggle keras gemma 2에 대한 Access 권한이 없기때문입니다.

이럴때 kaggle keara gemma 2로 가서 Access 권한을 요청합니다.

...

You don't have permission to access resource at URL: https://www.kaggle.com/models/keras/gemma2/keras/gemma2_9b_en/2
Please make sure you are authenticated if you are trying to access a private resource or a resource requiring consent.

 

https://www.kaggle.com/models/keras/gemma2

Request Access 클릭

 

 

생략...

Term and Condition Accept

 

권한이 부여된것 확인

728x90
반응형
728x90
반응형

M1 교체 이전에 사용하던 MacBook Pro 2015에서 Ollama로 Gemma2를 구동해봤습니다.

MacBook Pro 2015

 

Processor: Multi-core CPU (Intel i5/i7/i9 or AMD equivalent)
Memory: You should have at least 8 GB of RAM available to run the 7B models, 16 GB to run the 13B models, and 32 GB to run the 33B models.
Storage: At least 20 GB of free space on an SSD
Operating System: Recent versions of Windows, macOS, or Linux

 

Python 3.11.4로 생성된 Conda 가상환경으로 실행합니다.

(base) Gabrielui-MacBookPro:~ gabriel$ conda env list
# conda environments:
#
base                  *  /usr/local/anaconda3
gabriel                  /usr/local/anaconda3/envs/gabriel

(base) Gabrielui-MacBookPro:~ gabriel$ conda activate gabriel
(gabriel) Gabrielui-MacBookPro:~ gabriel$

(gabriel) Gabrielui-MacBookPro:~ gabriel$ python -V
Python 3.11.4

 

세 가지 크기: 2B, 9B 및 27B 파라미터의 모델

셋중에서 9B 모델이 Default 입니다. 

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama --version
ollama version is 0.3.9

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama run gemma2
pulling manifest
pulling ff1d1fc78170... 100% ▕█████████████████████████████████████████████████████████████████▏ 5.4 GB
pulling 109037bec39c... 100% ▕█████████████████████████████████████████████████████████████████▏  136 B
pulling 097a36493f71... 100% ▕█████████████████████████████████████████████████████████████████▏ 8.4 KB
pulling 2490e7468436... 100% ▕█████████████████████████████████████████████████████████████████▏   65 B
pulling 10aa81da732e... 100% ▕█████████████████████████████████████████████████████████████████▏  487 B
verifying sha256 digest
writing manifest
success
>>>

 

다운로드한 모델을 확인합니다.

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama list
NAME         	ID          	SIZE  	MODIFIED
gemma2:latest	ff02c3702f32	5.4 GB	14 minutes ago
(gabriel) Gabrielui-MacBookPro:~ gabriel$

 

 

Ollama + Gemma2 (9B)

ollama run gemma2 로 다운로드한 모델의 정보를 확인합니다.

>>> /show info
  Model
  	arch            	gemma2
  	parameters      	9.2B
  	quantization    	Q4_0
  	context length  	8192
  	embedding length	3584

  Parameters
  	stop	"<start_of_turn>"
  	stop	"<end_of_turn>"

  License
  	Gemma Terms of Use
  	Last modified: February 21, 2024

>>>

 

프롬프트로 질문 "why is the sky blue?"

>>> why is the sky blue?
The sky appears blue due to a phenomenon called **Rayleigh scattering**.

Here's a breakdown:

* **Sunlight:** Sunlight is made up of all the colors of the rainbow.
* **Atmosphere:** When sunlight enters Earth's atmosphere, it collides with tiny air molecules (mainly nitrogen and
oxygen).
* **Scattering:** These molecules scatter the sunlight in all directions.
* **Wavelengths:**  Blue light has a shorter wavelength than other colors in the visible spectrum. Shorter wavelengths are
scattered more effectively by the air molecules.

Therefore, blue light gets scattered much more than other colors, making the sky appear blue to our eyes.

**At sunrise and sunset:** The sunlight travels through more atmosphere to reach us. This means even more blue light is
scattered away, allowing longer wavelengths like orange and red to dominate, resulting in those beautiful hues.

>>> Send a message (/? for help)
Use Ctrl + d or /bye to exit.

 

REST 엔드포인트를 통해 응답 생성

(gabriel) Gabrielui-MacBookPro:~ gabriel$ curl http://localhost:11434/api/generate -d '{
>   "model": "gemma2",
>   "prompt": "Why is the sky blue?"
> }'
{"model":"gemma2","created_at":"2024-09-05T15:30:49.100401Z","response":"The","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:30:49.464952Z","response":" sky","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:30:49.798186Z","response":" appears","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:30:50.143292Z","response":" blue","done":false}



{"model":"gemma2","created_at":"2024-09-05T15:32:05.437344Z","response":" have","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:05.785728Z","response":" any","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:06.14108Z","response":" other","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:06.517148Z","response":" questions","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:06.926336Z","response":"!","done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:07.269795Z","response":"","done":true,"done_reason":"stop","context":[106,1645,108,4385,603,573,8203,3868,235336,107,108,106,2516,108,651,8203,8149,3868,3402,577,476,27171,3151,5231,15599,44957,38497,168428,235248,109,4858,235303,235256,476,25497,235292,109,235287,5231,219715,66058,175521,603,4247,1644,908,576,832,573,9276,576,573,30088,235265,108,235287,5231,30962,235303,235256,117961,66058,3194,33365,30866,573,10379,235303,235256,13795,235269,665,1041,23524,675,16791,2681,24582,591,80711,23584,578,16175,846,108,235287,5231,102164,574,66058,3766,24582,17109,573,33365,575,832,16759,235265,235248,108,235287,5231,10716,181430,235256,66058,7640,2611,919,476,25270,35571,1178,1156,9276,575,573,12918,18303,235265,10323,576,736,235269,665,6803,30390,1683,978,731,573,2681,24582,1178,5543,95178,1154,3118,689,10436,235265,109,688,2339,235269,1212,783,1443,66058,109,651,30390,3868,2611,26676,1167,4628,774,832,16759,235269,3547,573,8203,4824,3868,235265,2625,48825,578,22097,235269,573,33365,37845,1593,978,576,573,13795,235265,1417,3454,573,3868,2611,603,30390,3024,1693,978,235269,15267,573,5543,95178,591,165117,578,72638,235275,577,6378,1167,4628,235269,10241,1941,4964,9276,235265,110,5331,682,1230,1013,692,791,1089,1156,3920,235341],"total_duration":81320587916,"load_duration":42868270,"prompt_eval_count":15,"prompt_eval_duration":3107284000,"eval_count":210,"eval_duration":78169448000}
(gabriel) Gabrielui-MacBookPro:~ gabriel$

 

 

REST 엔드포인트를 통해 Gemma와 채팅

 

(gabriel) Gabrielui-MacBookPro:~ gabriel$ curl http://localhost:11434/api/chat -d '{
>   "model": "gemma2",
>   "messages": [
>     {
>       "role": "user",
>       "content": "why is the sky blue?"
>     }
>   ]
> }'
{"model":"gemma2","created_at":"2024-09-05T15:32:34.118301Z","message":{"role":"assistant","content":"The"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:34.466319Z","message":{"role":"assistant","content":" sky"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:34.821353Z","message":{"role":"assistant","content":" appears"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:35.182394Z","message":{"role":"assistant","content":" blue"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:32:35.523289Z","message":{"role":"assistant","content":" due"},"done":false}

{"model":"gemma2","created_at":"2024-09-05T15:33:50.644094Z","message":{"role":"assistant","content":" if"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:51.039595Z","message":{"role":"assistant","content":" you"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:51.411561Z","message":{"role":"assistant","content":" have"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:51.815174Z","message":{"role":"assistant","content":" any"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:52.152768Z","message":{"role":"assistant","content":" other"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:52.492949Z","message":{"role":"assistant","content":" questions"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:52.915517Z","message":{"role":"assistant","content":"!"},"done":false}
{"model":"gemma2","created_at":"2024-09-05T15:33:53.27064Z","message":{"role":"assistant","content":""},"done_reason":"stop","done":true,"total_duration":80946825634,"load_duration":44007406,"prompt_eval_count":15,"prompt_eval_duration":1749943000,"eval_count":190,"eval_duration":79152305000}
(gabriel) Gabrielui-MacBookPro:~ gabriel$

 

 

Ollama + Gemma 1.1 (2B)

 

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama run gemma:2b
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling manifest
pulling c1864a5eb193... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏ 1.7 GB
pulling 097a36493f71... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏ 8.4 KB
pulling 109037bec39c... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏  136 B
pulling 22a838ceb7fb... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏   84 B
pulling 887433b89a90... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏  483 B
verifying sha256 digest
writing manifest
success
>>> Send a message (/? for help)

 

다운로드한 모델을 확인합니다.

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama list
NAME         	ID          	SIZE  	MODIFIED
gemma:2b     	b50d6c999e59	1.7 GB	3 minutes ago
gemma2:latest	ff02c3702f32	5.4 GB	40 minutes ago
(gabriel) Gabrielui-MacBookPro:~ gabriel$

 

 

Gemma2와 동일한 질문을 합니다. "why is the sky blue?"

>>> why is the sky blue?
The sky appears blue due to Rayleigh scattering.

**Rayleigh scattering** is a scattering phenomenon where light waves are scattered in different directions depending on their wavelength.
Blue light has a shorter wavelength than other colors of light, meaning it scatters more effectively. This is why the sky appears blue.

Here's a more detailed explanation:

* **Sunlight** contains all colors of the rainbow.
* **Blue light** has a shorter wavelength than other colors.
* **When blue light** interacts with molecules in the atmosphere, it **scatters more strongly** than other colors.
* This scattering causes blue light to be scattered **towards the observer**.
* The scattered blue light is what we see in the sky as **blue color**.

**Other factors that contribute to the blue color of the sky:**

* **Dust particles:** Air molecules can also scatter light, but their scattering effect is generally weaker than that of molecules in the
atmosphere.
* **Water droplets:** Water droplets in the atmosphere can also scatter light, but their effect is typically less significant than that of
molecules.
* **Sun's position:** The sky appears blue because the sun is lower in the sky, meaning it is directly overhead. This means that more blue
light reaches our eyes.

In summary, the blue color of the sky is due to Rayleigh scattering of light by molecules in the atmosphere, which primarily results from
the shorter wavelength of blue light.

>>> Send a message (/? for help)

 

실행시에 MacBook의 성능을 확인합니다.

 

실행한 모델 정보 확인

>>> /show info
  Model
  	arch            	gemma
  	parameters      	3B
  	quantization    	Q4_0
  	context length  	8192
  	embedding length	2048

  Parameters
  	repeat_penalty	1
  	stop          	"<start_of_turn>"
  	stop          	"<end_of_turn>"

  License
  	Gemma Terms of Use
  	Last modified: February 21, 2024

>>> Send a message (/? for help)

 

Ollama + Gemma 1.1 (7B)

이번엔 Gemma 7B 모델을다운받아 테스트합니다.

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama run gemma:7b
pulling manifest
pulling ef311de6af9d...  74% ▕█████████████████████████████████████████
pulling manifest
pulling ef311de6af9d...  74% ▕█████████████████████████████████████████
pulling manifest
pulling ef311de6af9d...  74% ▕█████████████████████████████████████████
pulling manifest
pulling ef311de6af9d... 100% ▕███████████████████████████████████████████████████████████████▏ 5.0 GB
pulling 097a36493f71... 100% ▕███████████████████████████████████████████████████████████████▏ 8.4 KB
pulling 109037bec39c... 100% ▕███████████████████████████████████████████████████████████████▏  136 B
pulling 65bb16cf5983... 100% ▕███████████████████████████████████████████████████████████████▏  109 B
pulling 0c2a5137eb3c... 100% ▕███████████████████████████████████████████████████████████████▏  483 B
verifying sha256 digest
writing manifest
success
>>> Send a message (/? for help)

 

다운로드한 모델 확인

(gabriel) Gabrielui-MacBookPro:~ gabriel$ ollama list
NAME             ID              SIZE      MODIFIED
gemma:7b         a72c7f4d0a15    5.0 GB    2 weeks ago
gemma:2b         b50d6c999e59    1.7 GB    2 weeks ago
gemma2:latest    ff02c3702f32    5.4 GB    2 weeks ago

 

Gemma2와 동일한 질문을 합니다. "why is the sky blue?"

>>> why is the sky blue?
**The sky is blue due to a phenomenon called Rayleigh scattering.**

* Sunlight is composed of all the colors of the rainbow, each with a different wavelength.
* Shorter wavelengths of light, such as blue light, have higher energy and more tightly spaced photons.
* When sunlight interacts with molecules in the atmosphere, such as nitrogen and oxygen, the shorter wavelengths are
scattered more effectively.

**Here's how it works:**

1. Sunlight enters the atmosphere and interacts with molecules of nitrogen and oxygen.
2. These molecules have electrons that can be excited by the energy of the incoming light.
3. The electrons absorb the energy and vibrate, then emit it in all directions.
4. However, **blue light is scattered more efficiently than other colors** because its shorter wavelength allows for more
frequent collisions between the photons and the molecules.

**This scattering process results in:**

* More blue light is scattered in all directions, reaching our eyes and making the sky appear blue.
* Longer wavelengths of light, such as red light, are scattered less efficiently, so we see more of them directly from
the sun.

**Additional factors influencing the sky's color:**

* **Time of day:** The sky is generally bluer at midday when the sunlight travels through less atmosphere.
* **Cloud cover:** Clouds can block the sunlight and scatter less blue light, making the sky appear less blue.
* **Pollution:** Pollution in the atmosphere can also scatter light and affect the sky's color.

>>> Send a message (/? for help)

 

실행한 모델 정보 확인

>>> /show info
  Model
  	arch            	gemma
  	parameters      	9B
  	quantization    	Q4_0
  	context length  	8192
  	embedding length	3072

  Parameters
  	penalize_newline	false
  	repeat_penalty  	1
  	stop            	"<start_of_turn>"
  	stop            	"<end_of_turn>"

  License
  	Gemma Terms of Use
  	Last modified: February 21, 2024

>>> Send a message (/? for help)

 

질의 성능 확인

모델 실행 성능 확인

 

Intel CPU의 MacBook에서 Gemma2 9B 모델 그리고 Gemma 2B, 7B 모델까지 Ollama로 구동해 봤습니다.

감사합니다.

 

 

 

 

728x90
반응형

+ Recent posts