[AI] Ollama 모든 것
2025.04.15
Python이나 text-generation-webui에서 LLama3.3을 로딩하면 GPU RAM부족등으로 문제가 생기는데,
Ollama로 다운받은 Llama3.3은 잘 돌아간다.
Ollama에서 Web Search를 막는 방법 찾다가 좋은 블로그를 발견
https://recording-it.tistory.com/115
Ollama - 01. 설치 및 기본 사용
Ollama란?https://ollama.com/ ollama는 대규모 언어 모델(Large Language Models, LLMs)을 로컬 환경에서 쉽게 실행할 수 있게 해주는 오픈소스 프레임워크입니다. 이 도구는 복잡한 AI 모델을 개인용 컴퓨터나
recording-it.tistory.com
>>> /show info
Model
architecture llama
parameters 70.6B
context length 131072
embedding length 8192
quantization Q4_K_M
Capabilities
completion
tools
Parameters
stop "<|start_header_id|>"
stop "<|end_header_id|>"
stop "<|eot_id|>"
License
LLAMA 3.3 COMMUNITY LICENSE AGREEMENT
Llama 3.3 Version Release Date: December 6, 2024
4060Ti x 16GB
14.xGB + 14.xGB 사용
Q4_K-M이다.
>>> /load llama3.1
Loading model 'llama3.1'
>>> /show info
Model
architecture llama
parameters 8.0B
context length 131072
embedding length 4096
quantization Q4_K_M
Capabilities
completion
tools
Parameters
stop "<|start_header_id|>"
stop "<|end_header_id|>"
stop "<|eot_id|>"
License
LLAMA 3.1 COMMUNITY LICENSE AGREEMENT
Llama 3.1 Version Release Date: July 23, 2024
6GB 사용
text-generation-webui에서 Llama3.3*.gguf를 로드하는데 에러
이 오류는 LlamaCppModel을 로드하는 과정에서 NoneType 객체가 Llama 속성을 찾지 못해 발생하는 문제입니다. 일반적으로 다음과 같은 원인과 해결 방법이 있습니다:
가능한 원인 및 해결 방법
- llama.cpp 라이브러리 설치 문제
- llama_cpp_python이 올바르게 설치되지 않았을 가능성이 있습니다.
- pip install llama-cpp-python을 실행하여 최신 버전을 설치해 보세요.
일단 설치하는데 에러가 난다.
인스톨 하라는 것 하는데 안된다.
그냥 수동 빌드
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
mkdir build
cd build
cmake .. -DGGML_CUDA=ON
make -j$(nproc)
온갖 에러가 나서 ChatGPT에 물었더니 비슷한 답변.
마지막 라인 보여달래서 넣었더니 libgomp 이슈라고 설치하라고 함.
이미 최신인데?
find /usr -name "libgomp.so.1"
/usr/lib/x86_64-linux-gnu/libgomp.so.1
LD_LIBRARY_PATH 추가
창 다시열고
pip install git+https://github.com/abetlen/llama-cpp-python.git
성공!
다시 text-generation-webui로
로드가 된다!!
그런데 GPU가 안돌고 CPU 만
export CMAKE_ARGS='-DLLAMA_CUDA=ON'
pip install git+https://github.com/abetlen/llama-cpp-python.git --force-reinstall
재 설치
서버 실행중 에러 발생
pip install numpy==1.26.4 --force-reinstall
모델 로드하니 6GB+6GB 정도 사용한다.
답변은 별로다
좋아요! llama-cpp-python을 사용해서 .gguf 모델을 로드하고 Python 코드에서 활용하는 건 가능하지만, **직접 파인튜닝(fine-tuning)**은 안 됩니다.
.gguf는 inference 전용 포맷이기 때문이에요.
🔎 .gguf 파일 요약
- .gguf는 llama.cpp 프로젝트의 최적화된 추론용 포맷이에요.
- → 학습이 아닌 "추론"만 가능
- 파인튜닝하려면 Hugging Face Transformers 포맷 (.bin, .safetensors, etc) 이 필요합니다.
✅ 옵션 1: .gguf 모델 로드 & 추론 (Inference)
from llama_cpp import Llama
# 모델 경로 (.gguf 파일)
model_path = "/path/to/llama-3-8b-instruct.gguf"
llm = Llama(
model_path=model_path,
n_gpu_layers=40, # GPU 사용할 ggml layer 수 (cuda 지원됨)
n_ctx=2048,
n_threads=8,
verbose=True
)
output = llm("Q: What is the capital of France?\nA:", max_tokens=64)
print(output["choices"][0]["text"])
- n_gpu_layers를 지정해야 GPU 사용이 활성화됩니다.
- 모델이 GPU에 올라가는지 확인하려면 nvidia-smi로 체크해보세요.
❌ 옵션 2: .gguf 로 파인튜닝 ❓ → 불가능
- .gguf는 파인튜닝할 수 없음 (inference 전용이라 파라미터가 quantized 됨)
- 파인튜닝을 하고 싶다면 다음처럼 하셔야 해요:
✅ 옵션 3: 파인튜닝을 원한다면? → Hugging Face 포맷 사용
- .gguf 말고 original model weights (pytorch_model.bin 또는 model.safetensors)를 다운받습니다.
- transformers + peft (LoRA 등) 조합으로 파인튜닝합니다.
예시 코드 (요약):
from transformers import LlamaForCausalLM, LlamaTokenizer
from peft import get_peft_model, LoraConfig, TaskType
model = LlamaForCausalLM.from_pretrained("/path/to/llama3.1-8B")
tokenizer = LlamaTokenizer.from_pretrained("/path/to/llama3.1-8B")
peft_config = LoraConfig(
r=8,
lora_alpha=32,
task_type=TaskType.CAUSAL_LM,
lora_dropout=0.1,
target_modules=["q_proj", "v_proj"]
)
model = get_peft_model(model, peft_config)
# 이후 Trainer 또는 accelerate로 학습
📌 요약
작업 가능 여부 방법
.gguf로 추론 | ✅ 가능 | llama_cpp.Llama() |
.gguf로 파인튜닝 | ❌ 불가능 | |
파인튜닝 | ✅ 가능 | transformers + peft + 원본 모델 |
.gguf로 최대한 가볍게 추론하고, 파인튜닝은 별도로 .bin 포맷에서 하시면 됩니다.
필요하시면 .gguf 추론 + transformers 파인튜닝 파이프라인 정리해서 드릴게요. 원하시나요?