How-to

How To Deploy Gemma On-Premise Using Docker

This guide is for technical operators and engineers looking to run Google's Gemma models securely within their own infrastructure. We cover the practical steps, tools, and common considerations for an effective on-premise deployment.

TL;DR

To deploy Gemma on-premise with Docker, first ensure you have adequate GPU hardware and Docker Engine installed. Download Gemma models locally, typically from Hugging Face. Then, set up an inference server like Ollama or vLLM in a Docker container, configuring it to access your GPU. This approach offers significant benefits for data privacy and cost management, giving you full control over your AI operations.

Why Deploy Gemma On-Premise?

Running Gemma on your own servers offers distinct advantages, primarily around data privacy and cost control. For applications handling sensitive information, keeping data within your network is often a compliance requirement. Additionally, while cloud inference costs can scale unpredictably, an on-premise setup allows for more predictable expenditure once the initial hardware investment is made. It also provides greater control over model customisation and integration with existing systems, without relying on external API uptimes or rate limits.

Prerequisites: Hardware and Software

Before you begin, ensure you have suitable hardware. Gemma models benefit significantly from GPUs; aim for at least 16GB of VRAM for the 7B parameter model. NVIDIA GPUs are generally best supported, with CUDA drivers installed. On the software side, you'll need Docker Engine and Docker Compose installed on your Linux host. For GPU access within Docker, NVIDIA Container Toolkit (nvidia-docker) is essential. Verify your GPU drivers and Docker installation are working correctly before proceeding to avoid common setup headaches.

Obtaining Gemma Models

Gemma models are available on Hugging Face. You'll need to accept the terms of use and download the desired model variant (e.g., Gemma 7B Instruct). For on-premise deployment, store these model files in a local directory accessible by your Docker containers. Tools like `git lfs` can help manage larger model files. Alternatively, inference servers like Ollama can download and manage models directly, simplifying the process, though you'll still want to ensure local caching for consistent performance.

Setting Up Your Docker Environment

The simplest way to get Gemma running is often with an inference server like Ollama or vLLM within Docker. For Ollama, create a `docker-compose.yml` file. Map a local volume for model storage and ensure the container has access to your GPU using `runtime: nvidia`. Here's a basic structure: `services: ollama: image: ollama/ollama container_name: ollama volumes: - ./ollama:/root/.ollama environment: - OLLAMA_HOST=0.0.0.0:11434 ports: - "11434:11434" deploy: resources: reservations: devices: - driver: nvidia count: all capabilities: [gpu]`. Once running, you can pull Gemma directly via `docker exec -it ollama ollama pull gemma:7b`.

Running and Testing Gemma

With Ollama running in Docker, you can interact with Gemma via its API. For example, from your host, use `curl http://localhost:11434/api/generate -d '{"model": "gemma:7b", "prompt": "Why is the sky blue?"}'`. Monitor your GPU usage (e.g., with `nvidia-smi`) to ensure the model is loading and inferring correctly. Pay attention to memory consumption. If you face issues, check Docker logs and ensure your NVIDIA Container Toolkit is correctly configured for GPU passthrough. Optimisation might involve adjusting model quantisation or batch sizes.

Frequently Asked

What are the minimum GPU requirements for Gemma?

+

For the Gemma 7B parameter model, we recommend a GPU with at least 16GB of VRAM. While it might run on less, performance will be significantly constrained. The 2B model can run on GPUs with less memory, often around 8GB VRAM.

Can I deploy Gemma on-premise without a GPU?

+

Yes, but performance will be very slow. Gemma models are designed to run efficiently on GPUs. CPU-only inference is technically possible but not practical for most real-world applications requiring reasonable response times, especially for larger models.

What's the difference between Ollama and vLLM for deployment?

+

Ollama simplifies model management and local deployment, making it user-friendly for getting started. vLLM is a high-performance serving engine for LLMs, offering advanced features like PagedAttention for better throughput and lower latency, ideal for production workloads with higher demands.

How does on-premise deployment affect data privacy?

+

Deploying Gemma on-premise means your data remains within your controlled infrastructure. No data leaves your network to third-party cloud providers for inference, significantly enhancing data privacy and simplifying compliance with regulations like GDPR or HIPAA.

Is it difficult to update Gemma models on-premise?

+

Updating Gemma models on-premise is generally straightforward. If using Ollama, a simple `ollama pull` command updates the model. For custom setups, you'd replace the model files in your specified volume. The main challenge is managing downtime during the update process and ensuring compatibility.

Need Custom AI Solutions?

Ready to explore custom AI solutions? Book a free discovery call on Cal.com with Agentized to discuss your project and how we can help.