翻篇收录说明
翻篇网页快照

Gemma 4 - How to Run Locally | Unsloth Documentation

https://unsloth.ai/docs/models/gemma-4

最近抓取:2026-12-05 06:32:30(北京时间)

最近内容变化:2026-11-30 13:26:03(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Run Google’s new Gemma 4 models locally, including E2B, E4B, 26B A4B, and 31B.

正文摘录

Gemma 4 is Google DeepMind’s new family of open models, including 12B, E2B, E4B, 26B-A4B, and 31B. The multimodal, hybrid-thinking models support 140+ languages, up to 256K context, and have dense and MoE variants. Gemma 4 is Apache-2.0 licensed and can run on your local device.Gemma-4-12B is new and features unified text, image and audio support. It runs on 8GB RAM (4-bit) or 14GB (8-bit). Gemma-4-E2B and E4B also support image and audio. Run on 5GB RAM (4-bit) or 15GB (full 16-bit) via GGUF, MLX or NVFP4 quants.Run Gemma 4Fine-tune Gemma 4Gemma 4 QATGemma 4 MTPNEW: Gemma 4 MTP is here! MTP enables 1.4-2.2x faster inference without accuracy loss. Run MTP directly in Unsloth Studio.Gemma-4-26B-A4B runs on 18GB (4-bit) or 28GB (8-bit). Gemma-4-31B needs 20GB RAM (4-bit) or 34GB (8-bit).You can now run all GGUFs, MLX and fine-tune Gemma 4 in Unsloth Studio (see right).QAT variants of Gemma 4 reduce memory requirements around 3x while preserving model quality.Jun 9: Gemma 4 MTP is here.Jun 5: Gemma 4 QAT is released.Jun 2: Gemma 4 12B Unified is released.Apr 20: We conducted Gemma 4 GGUF Benchmarks to help you pick the best quant.Usage GuideGemma 4 excels at reasoning, coding, tool use, long-context and agentic workflows, and multimodal tasks. The smaller E2B and E4B variants are designed for phones and laptops, while the larger models target medium-high CPU /VRAM systems such as PCs with NVIDIA RTX GPUs.Gemma 4 VariantDetailsBest fitE2BDense + PLE (128K context) Support: Text, Image, AudioFor phone / edge inference, ASR, speech translationE4BDense + PLE (128K context) Support: Text, Image, AudioSmall model for laptops and fast local multimodal use12B UnifiedDense (256K context) Support: Text, Image, AudioMedium model for laptops and local multimodal use26B-A4BMoE (256K context) Support: Text, ImageBest speed / quality tradeoff for computer use31BDense (256K context) Support: Text, ImageStrongest performance at slower inferenceSee Gemma 4: Performance benchmarks and GGUF benchmarks.Should I pick 26B-A4B or 31B?26B-A4B - balances speed and accuracy. Its MoE design makes it faster than 31B, with 4B active parameters. Pick it if RAM is limited and you are fine trading a bit of quality for speed.31B - currently the strongest Gemma 4 model. Pick it for maximum quality if you have enough memory and can accept slightly slower speeds.Hardware requirementsTable: Gemma 4 Inference GGUF recommended hardware requirements (units = total memory: RAM + VRAM, or unified memory). You can use Gemma 4 on MacOS, NVIDIA RTX GPUs etc.Gemma 4 variant4-bit8-bitBF16 / FP16E2B4 GB5–8 GB10 GBE4B5.5–6 GB9–12 GB16 GB12B Unified7–8 GB13–14 GB25 GB26B A4B16–18 GB28–30 GB52 GB31B17–20 GB34–38 GB62 GBAs a rule of thumb, your total available memory should at least exceed the size of the quantized model you download. If it does not, llama.cpp can still run using partial RAM / disk offload, but generation will be slower. You will also need more compute, depending on the context window you use.Recommended SettingsIt is recommended to use Google's default Gemma 4 parameters:temperature = 1.0top_p = 0.95top_k = 64Gemma 4's max context is 128K for E2B / E4B and 262,144 for 12B / 26B A4B / 31B.Thinking ModeCompared to older Gemma chat templates, Gemma 4 uses the standard system, assistant, and user roles and adds explicit thinking control.How to enable thinking:Add the token <|think|> at the start of the system prompt.Thinking enabledThinking disabledOutput behavior:When thinking is enabled, the model outputs its internal reasoning channel before the final answer.When thinking is disabled, the larger models may still emit an empty thought block before the final answer.For example using "What is the capital of France?":then it outputs with:Multi-turn chat rule:For multi-turn conversations, only keep the final visible answer in chat history. Do not feed prior thought blocks back into the next turn.How to disable thinking:Note llama-cli might not work reliably, so use llama-server for disabling reasoning:To disable thinking / reasoning, use --chat-template-kwargs '{"enable_thinking":false}'If you're on Windows Powershell, use: --chat-template-kwargs "{\"enable_thinking\":false}"Use 'true' and 'false' interchangeably.Run Gemma 4 TutorialsBecause Gemma 4 GGUFs comes in several sizes, the recommended starting point for the small models is 8-bit and the larger models is Dynamic 4-bit. Gemma 4 GGUFs or MLX or NVFP4:E2BE4B12b26B-A4B31B🦥 Unsloth Desktop Guide🦙 Llama.cpp GuideNVFP4 GuideYou can run and train Gemma 4 for free with a UI in our Unsloth Studio✨ notebook:Google Colabcolab.research.google.com🦥 Unsloth GuideGemma 4 can now be run and fine-tuned in Unsloth Desktop, our new open-source desktop UI for local AI. Unsloth Studio lets you run models locally on MacOS, Windows, Linux and:Search, download, run GGUFs and safetensor modelsSelf-healing tool calling + web searchCode execution (Python, Bash)Automatic inference parameter tuning (temp, top-p, etc.)Fast CPU + GPU inference via llama.cppTrain LLMs 2x faster with 70% less VRAM1Install UnslothThe easiest way to get started is by downloading the Unsloth Desktop app. Works on macOS, Windows, and Linux.Download Unsloth Download for macOS Download for Windows Download for LinuxOr, if you prefer to install manually:MacOS, Linux, WSL:Windows PowerShell:2Launch UnslothMacOS, Linux, WSL and Windows:Then open http://127.0.0.1:8888 or your specific URL in your browser.Launch Unsloth securely with HTTPS and CloudflareNEW! Unsloth now provides a secure way to launch Unsloth over HTTPS through a free Cloudflare tunnel. Use the below (works in Windows, Mac & Linux):3Search and download Gemma 4On first launch you will need to create a password to secure your account and sign in again.Then go to the Unsloth Chat tab and search for Gemma 4 in the search bar and download your desired model and quant. Unsloth supports the latest Gemma-4-12B Unified model.4Run Gemma 4Inference parameters should be auto-set when using Unsloth Studio, however you can still change it manually. You can also edit the context length, chat template and other settings. You can run GGUFs and MLX files.For more information, you can view our Unsloth Studio inference guide.🦙 Llama.cpp GuideFor this guide we will be utilizing Dynamic 4-bit for the 12B, 26B-A4B and 31B, and 8-bit for E2B and E4B. See: Gemma 4 GGUF collectionFor these tutorials, we will using llama.cpp for fast local inference, especially if you have a CPU.1Obtain the latest llama.cpp on GitHub here. You can follow the build instructions below as well. Change -DGGML_CUDA=ON to -DGGML_CUDA=OFF if you don't have a GPU or just want CPU inference. For Apple Mac / Metal devices, set -DGGML_CUDA=OFF then continue as usual - Metal support is on by default.2If you want to use llama.cpp directly to load models, you can follow commands below, according to each model. UD-Q4_K_XL is the quantization type. You can also download via Hugging Face (step 3). This is similar to ollama run . Use export LLAMA_CACHE="folder" to force llama.cpp to save to a specific location. There is no need to set context length as llama.cpp automatically uses the exact amount required.To disable thinking / reasoning, use: --chat-template-kwargs '{"enable_thinking":false}'Windows Powershell: --chat-template-kwargs "{\"enable_thinking\":false}"Use 'true' and 'false' interchangeably.12B:26B-A4B:31B:E4B:E2B:3You can also download the model manually as well via the code below (after installing pip install huggingface_hub). You can choose UD-Q4_K_XL or other quantized versions like Q8_0 . If downloads get stuck, see: Hugging Face Hub, XET debugging4Then run the model in conversation mode (with vision mmproj-F16):5Llama-server deploymentTo deploy Gemma-4 on llama-server, use:MLX Dynamic QuantsWe also uploaded dynamic 4bit and 8bit quants as a first trial for MacOS device! The MLX quants support vision.All MLX quants now work in Unsloth Studio!Gemma 44-bit MLX8-bit MLX31Blinklink26B-A4BlinklinkE4BlinklinkE2BlinklinkTo try them out use:NVFP4 GuideWe uploaded Dynamic NVFP4 Gemma 4 quants for faster 4-bit inference on NVIDIA Blackwell GPUs. are the hardware requirements for models which you can use including Gemma 4. Also see the overall speed boost you will achieve:Gemma 4 variantRequired VRAMFaster than BF16E2B7 GB1.12× fasterE4B9 GB1.22× faster12B Unified11 GB1.26× faster26B A4B26 GB1.41× faster31B32 GB1.45× fastervLLM Tutorial:To run NVFP4 quants, see below for commands to run Gemma-4-26B-A4B in vLLM and SGLang (you can change model name to gemma-4-31B-it-NVFP4 etc.) Also do NOT select any MoE backend - leave vLLM to select it - for eg Marlin is 2.5x slower! See Gemma 4If you have a DGX Spark, see Gemma 4 you must use --moe-backend flashinfer_b12x or you will get much slower inference.To install vLLM in a separate venv:Then to serve the 26B MoE variant:Change unsloth/gemma-4-26B-A4B-it-NVFP4 to any available NVFP4 quant name!To enable MTP / speculative decoding (faster decode but somewhat less throughput), use:If you get Torchcodec issues, be sure to do the below then relaunch vllm.DGX Spark with NVFP4 quantsTo ensure DGX Spark has the correct kernels (or you will get 2x SLOWER inference), first check:which should NOT error out - if it did, please update vllm or reinstall via:Then to serve in vLLM for DGX Spark:If you get Torchcodec issues, be sure to do the below then relaunch vllm.SGLang Tutorial:Ollama GuideOllama now supports Unsloth GGUFs well now. Use curl -fsSL https://ollama.com/install.sh | sh to install Ollama on Linux or irm https://ollama.com/install.ps1 | iex for Windows. To use a single quant file (under 50GB) use:For multiple shards like larger BF16 shards do:If you see Error: 500 Internal Server Error: unable to load model update Ollama via curl -fsSL https://ollama.com/install.sh | sh or use the Powershell one.Gemma 4 Best PracticesPrompting examplesSimple reasoning promptOCR / document promptFor OCR, use a high visu