0% read

Cara Mengunduh Gemma 4 dari Hugging Face (Weights & GGUF)

Apr 7, 2026

Hugging Face adalah hub utama untuk mengunduh bobot model Gemma 4. Entah kamu ingin bobot FP16 asli untuk fine-tuning atau file kuantisasi GGUF untuk inferensi lokal, semuanya ada di HF. Panduan ini membahas setiap metode unduh dan menunjukkan cara mulai menggunakan model langsung.

Repositori Resmi

Google mempublikasikan bobot asli Gemma 4 di Hugging Face:

ModelRepo Hugging FaceUkuranFormat
Gemma 4 1B ITgoogle/gemma-4-1b-it~2 GBSafeTensors
Gemma 4 4B ITgoogle/gemma-4-4b-it~8 GBSafeTensors
Gemma 4 12B ITgoogle/gemma-4-12b-it~24 GBSafeTensors
Gemma 4 27B ITgoogle/gemma-4-27b-it~54 GBSafeTensors
Gemma 4 E2B ITgoogle/gemma-4-e2b-it~4 GBSafeTensors
Gemma 4 E4B ITgoogle/gemma-4-e4b-it~8 GBSafeTensors

Model dasar (pre-trained, non-instruction-tuned) juga tersedia dengan sufiks -pt alih-alih -it.

Repositori GGUF

Untuk dijalankan dengan llama.cpp, Ollama, atau LM Studio, ambil versi GGUF dari Unsloth:

ModelRepo Hugging FaceKuantisasi Tersedia
Gemma 4 1Bunsloth/gemma-4-1b-it-GGUFQ4_K_M, Q5_K_M, Q8_0, IQ4_XS
Gemma 4 4Bunsloth/gemma-4-4b-it-GGUFQ4_K_M, Q5_K_M, Q8_0, IQ4_XS
Gemma 4 12Bunsloth/gemma-4-12b-it-GGUFQ4_K_M, Q5_K_M, Q6_K, Q8_0, IQ4_XS
Gemma 4 27Bunsloth/gemma-4-27b-it-GGUFQ4_K_M, Q5_K_M, Q6_K, Q8_0, IQ4_XS

Metode Unduh

Metode 1: huggingface-cli (Direkomendasikan)

Hugging Face CLI adalah cara paling andal untuk mengunduh file model besar:

# Instal CLI
pip install huggingface_hub

# Login (diperlukan untuk model yang di-gate)
huggingface-cli login

# Unduh file GGUF spesifik
huggingface-cli download unsloth/gemma-4-12b-it-GGUF \
  gemma-4-12b-it-Q4_K_M.gguf \
  --local-dir ./models

# Unduh model resmi penuh
huggingface-cli download google/gemma-4-12b-it \
  --local-dir ./models/gemma-4-12b-it

# Resume unduhan yang terputus secara otomatis
# Cukup jalankan perintah yang sama lagi — akan melanjutkan dari tempat ia berhenti

Metode 2: Git LFS

Untuk mengunduh seluruh repositori termasuk semua file:

# Instal git-lfs
# macOS
brew install git-lfs

# Ubuntu
sudo apt install git-lfs

# Inisialisasi git-lfs
git lfs install

# Clone repo model
git clone https://huggingface.co/google/gemma-4-12b-it

# Untuk GGUF — clone hanya file yang kamu butuhkan
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/unsloth/gemma-4-12b-it-GGUF
cd gemma-4-12b-it-GGUF
git lfs pull --include="gemma-4-12b-it-Q4_K_M.gguf"

Trik GIT_LFS_SKIP_SMUDGE=1 meng-clone metadata repo tanpa mengunduh file besar, lalu kamu secara selektif pull hanya kuantisasi yang kamu inginkan. Ini menghemat bandwidth saat repo punya banyak file besar.

Metode 3: Python API

Unduh secara programatik di skripmu:

from huggingface_hub import hf_hub_download, snapshot_download

# Unduh satu file
path = hf_hub_download(
    repo_id="unsloth/gemma-4-12b-it-GGUF",
    filename="gemma-4-12b-it-Q4_K_M.gguf",
    local_dir="./models"
)
print(f"Downloaded to: {path}")

