huggingface-gemma-recipes
는 Hugging Face에서 공식적으로 관리하는 오픈 소스 프로젝트로, 사용자에게 Google Gemma 시리즈 모델과 관련된 최소화된 예제 코드와 튜토리얼을 제공하는 것을 목표로 합니다. 이 프로젝트의 핵심 목표는 개발자가 Gemma 모델의 추론, 미세 조정 및 다양한 실제 응용 시나리오를 빠르게 시작할 수 있도록 돕는 것입니다.
이 프로젝트는 Gemma 3 시리즈 모델의 멀티모달 기능을 지원합니다.
이 프로젝트는 Gemma 모델을 빠르게 로드하고 사용할 수 있도록 통합된 모델 추론 인터페이스를 제공합니다.
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
model_id = "google/gemma-3n-e4b-it" # 또는 google/gemma-3n-e2b-it
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(model_id).to(device)
def model_generation(model, messages):
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
)
input_len = inputs["input_ids"].shape[-1]
inputs = inputs.to(model.device, dtype=model.dtype)
with torch.inference_mode():
generation = model.generate(**inputs, max_new_tokens=32, disable_compile=False)
generation = generation[:, input_len:]
decoded = processor.batch_decode(generation, skip_special_tokens=True)
print(decoded[0])
# 텍스트 질의응답
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "What is the capital of France?"}
]
}
]
model_generation(model, messages)
# 음성 텍스트 변환
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "Transcribe the following speech segment in English:"},
{"type": "audio", "audio": "https://huggingface.co/datasets/ariG23498/demo-data/resolve/main/speech.wav"},
]
}
]
model_generation(model, messages)
# 이미지 설명
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "https://huggingface.co/datasets/ariG23498/demo-data/resolve/main/airplane.jpg"},
{"type": "text", "text": "Describe this image."}
]
}
]
model_generation(model, messages)
이 프로젝트는 다양한 미세 조정 솔루션과 스크립트를 제공합니다.
# 의존성 설치
$ pip install -U -q -r requirements.txt
# 핵심 의존성 설치
$ pip install -U -q transformers timm
# 전체 의존성 설치 (미세 조정을 위해)
$ pip install -U -q -r requirements.txt
huggingface-gemma-recipes/
├── notebooks/ # Jupyter 노트북 튜토리얼
│ └── fine_tune_gemma3n_on_t4.ipynb
├── scripts/ # 미세 조정 스크립트
│ ├── ft_gemma3n_image_vt.py
│ ├── ft_gemma3n_audio_vt.py
│ └── ft_gemma3n_image_trl.py
├── requirements.txt # 의존성 목록
└── README.md # 프로젝트 설명
이 프로젝트는 Hugging Face에서 공식적으로 관리하는 오픈 소스 프로젝트로서 다음과 같은 장점을 가지고 있습니다.
huggingface-gemma-recipes
는 고품질의 오픈 소스 프로젝트로, Gemma 모델 사용에 대한 완전한 솔루션을 제공합니다. 초보자든 경험이 풍부한 개발자든 모두에게 적합한 리소스와 지침을 찾을 수 있습니다. 이 프로젝트의 멀티모달 지원과 유연한 미세 조정 솔루션은 현재 AI 개발 분야에서 중요한 도구 중 하나가 되도록 합니다.