> python & transformers

To use Gemma 4 from Python, install a recent Transformers (plus accelerate and timm for the vision tower) and load an instruction-tuned repo like google/gemma-4-E4B-it. The processor's apply_chat_template handles the turn format and thinking toggle; bitsandbytes or the QAT GGUFs shrink the memory footprint. These entries stay single-command — the multi-line loading code lives in the linked model cards.

// python & transformers

4 commands

// faq

What do I need to pip install to run Gemma 4?

pip install -U transformers accelerate torch timm. Gemma 4 support only exists in recent Transformers releases, so upgrade first — an older version fails with an unrecognized-model or unknown-architecture error. accelerate handles device placement and timm backs the vision encoder.

What are the exact Hugging Face repo names for Gemma 4?

The instruction-tuned repos are google/gemma-4-E2B-it, google/gemma-4-E4B-it, google/gemma-4-12B-it, google/gemma-4-26B-A4B-it, and google/gemma-4-31B-it. The hub is case-sensitive, so the capital B and the -it suffix matter — a lowercase id like gemma-4-e4b returns a 404.

Why do I get a 401 or 403 downloading Gemma 4 from Hugging Face?

You are either not logged in or have not acknowledged the model's terms. Run huggingface-cli login with a read-scoped token from huggingface.co/settings/tokens, then open the model page in a browser and accept the license if prompted. Retry the download afterward.

How do I run Gemma 4 in 4-bit from Python?

Install bitsandbytes and pass BitsAndBytesConfig(load_in_4bit=True) as quantization_config to from_pretrained, which quantizes on the fly and drops E4B from ~15 GB to ~5 GB. bitsandbytes requires a CUDA GPU; on Apple Silicon or CPU use the MLX or GGUF path, or load a QAT GGUF instead.