# Unduh seluruh model
snapshot_download(
    repo_id="google/gemma-4-12b-it",
    local_dir="./models/gemma-4-12b-it"
)

Menggunakan dengan Library Transformers

Setelah kamu mengunduh bobot resmi, muat langsung dengan library transformers:

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load model dan tokenizer
model_id = "google/gemma-4-12b-it"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto"  # Otomatis distribusikan ke GPU yang tersedia
)

# Generate teks
messages = [
    {"role": "user", "content": "Jelaskan quantum computing dengan istilah sederhana."}
]

input_ids = tokenizer.apply_chat_template(
    messages,
    return_tensors="pt",
    add_generation_prompt=True
).to(model.device)

outputs = model.generate(
    input_ids,
    max_new_tokens=512,
    temperature=0.7,
    do_sample=True
)

response = tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True)
print(response)

Dengan Kuantisasi 4-bit (BitsAndBytes)

Jalankan model penuh di VRAM lebih kecil menggunakan kuantisasi on-the-fly:

from transformers import AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.bfloat16,
    bnb_4bit_quant_type="nf4"
)

model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-4-12b-it",
    quantization_config=quantization_config,
    device_map="auto"
)
# Sekarang berjalan di ~8GB VRAM alih-alih ~26GB

Menggunakan dengan Text Generation Inference (TGI)

Untuk serving produksi, TGI Hugging Face menyediakan inferensi teroptimasi:

# Jalankan dengan Docker
docker run --gpus all \
  -p 8080:80 \
  -v ./models:/data \
  ghcr.io/huggingface/text-generation-inference:latest \
  --model-id google/gemma-4-12b-it \
  --max-input-tokens 4096 \
  --max-total-tokens 8192 \
  --dtype bfloat16

# Query API
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemma-4-12b-it",
    "messages": [{"role": "user", "content": "Halo!"}],
    "max_tokens": 256
  }'

Mirror HF untuk Pengguna China

Jika kamu di China dan Hugging Face lambat atau diblokir, gunakan mirror resmi:

# Set endpoint mirror
export HF_ENDPOINT=https://hf-mirror.com

# Sekarang semua perintah huggingface-cli menggunakan mirror
huggingface-cli download unsloth/gemma-4-12b-it-GGUF \
  gemma-4-12b-it-Q4_K_M.gguf \
  --local-dir ./models

# Atau di Python
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"

from huggingface_hub import hf_hub_download
path = hf_hub_download(
    repo_id="unsloth/gemma-4-12b-it-GGUF",
    filename="gemma-4-12b-it-Q4_K_M.gguf"
)

Mirror sinkron dengan hub HF utama, jadi semua model dan file tersedia.

Tips Unduh

TipsDetail
Gunakan huggingface-cli daripada git cloneDukungan resume lebih baik, progress bar, dan penanganan error
Unduh file spesifik saat memungkinkanJangan clone seluruh repo dengan 10+ file kuantisasi
Cek ruang disk duluModel 27B FP16 butuh 54GB+ ruang kosong
Gunakan --cache-dir untuk lokasi cache kustomDefault ke ~/.cache/huggingface/ yang mungkin di drive kecil
Verifikasi integritas filehuggingface-cli cek SHA256 otomatis

Langkah Selanjutnya

  • Tidak yakin GGUF mana yang dipilih? Baca Panduan Kuantisasi GGUF kami untuk perbandingan format detail
  • Ingin semua opsi unduh di satu tempat? Cek Panduan Unduh Lengkap yang mencakup Ollama, LM Studio, dan unduhan langsung
  • Siap menjalankan model? Ikuti tutorial Ollama kami untuk setup tercepat

Hugging Face membuat distribusi model tanpa rasa sakit. Entah kamu mengambil GGUF cepat untuk Ollama atau bobot penuh untuk proyek riset, proses unduhnya langsung dan bisa dilanjutkan.

gemma4 — interact

Stop reading. Start building.

~/gemma4 $ Get hands-on with the models discussed in this guide. No deployment, no friction, 100% free playground.

Launch Playground />
Gemma 4 AI

Gemma 4 AI

Related Guides

Cara Mengunduh Gemma 4 dari Hugging Face (Weights & GGUF) | Blog