🤖 AI/ML

Gemma

Google's open-source lightweight language model

📖 Detailed Explanation

Gemma is a family of open-source lightweight language models released by Google DeepMind. Built with the same research and technology used to create Gemini, it can be downloaded for free by anyone, run in a local environment, and used commercially.

After its first release in February 2024, Gemma 3 was announced in 2025 and shook up the open-source LLM ecosystem. The Gemma 3 27B model can run on a single GPU, yet it outperforms much larger models such as Llama 3 405B and DeepSeek-V3 on the LMArena benchmark.

The model lineup comes in five sizes: 270M, 1B, 4B, 12B, and 27B. It supports a 128K-token context window, more than 35 languages, text-plus-image multimodality, and even Function Calling. In particular, Gemma 3n is a mobile-optimized version that can deliver real-time AI on smartphones.

In practice, Gemma is the best choice when you want to run an LLM on your own servers without API costs. As of August 2025 it has been downloaded more than 200 million times, making it one of the most popular open-source LLMs on Hugging Face. It is especially favored in finance and healthcare, where sensitive data is handled.

💻 Code Example

# Gemma 3 로컬 실행 예제 (Hugging Face Transformers)
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# 1. 모델 로드 (4B 모델 - 8GB VRAM이면 충분)
model_id = "google/gemma-3-4b-it"  # instruction-tuned 버전
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,  # 메모리 절약
    device_map="auto"  # GPU 자동 할당
)

# 2. 텍스트 생성
prompt = """user
한국어로 간단한 FastAPI 서버 코드를 작성해줘.
헬스체크 엔드포인트 포함해서.
model
"""

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
    **inputs,
    max_new_tokens=500,
    temperature=0.7,
    do_sample=True
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

# 3. vLLM으로 고성능 서빙 (프로덕션용)
# pip install vllm
from vllm import LLM, SamplingParams

llm = LLM(model="google/gemma-3-12b-it", tensor_parallel_size=1)
sampling_params = SamplingParams(temperature=0.7, max_tokens=512)

prompts = [
    "Python에서 비동기 처리의 장단점을 설명해줘",
    "React와 Vue의 주요 차이점은?"
]
outputs = llm.generate(prompts, sampling_params)

for output in outputs:
    print(f"Prompt: {output.prompt[:50]}...")
    print(f"Response: {output.outputs[0].text}\n")

# 4. Ollama로 간편 실행 (로컬 개발용)
# 터미널: ollama run gemma3:27b
import requests
response = requests.post("http://localhost:11434/api/generate", json={
    "model": "gemma3:12b",
    "prompt": "Kubernetes와 Docker의 관계를 설명해줘",
    "stream": False
})
print(response.json()["response"])

🗣️ Say It Like This in Practice

💬 In a Meeting
"Customer data must not leave our environment, so we'll deploy Gemma 3 12B on our own servers. A single RTX 4090 is enough, and the API cost is zero."
💬 In an Interview
"Gemma is a lightweight, open-source release built on the same architecture as Gemini. The reason the 27B model scores higher than Llama 405B on benchmarks is Google's training data quality and efficient architecture."
💬 In a Technical Discussion
"Try the QAT (Quantization-Aware Training) version. Even with 4-bit quantization there is almost no performance loss, so you can run the 12B model on a laptop with 8GB of VRAM."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Using the base model as is

The Gemma base models are not meant for chat. Always use the "-it" (instruction-tuned) version. Example: gemma-3-4b-it

❌
Ignoring the prompt format

Gemma 3 uses a specific turn format. If you feed input without the <start_of_turn>user/model tags, quality drops sharply.

✅
The right way: serve with vLLM or Ollama

Loading directly with Transformers is slow. We recommend vLLM for production (high performance) and Ollama for development and testing (simplicity). The difference in tokens per second is 5x or more.

🔗 Related Terms

📚 Learn More