Home
Login

Hugging Face 공식 Gemma 모델 빠른 시작 튜토리얼 라이브러리, 추론, 미세 조정 등 다양한 실용적인 스크립트와 노트북 제공

MITPython 11huggingfacehuggingface-gemma-recipes Last Updated: 2025-06-26

Hugging Face Gemma Recipes 프로젝트 상세 소개

프로젝트 개요

huggingface-gemma-recipes는 Hugging Face에서 공식적으로 관리하는 오픈 소스 프로젝트로, 사용자에게 Google Gemma 시리즈 모델과 관련된 최소화된 예제 코드와 튜토리얼을 제공하는 것을 목표로 합니다. 이 프로젝트의 핵심 목표는 개발자가 Gemma 모델의 추론, 미세 조정 및 다양한 실제 응용 시나리오를 빠르게 시작할 수 있도록 돕는 것입니다.

프로젝트 특징

🚀 빠른 시작

  • 가장 단순화된 코드 예제를 제공하여 학습 장벽을 낮춥니다.
  • 다양한 모달리티의 입력 처리(텍스트, 이미지, 오디오)를 지원합니다.
  • 최신 Transformers 라이브러리 기능을 통합했습니다.

🎯 멀티모달 지원

이 프로젝트는 Gemma 3 시리즈 모델의 멀티모달 기능을 지원합니다.

  • 순수 텍스트 처리: 전통적인 텍스트 생성 및 질의응답
  • 이미지 이해: 이미지 설명, 시각적 질의응답
  • 오디오 처리: 음성 텍스트 변환, 오디오 분석
  • 멀티모달 상호 작용: 텍스트, 이미지, 오디오의 혼합 입력

핵심 기능

1. 모델 추론

이 프로젝트는 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])

2. 사용 예시

순수 텍스트 처리
# 텍스트 질의응답
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)

3. 모델 미세 조정

이 프로젝트는 다양한 미세 조정 솔루션과 스크립트를 제공합니다.

미세 조정 리소스
  • [Fine tuning Gemma 3n on T4]: T4 GPU에 특화된 미세 조정 튜토리얼
  • [Fine tuning Gemma 3n on images]: 이미지 이해 작업을 위한 미세 조정 스크립트
  • [Fine tuning Gemma 3n on audio]: 오디오 처리 작업을 위한 미세 조정 스크립트
  • [Fine tuning Gemma 3n on images using TRL]: TRL 라이브러리를 기반으로 한 이미지 미세 조정 솔루션
미세 조정 환경 설정
# 의존성 설치
$ pip install -U -q -r requirements.txt

설치 및 사용

시스템 요구 사항

  • Python 3.8+
  • PyTorch 2.0+
  • CUDA를 지원하는 GPU (권장)

빠른 설치

# 핵심 의존성 설치
$ pip install -U -q transformers timm

# 전체 의존성 설치 (미세 조정을 위해)
$ pip install -U -q -r requirements.txt

기본 사용 흐름

  1. 프로젝트 저장소 복제
  2. 의존성 패키지 설치
  3. 적절한 Gemma 모델 선택
  4. 필요에 따라 추론 또는 미세 조정 스크립트 선택
  5. 해당 코드 실행

프로젝트 구조

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                 # 프로젝트 설명

기술적 장점

1. 사용 편의성

  • 최소화된 코드 예제, 빠른 시작
  • 통합된 인터페이스 설계, 학습 비용 절감
  • 완전한 문서 및 예제

2. 유연성

  • 다양한 모달리티의 입력 처리 지원
  • 다양한 미세 조정 전략 제공
  • 다양한 하드웨어 구성과 호환

3. 실용성

  • 공식 Transformers 라이브러리 기반
  • 최신 모델 최적화 기술 통합
  • 생산 수준의 코드 품질 제공

적용 가능한 시나리오

연구 및 개발

  • 멀티모달 AI 연구
  • 모델 성능 평가
  • 새로운 응용 시나리오 탐색

상업적 응용

  • 지능형 고객 서비스 시스템
  • 콘텐츠 제작 도구
  • 멀티미디어 분석 플랫폼

교육 훈련

  • AI 과정 교육
  • 모델 미세 조정 실습
  • 기술 개념 검증

커뮤니티 및 지원

이 프로젝트는 Hugging Face에서 공식적으로 관리하는 오픈 소스 프로젝트로서 다음과 같은 장점을 가지고 있습니다.

  • 활발한 커뮤니티 지원
  • 정기적인 업데이트 및 유지 관리
  • 최신 모델 버전과의 동기화
  • 풍부한 문서 및 예제

요약

huggingface-gemma-recipes는 고품질의 오픈 소스 프로젝트로, Gemma 모델 사용에 대한 완전한 솔루션을 제공합니다. 초보자든 경험이 풍부한 개발자든 모두에게 적합한 리소스와 지침을 찾을 수 있습니다. 이 프로젝트의 멀티모달 지원과 유연한 미세 조정 솔루션은 현재 AI 개발 분야에서 중요한 도구 중 하나가 되도록 합니다.

Star History Chart