!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
새 비밀번호 만들기 (+새 보안 비밀 추가) : KAGGLE_USERNAME 및 KAGGLE_KEY
사용자 이름을 KAGGLE_USERNAME에 복사하여 붙여넣으세요.
KAGGLE_KEY에 키를 복사하여 붙여넣으세요.
secret 에 대한 "노트북 액세스"를 허용하려면 왼쪽에 있는 버튼을 전환하세요.
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 권한이 없기때문입니다.
M1 교체 이전에 사용하던 MacBook Pro 2015에서 Ollama로 Gemma2를 구동해봤습니다.
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
(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.
(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)
(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로 구동해 봤습니다.