This article provides a step by step debugging guide for deploying Gemma 4 to a Google Cloud TPU system,. A suite of Python MCP tools is built to simplify management of the vLLM hosted Gemma 4 deployment with Antigravity CLI.
What is this project trying to Do?
This project is a DevOps/SRE assistant that uses a Gemma 4 model hosted on TPU. It provides tools to provision the Docker container and deploy the model, as well as for observability and performance testing.
This project is similar to a previous project that targeted GPU hosted Gemma4 instances on GCP:
Gemma-SRE: Self-Hosted vLLM Infrastructure Agent
Antigravity CLI
Antigravity CLI is the follow-on successor to Gemini CLI- the terminal driven, agent assisted coding tool.
Full details on installing Antigravity CLI are here:
Getting Started with Antigravity CLI
Testing the Antigravity CLI Environment
Once you have all the tools in place- you can test the startup of Antigravity CLI.
You will need to authenticate with a Google Cloud Project or your Google Account:
agy
This will start the interface:
Full Installation Instructions
The detailed installation instructions for Antigravity CLI are here:
Getting Started with Antigravity CLI
Python MCP Documentation
The official GitHub Repo provides samples and documentation for getting started:
Where do I start?
The strategy for starting MCP development for model management is a incremental step by step approach.
First, the basic development environment is setup with the required system variables, and a working Antigravity CLI configuration.
Then, a minimal Python MCP Server is built with stdio transport. This server is validated with Antigravity CLI in the local environment.
This setup validates the connection from Antigravity CLI to the local server via MCP. The MCP client (Antigravity CLI) and the Python MCP server both run in the same local environment.
Setup the Basic Environment
At this point you should have a working Python environment and a working Antigravity CLI installation. The next step is to clone the GitHub samples repository with support scripts:
cd ~
git clone https://github.com/xbill9/gemma4-tips
Then run init.sh from the cloned directory.
The script will attempt to determine your shell environment and set the correct variables:
cd tpu-4B-v6e1-devops-agent
source init.sh
If your session times out or you need to re-authenticate- you can run the set_env.sh script to reset your environment variables:
cd tpu-4B-v6e1-devops-agent
source set_env.sh
Variables like PROJECT_ID need to be setup for use in the various build scripts- so the set_env script can be used to reset the environment if you time-out.
Model Management Tool with MCP Stdio Transport
One of the key features that the standard MCP libraries provide is abstracting various transport methods.
The high level MCP tool implementation is the same no matter what low level transport channel/method that the MCP Client uses to connect to a MCP Server.
The simplest transport that the SDK supports is the stdio (stdio/stdout) transport — which connects a locally running process. Both the MCP client and MCP Server must be running in the same environment.
The connection over stdio will look similar to this:
# Initialize FastMCP server
mcp = FastMCP("Self-Hosted vLLM DevOps Agent")
Running the Python Code
First- switch the directory with the Python version of the MCP sample code:
xbill@penguin:~/gemma4-tips/tpu-4B-v6e1-devops-agent$ make install
pip install -r requirements.txt
The project can also be linted:
xbill@penguin:~/gemma4-tips/tpu-4B-v6e1-devops-agent$ make lint
ruff check .
All checks passed!
ruff format --check .
6 files already formatted
mypy .
Success: no issues found in 6 source files
Antigravity CLI mcp_config.json
A sample MCP server file is provided in the .agents directory:
{
"mcpServers": {
"tpu-4B-v6e1-devops-agent": {
"command": "python3",
"args": [
"/home/xbill/gemma4-tips/tpu-4B-v6e1-devops-agent/server.py"
],
"env": {
"GOOGLE_CLOUD_PROJECT": "comglitn",
"GOOGLE_CLOUD_REGION": "europe-west4",
"GOOGLE_CLOUD_ZONE": "europe-west4-a",
"MODEL_NAME": "google/gemma-4-E4B-it",
"ACCELERATOR_TYPE": "v6e-1",
"TENSOR_PARALLEL_SIZE": "1",
"TRIGGER_RELOAD": "1"
}
}
}
}
Validation with Antigravity CLI
The final connection test uses Antigravity CLI as a MCP client with the Python code providing the MCP server:
MCP Servers
Configured (~/.gemini/config/mcp_config.json)
> ✓ tpu-4B-v6e1-devops-agent Tools: verify_model_health, save_hf_token, get_vllm_deployment_config,
get_vllm_tpu_deployment_config, destroy_queued_resource, +26 more
Model Lifecycle Management via MCP
The MCP tools provide a complete suite of agent-oriented operations for managing vLLM deployment on Cloud Run or a TPU.
Overview of MCP tools :
> make help
43.1k in | 604 out | 527 thinking
● Bash(make help) (ctrl+o to expand)
Here is the output from running make help :
Available MCP tools in server.py:
get_vllm_deployment_config - Generates the gcloud command for a single-host TPU v6e vLLM deployment.
get_vllm_tpu_deployment_config - Generates a GKE manifest for a TPU v6e vLLM deployment.
list_queued_resources - Lists all Queued Resources in a specific zone.
describe_queued_resource - Provides detailed information about a specific Queued Resource.
get_reservation_status - Checks the lifecycle state and expiry time of a Queued Resource.
check_tpu_availability - Simple check to see if a Queued Resource has reached ACTIVE state.
estimate_deployment_cost - Estimates the cost of a TPU deployment.
get_system_status - Status dashboard prioritizing Queued Resource states in us-central1-a.
orchestrate_gemma4_stack - Seamless turnkey deployment of the Gemma 4 stack.
get_vllm_endpoint - Discovery tool to verify connectivity and return the active vLLM service URL.
deploy_queued_vllm - Deploys vLLM strictly using Queued Resources for Flex-start allocation.
create_tpu_queued_resource - Creates a TPU Queued Resource (Flex-start) with the specified configuration.
check_tpu_utilization - Monitors Tensor Core and HBM pressure on the TPU VM.
get_vllm_metrics - Fetches real-time Prometheus metrics from the active vLLM service.
validate_gemma4_deployment - Performs a comprehensive sanity check on the Gemma 4 deployment.
query_queued_gemma4 - Queries the model hosted on the active Queued Resource.
run_vllm_benchmark - Runs vLLM's internal benchmark tool inside the container on the TPU VM.
run_vllm_internal_benchmark - Runs vLLM's internal benchmark tool inside the container on the TPU VM.
run_external_load_test - Performs an external load test against the active vLLM endpoint.
get_gemma4_full_report - Generates a deep technical report of the Gemma 4 deployment.
fetch_tpu_vm_logs - Fetches specific logs from a TPU VM.
grep_tpu_logs - Searches for a pattern in both startup and container logs on the TPU VM.
destroy_queued_resource - Safely deletes a Queued Resource and its associated node.
fetch_queued_node_logs - Fetches logs by identifying the node linked to a Queued Resource.
save_hf_token - Saves HF token to GCP Secret Manager for the Queued Resource deployer.
analyze_cloud_logging - Searches Cloud Logging for TPU-related errors and lifecycle events.
verify_model_health - Performs a deep health check by querying the model with a simple prompt.
query_vllm_with_metrics - Queries the model and provides streaming-based performance metrics.
get_vllm_model_stats - Aggregates model-specific statistics from the vLLM server.
Getting Started with Gemma 4 on TPU
The Official vLLM repo also has Gemma4 specific information:
Find and Start the TPU
First check for available zones with quota:
> get_zones_with_available_quota
We have Lift Off!
Finally- a zone with availability and Quota as found!
### Current Status
The Gemma 4 4B inference server is ONLINE 🟢 and healthy.
#### 🐳 Cloud TPU Infrastructure Details
• Project: comglitn
• Zone: europe-west4-a
• Queued Resource: vllm-gemma4-qr (State: ACTIVE )
• TPU VM Node: vllm-gemma4-qr-node (State: READY / HEALTHY )
• Accelerator Type: v6e-1 (TPU v6e, topology 1x1 )
• Network Endpoint (External IP): 34.158.180.227:8000
#### 🤖 Model Serving Details
• Serving Model: google/gemma-4-E4B-it (Gemma 4 4B)
• Serving Backend: vLLM ( vllm-0.23.1rc1 )
• Sanity Check: Verified chat completion is responding successfully.
{
"model": "google/gemma-4-E4B-it",
"choices": [
{
"message": {
"role": "assistant",
"content": "Why don't scientists trust atoms?\n\nBecause they make up *everything*!"
}
}
]
}
Review the Memory Layout
The MCP server tools are used to review the model:
Based on the initialization logs of the running vLLM engine, here is the exact memory layout of the Cloud
TPU v6e (Trillium) chip during serving of the Gemma 4 4B model:
### 🧠 TPU HBM (High Bandwidth Memory) Layout
• Total Physical HBM Capacity: 31.25 GiB (32 GB)
• Allocated Safety Capacity Limit: 28.75 GiB (Safety boundary set by vLLM to prevent OOM)
• Model Weights & System Overhead: 14.32 GiB (Memory consumed once weights are loaded into JAX/Flax)
• Available HBM for KV Cache: 14.43 GiB
──────
### 📊 KV Cache Configuration
The available 14.43 GiB of memory is fully dedicated to the KV (Key-Value) cache, resulting in the
following serving capacities:
• KV Cache Capacity: 270,112 tokens
• Maximum Serving Concurrency: 16.49x concurrently active requests (assuming the maximum sequence length
of 16,384 tokens per request)
Cross Check The Deployed Model
Once the model starts — the MCP tool allows for model verification:
The health check passed successfully!
• Status: PASSED ✅
• Response: "Hello! Yes, the model is working. I..."
• Latency: 0.70 seconds
and model details:
> get_model_details
13.2k in | 494 out | 168 thinking
● Bash(GOOGLE_CLOUD_PROJECT=comglitn python -c "import asyncio; from server import get_mod...) (ctrl+o to
expand)
I have initiated the retrieval of model details. I will report the engine and configuration details once
the query completes.
The detailed model and engine parameters are as follows:
### 🧩 Model & vLLM Engine Details ( http://34.158.180.227:8000 )
• Model ID: google/gemma-4-E4B-it (Gemma 4 4B Model)
• Maximum Model Length: 16,384 tokens
• vLLM Engine Version: 0.23.1rc1.dev788+gfa4321de3
• Health Status: Healthy ✅
• Host Process Resident Memory Size: ~2.99 GB
Check the Cloud TPU
Once Deployed — the TPU is on the Google Cloud Console:
Review the Model
Check the model details:
I have initiated the retrieval of raw Prometheus metrics. I will output the logs once they are fetched.
Here are the raw Prometheus metrics retrieved from the running vLLM service's /metrics endpoint:
# HELP http_response_size_bytes_created Content length of outgoing responses by handler. Only value of
header is respected. Otherwise ignored. No percentile calculated.
# TYPE http_response_size_bytes_created gauge
http_response_size_bytes_created{handler="/v1/models"} 1.7833693959992864e+09
http_response_size_bytes_created{handler="/v1/chat/completions"} 1.7833693990824807e+09
# HELP http_request_duration_highr_seconds Latency with many buckets but no API specific labels. Made
for more accurate percentile calculations.
# TYPE http_request_duration_highr_seconds histogram
http_request_duration_highr_seconds_bucket{le="0.01"} 2.0
http_request_duration_highr_seconds_bucket{le="0.025"} 2.0
http_request_duration_highr_seconds_bucket{le="0.05"} 2.0
http_request_duration_highr_seconds_bucket{le="0.075"} 2.0
http_request_duration_highr_seconds_bucket{le="0.1"} 3.0
http_request_duration_highr_seconds_bucket{le="0.25"} 3.0
http_request_duration_highr_seconds_bucket{le="0.5"} 4.0
http_request_duration_highr_seconds_bucket{le="0.75"} 4.0
http_request_duration_highr_seconds_bucket{le="1.0"} 4.0
http_request_duration_highr_seconds_bucket{le="+Inf"} 4.0
http_request_duration_highr_seconds_count 4.0
http_request_duration_highr_seconds_sum 0.49223544199981006
# HELP http_request_duration_seconds Latency with only few buckets by handler. Made to be only used if
aggregation by handler is important.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{handler="/v1/models",le="0.1",method="GET"} 2.0
http_request_duration_seconds_bucket{handler="/v1/models",le="+Inf",method="GET"} 2.0
http_request_duration_seconds_count{handler="/v1/models",method="GET"} 2.0
http_request_duration_seconds_sum{handler="/v1/models",method="GET"} 0.001482499999610809
http_request_duration_seconds_bucket{handler="/v1/chat/completions",le="0.1",method="POST"} 1.0
http_request_duration_seconds_bucket{handler="/v1/chat/completions",le="0.5",method="POST"} 2.0
http_request_duration_seconds_bucket{handler="/v1/chat/completions",le="1.0",method="POST"} 2.0
http_request_duration_seconds_bucket{handler="/v1/chat/completions",le="+Inf",method="POST"} 2.0
http_request_duration_seconds_count{handler="/v1/chat/completions",method="POST"} 2.0
http_request_duration_seconds_sum{handler="/v1/chat/completions",method="POST"} 0.49075294200019925
# HELP vllm:tool_call_parser_invocations_total Total number of ToolParser invocations. Non-streaming
increments once per choice; streaming increments once per delta.
# TYPE vllm:tool_call_parser_invocations_total counter
vllm:tool_call_parser_invocations_total{mode="non_streaming",model_name="google/gemma-4-E4B-it",
outcome="no_tool_call",request_type="chat_completions"} 2.0
Once everything is online — you can send queries to the Model:
> query_gemma4_with_stats what is Gemma?
I have sent the prompt "what is Gemma?" to the serving stack to measure performance statistics. I will
display the model's response and latency metrics once they are generated.
Here are the performance statistics and response generated by the Gemma 4 4B model hosted on the Cloud TPU
v6e:
### 📊 Performance Stats
• Time to First Token (TTFT): 0.597s
• Total Generation Time: 2.713s
• Throughput (Tokens per Second): 108.23 tokens/s
• Total Tokens Generated: 229
──────
### 💬 Model Response
│ I am Gemma 4.
│
│ Gemma is a family of lightweight, state-of-the-art open models developed by Google DeepMind.
│
│ Here are the key things to know about Gemma:
│
│ 1. Open Weights: A significant feature of the Gemma family is that they are open-weight models. This
│ means that researchers, developers, and the community can download and use the models to build their own
│ applications, which promotes transparency and innovation.
│ 2. Designed for Responsibility: Like other models from Google, the Gemma family is built with principles
│ of responsible AI in mind.
│ 3. Versatility: The Gemma family includes various sizes (like 2B and 7B parameters, among others), which
│ allows users to choose a model that balances performance needs with the computational resources
available
│ (making them good for deployment on various hardware).
│ 4. Capabilities: As a large language model, Gemma is capable of performing various natural language
│ processing tasks, such as answering questions, generating creative text, summarizing information, and
│ translating languages.
│
│ In short, Gemma is Google DeepMind's family of accessible, powerful, and openly available AI models.
Benchmark the Local Model
The local model was benchmarked:
### 🚀 Key Performance Insights
Here is the performance summary of the benchmark sweep on the Cloud TPU v6e-1 serving Gemma 4 4B:
### 📊 Sweep Statistics
• Total Benchmark Configurations Checked: 156 (12 concurrencies × 13 context lengths)
• Successful Configurations: 145
• Timeouts / Overload Failures: 11 (all occurred at extremely high densities, e.g., concurrency ≥512
with ≥4 K context window)
──────
### 🚀 Peak Throughput by Context Size
Context Length | Peak Throughput | Optimal Concurrency (Users) | Performance Classification
--------------------|--------------------|-----------------------------|----------------------------------
4 tokens | 27.85 req/s | 1024 | Ultra-short prompts / chat
8 tokens | 28.00 req/s | 1024 | Peak system serving throughput
16 tokens | 27.89 req/s | 1024 | Short prompt queries
32 tokens | 27.60 req/s | 1024 | Basic instructions
64 tokens | 27.61 req/s | 1024 | Sentences / standard prompts
128 tokens | 27.27 req/s | 1024 | Multi-sentence requests
256 tokens | 26.44 req/s | 512 | Mid-length context
512 tokens | 24.69 req/s | 256 | Single document/paragraph
1024 tokens | 20.55 req/s | 128 | Multi-document query
2048 tokens | 14.80 req/s | 128 | Large document context
4096 tokens | 9.29 req/s | 64 | RAG / codebase snippets
8192 tokens | 5.68 req/s | 16 | Large codebase context
16384 tokens | 0.00 req/s | 1 | Maximum sequence length boundary
──────
### 💡 Key Takeaways
1. Optimal Workload Densities:
• For short context queries (<256 tokens), the TPU v6e-1 excels at handling high concurrency (up to
1024 users simultaneously) with almost flat throughput degradation (~27.5 req/s).
• As context length extends, the optimal concurrency level shifts downward ( 128 users at 2K tokens,
64 users at 4K tokens, 16 users at 8K tokens) to prevent queue saturation.
2. Resource Boundary (Timeouts):
• The 11 timeouts confirm the physical memory bandwidth and processing capacity limit of a single
v6e-1 chip when bombarded with large context windows under high concurrency.
• Scaling beyond these limits for 8K/16K context serving would benefit from a multi-chip topology (
v6e-4 or v6e-8 ).
This is visualized:
Comparison with Other Deployments
What just happened? Compare and contrast 2B, 12B on v6e-1:
Based on the benchmark sweeps, memory footprints, and architectural requirements on a Cloud TPU v6e-1 (32
GB HBM), here is a comparison of the Gemma 4 2B, 4B, and 12B models:
### 📊 Comparative Analysis Matrix
Metric / Aspect | Gemma 4 2B ( google/gem… | Gemma 4 4B ( google/gem… | Gemma 4 12B ( google/ge…
-------------------------|--------------------------|--------------------------|--------------------------
Model Size | 2 Billion Parameters | 4 Billion Parameters | 12 Billion Parameters
BF16 Weights Size | ~4.50 GiB | ~8.00 GiB | ~24.00 GiB
KV Cache Capacity | ~24.25 GiB (High) | 14.43 GiB ( 270k | ~4.75 GiB (Low,
| | tokens) | constrained)
Peak Throughput (req/s) | 25.76 req/s (at 100- | 28.00 req/s (at 100- | 72.83 req/s (at 16-tok
| tok output) | tok output) | output)*
Optimal Concurrency | 1024 users | 1024 users | 128 users (at scale)
Scalability (Single | High concurrency & large | High concurrency & | Highly constrained (OOMs
Chip) | context | balanced context | easily)
Primary Use Case | Ultra-low latency, basic | General SRE Agent, tool- | Complex SRE logic,
| SRE diagnostics | calling, RAG | multi-hop reasoning
│ [!NOTE]
│ *The 12B model peak throughput of 72.83 req/s was benchmarked with a very short output window of 16
│ tokens to evaluate context ingestion speed, whereas the 2B and 4B models were swept using a 100-token
│ generation window. Adjusting for token generation length, the raw processing throughput scales down
│ inversely with parameter size.
──────
### 🔍 Key Contrasts & Trade-offs
#### 1. 💾 Memory Allocation & HBM Pressure
• 2B & 4B Models (Lightweight): These models fit comfortably on a single v6e-1 chip. Since the weights
take up only a fraction of the 32 GB HBM, a massive portion of memory is reserved for the KV cache. This
makes them exceptionally robust at handling long context windows and massive concurrency.
• 12B Model (Heavyweight): The 12B model's weights consume nearly 75% of the total physical HBM on a
single chip, leaving very little room for the KV cache. Consequently, it saturates and suffers Out-Of-
Memory (OOM) errors much faster when exposed to high concurrency or context lengths above 4K.
#### 2. ⚡ Processing Throughput
• The 4B model achieves slightly better peak throughput ( 28.00 req/s ) than the 2B model ( 25.76 req/s )
under identical 100-token generation workloads. This shows that the matrix multiplication layout of the 4B
model aligns extremely well with the hardware utilization of the TPU v6e Tensor Cores.
• The 12B model requires significantly more Matrix Multiply-Accumulate (MMA) operations per token, which
reduces token generation speed.
#### 3. 🎯 Topologies & Multi-Chip Recommendation
• 2B / 4B: Highly optimal for single-chip ( v6e-1 ) deployments.
• 12B: While deployable on v6e-1 for lightweight single-user tasks, running production workloads with
the 12B model requires scaling to a multi-chip topology like v6e-4 (4 chips / 128 GB HBM) to expand the
available KV cache capacity and prevent bottlenecking.
Compare the models on the v6e-4:
> compare and contrast the 4B and 2B and 12B models on v6e-4
238.0k in | 2.4k out | 1.0k thinking
● Bash(python -c "import pandas as pd; df = pd.read_csv('../tpu-2B-v6e4-devops-agent/grid_...) (ctrl+o to
expand)
When we scale from a single-chip v6e-1 to a multi-chip v6e-4 (4 chips, 128 GB total HBM) topology
using Tensor Parallelism ( --tensor-parallel-size 4 ), the system's memory constraints and compute
dynamics shift significantly.
Here is the comparison and contrast of the Gemma 4 2B, 4B, and 12B models under the v6e-4 configuration:
──────
### 📊 Comparative Analysis Matrix ( v6e-4 Topology)
Metric / Aspect | Gemma 4 2B ( google/g… | Gemma 4 4B ( google/g… | Gemma 4 12B ( google/…
-------------------------------|------------------------|------------------------|------------------------
Total Memory (HBM) | 128 GB (4 × 32 GB) | 128 GB (4 × 32 GB) | 128 GB (4 × 32 GB)
Sharded Weights per Chip | ~1.13 GiB | ~2.00 GiB | ~6.00 GiB
KV Cache Capacity per Chip | ~30.12 GiB | ~29.25 GiB | ~25.25 GiB
Total KV Cache Pool (4 chips) | ~120 GiB | ~117 GiB | ~101 GiB (Massive)
Peak Throughput (req/s) | High (Bounded by CPU | 223.85 req/s | 72.83 req/s
| overhead) | |
Optimal Concurrency | 1024+ users | 1024+ users | 1024 users
Scalability (4 Chips) | Near-unlimited context | Massive throughput | Solves
| capacity | scaling | memory/concurrency
| | | bounds
──────
### 🔍 Key Contrasts & Scaling Dynamics on v6e-4
#### 1. 💾 Elimination of the 12B Memory Bottleneck
• On v6e-1 : The 12B model was heavily throttled because its weights consumed 24 GiB of the 32 GiB HBM,
leaving a tiny 4.75 GiB pool for KV cache (resulting in quick OOMs).
• On v6e-4 : With weights sharded across 4 chips ( 6.0 GiB per chip), each chip retains a huge 25.25
GiB pool for KV cache. This opens up a total pool of ~101 GiB for the 12B model, allowing it to handle
massive context windows (up to 16K) and high concurrency ( 1024 users) without OOM risks.
#### 2. ⚡ Performance and Throughput Scaling
• Matrix Multiplications: With 4 chips working in parallel via Tensor Parallelism, the compute capacity
quadruples.
• 4B Performance: Under optimal batching configurations on v6e-4 , the 4B model scales to a peak serving
throughput of 223.85 req/s .
• 2B Performance: The 2B model is extremely fast, but at this scale, it becomes bounded by host CPU
dispatch overhead (the TPU processes tokens faster than the host can schedule them).
#### 3. 🎯 Best Match for v6e-4
• 2B Model: Over-provisioned. The compute power of 4 chips is wasted on a model this small due to
scheduling overhead.
• 4B Model: Excellent choice for applications requiring ultra-high throughput serving (e.g., thousands of
simultaneous chat users).
• 12B Model: The Sweet Spot. The v6e-4 topology is the ideal deployment target for the 12B model,
resolving all memory bottleneck issues and allowing it to use its superior reasoning capabilities at scale.
how does the 4 chip vs 1 chip vs model version compare?
> compare and contrast the 4B and 2B and 12B models on v6e-4 vs v6e-1
Scaling the serving topology from v6e-1 (1 chip, 32 GB HBM) to v6e-4 (4 chips, 128 GB HBM) changes the
cost-efficiency, memory boundaries, and performance profile of the Gemma 4 models.
──────
### 📊 Cross-Topology Comparison Matrix
Model Size | Metric | Single Chip ( v6e-1… | Multi-Chip ( v6e-4 … | Scaling Impact & Eff…
-------------|----------------------|----------------------|----------------------|-----------------------
Gemma 4 2B | Peak Throughput KV | 25.76 req/s | High (CPU Bounded) | Dimension Over-
| Cache Pool | ~24.25 GiB | ~120 GiB | provisioned: Compute
| | | | capacity is under-
| | | | utilized relative to
| | | | host scheduling
| | | | overhead.
Gemma 4 4B | Peak Throughput KV | 28.00 req/s | 223.85 req/s | Efficiency Doubled:
| Cache Pool Cost | 14.43 GiB 20.74 | ~117 GiB 41.45 | Scaling to 4 chips
| Efficiency | req/s / $ | req/s / $ | nearly doubles the
| | | | throughput per dollar
| | | | due to massive
| | | | batching capacity.
Gemma 4 12B | Peak Throughput KV | 72.83 req/s * | 72.83 req/s ~101 | Reliability Unlocked:
| Cache Pool OOM Risk | 4.75 GiB **High** | GiB None (up to | Resolves critical
| | (at >4K context) | 16K context) | memory boundaries,
| | | | unlocking production-
| | | | grade 12B serving.
│ [!NOTE]
│ *The 12B model peak on v6e-1 was benchmarked with a short 16-token output. Under a standard 100-token
│ generation workload, its throughput is heavily throttled by compute limits on a single chip.
──────
### 🔑 Critical SRE Insights
#### 1. 📈 Throughput-per-Dollar Optimization (4B Model)
• On v6e-1 : The 4B model achieves 28.00 req/s costing $1.35/hr ( 20.74 req/s per dollar ).
• On v6e-4 : The 4B model scales to 223.85 req/s costing $5.40/hr ( 41.45 req/s per dollar ).
• Takeaway: Upgrading to a 4-chip topology is highly recommended for high-traffic 4B serving. It increases
raw throughput by 8x and nearly doubles cost efficiency because it enables much larger batch sizes and
higher hardware utilization.
#### 2. 🛡️ Memory Buffer & OOM Mitigation (12B Model)
• On v6e-1 : The 12B model suffers from severe memory bottlenecks. High-concurrency requests or long
context windows quickly trigger Out-Of-Memory (OOM) errors due to the constrained 4.75 GiB KV cache
safety limit.
• On v6e-4 : Tensor Parallelism shards the 24 GB model weights across the 4 chips. This expands the KV
cache pool to ~101 GiB , completely resolving OOM risks and allowing stable long-context serving.
#### 3. ⚖️ Topology Selection Guide
• Use v6e-1 for Gemma 4 2B/4B single-agent testing, low-concurrency internal SRE automation, or dev
environments.
• Use v6e-4 for Gemma 4 12B in production, or when serving Gemma 4 4B to high-concurrency client
applications.
Cost Breakdown
Finally — the last key question. What deployment is most cost effective?
> compare costs across TPU v6e-1, TPU v6e-4, GCE with GPU, Cloud Run, azure, and AWS EC2 GPU do not use MCP
tool
● Search(Search for cost in files) (ctrl+o to expand)
Here is a cost comparison matrix across Cloud TPU v6e, Google Compute Engine (GCE), Cloud Run, Azure, and
AWS EC2 for serving Gemma 4 models:
### 💵 Cost Comparison Matrix
Provider / Service | Hardware Profile | Spot / Flex Rate | On-Demand Rate | Key Characteristics
----------------------|----------------------|------------------|------------------|----------------------
GCP Cloud TPU | 1x TPU v6e-1 (32 GB | $1.35 / hr | $2.70 / hr (On- | Specialized ML
start) | HBM) | | (On-demand) | silicon; excellent
| | | | throughput/dollar
| | | | for batching.
GCP Cloud TPU (Flex- | 4x TPU v6e-4 (128 GB | $5.40 / hr | $10.80 / hr | Ideal for 12B/31B
start) | HBM) | | (On-demand) | models; solves KV
| | | | cache limits.
GCP GCE VM | 1x NVIDIA L4 GPU (24 | ~$0.30 / hr | ~$1.00 / hr | High portability;
| GB VRAM) | | | runs standard vLLM
| | | | CUDA stack.
GCP GCE VM | 8x NVIDIA L4 GPU | ~$2.40 / hr | ~$8.00 / hr | Distributed CUDA
| (192 GB VRAM) | | | serving; comparable
| | | | to TPU v6e-4.
GCP Cloud Run | 1x NVIDIA L4 GPU (24 | N/A (Pay-per- | ~$1.20 - $1.50 | Zero scale-to-idle
(Serverless) | GB VRAM) | use) | / hr | cost; best for
| | | (equivalent | low/spiky workload
| | | active) | profiles.
AWS EC2 ( g6.xlarge | 1x NVIDIA L4 GPU (24 | ~$0.35 / hr | ~$0.97 / hr | Standard AWS GPU
) | GB VRAM) | | | worker; robust CUDA
| | | | integration.
AWS EC2 ( | 4x NVIDIA A10G (96 | ~$1.85 / hr | ~$5.67 / hr | High VRAM capacity
g5.12xlarge ) | GB VRAM) | | | for multi-GPU
| | | | inference scaling.
Azure VM ( | 1x NVIDIA A10G (24 | ~$0.35 / hr | ~$1.05 / hr | Standard Azure GPU
NVadsA10v5 ) | GB VRAM) | | | instance for
| | | | processing
| | | | workloads.
Azure Container Apps | Serverless L4 GPU | N/A (Pay-per- | ~$1.30 - $1.60 | Serverless GPU
| (24 GB VRAM) | use) | / hr | hosting on Azure AKS
| | | (equivalent | infrastructure.
| | | active) |
──────
### 🔍 Cost-Efficiency Trade-Offs
1. TPU v6e (Flex-start) vs GCE GPU (On-Demand):
• At $1.35/hr , a TPU v6e-1 (32 GB HBM) provides a substantial VRAM speed advantage over a single L4
GPU ( $1.00/hr ) for about a 35% cost premium. The TPU v6e's HBM bandwidth enables much faster batch
token generation.
2. Serverless (Cloud Run / Azure ACA) vs Dedicated VMs:
• For constant 24/7 workloads, dedicated VMs or TPUs are significantly cheaper (e.g., $1.35/hr TPU
Flex vs ~$1.50/hr serverless GPU compute charge).
• For spiky SRE automation tools that run infrequently, serverless options save money by scaling down
to 0 instances when idle, incurring zero costs.
3. Multi-GPU Scaling vs Multi-Chip TPU:
• An 8x L4 GPU instance ( $8.00/hr on-demand) is comparable in raw VRAM capacity to a TPU v6e-4 (
$10.80/hr on-demand / $5.40/hr Flex-start). If you can leverage GCP Flex-start allocations, the TPU
v6e-4 at $5.40/hr is a highly cost-efficient option for running 12B/31B model parameters.
Here is a cost comparison matrix across Cloud TPU v6e, Google Compute Engine (GCE), Cloud Run, Azure, and
AWS EC2 for serving Gemma 4 models:
### 💵 Cost Comparison Matrix
Provider / Service | Hardware Profile | Spot / Flex Rate | On-Demand Rate | Key Characteristics
----------------------|----------------------|------------------|------------------|----------------------
GCP Cloud TPU | 1x TPU v6e-1 (32 GB | $1.35 / hr | $2.70 / hr (On- | Specialized ML
start) | HBM) | | (On-demand) | silicon; excellent
| | | | throughput/dollar
| | | | for batching.
GCP Cloud TPU (Flex- | 4x TPU v6e-4 (128 GB | $5.40 / hr | $10.80 / hr | Ideal for 12B/31B
start) | HBM) | | (On-demand) | models; solves KV
| | | | cache limits.
GCP GCE VM | 1x NVIDIA L4 GPU (24 | ~$0.30 / hr | ~$1.00 / hr | High portability;
| GB VRAM) | | | runs standard vLLM
| | | | CUDA stack.
GCP GCE VM | 8x NVIDIA L4 GPU | ~$2.40 / hr | ~$8.00 / hr | Distributed CUDA
| (192 GB VRAM) | | | serving; comparable
| | | | to TPU v6e-4.
GCP Cloud Run | 1x NVIDIA L4 GPU (24 | N/A (Pay-per- | ~$1.20 - $1.50 | Zero scale-to-idle
(Serverless) | GB VRAM) | use) | / hr | cost; best for
| | | (equivalent | low/spiky workload
| | | active) | profiles.
AWS EC2 ( g6.xlarge | 1x NVIDIA L4 GPU (24 | ~$0.35 / hr | ~$0.97 / hr | Standard AWS GPU
) | GB VRAM) | | | worker; robust CUDA
| | | | integration.
AWS EC2 ( | 4x NVIDIA A10G (96 | ~$1.85 / hr | ~$5.67 / hr | High VRAM capacity
g5.12xlarge ) | GB VRAM) | | | for multi-GPU
| | | | inference scaling.
Azure VM ( | 1x NVIDIA A10G (24 | ~$0.35 / hr | ~$1.05 / hr | Standard Azure GPU
NVadsA10v5 ) | GB VRAM) | | | instance for
| | | | processing
| | | | workloads.
Azure Container Apps | Serverless L4 GPU | N/A (Pay-per- | ~$1.30 - $1.60 | Serverless GPU
| (24 GB VRAM) | use) | / hr | hosting on Azure AKS
| | | (equivalent | infrastructure.
| | | active) |
──────
### 🔍 Cost-Efficiency Trade-Offs
1. TPU v6e (Flex-start) vs GCE GPU (On-Demand):
• At $1.35/hr , a TPU v6e-1 (32 GB HBM) provides a substantial VRAM speed advantage over a single L4
GPU ( $1.00/hr ) for about a 35% cost premium. The TPU v6e's HBM bandwidth enables much faster batch
token generation.
2. Serverless (Cloud Run / Azure ACA) vs Dedicated VMs:
• For constant 24/7 workloads, dedicated VMs or TPUs are significantly cheaper (e.g., $1.35/hr TPU
Flex vs ~$1.50/hr serverless GPU compute charge).
• For spiky SRE automation tools that run infrequently, serverless options save money by scaling down
to 0 instances when idle, incurring zero costs.
3. Multi-GPU Scaling vs Multi-Chip TPU:
• An 8x L4 GPU instance ( $8.00/hr on-demand) is comparable in raw VRAM capacity to a TPU v6e-4 (
$10.80/hr on-demand / $5.40/hr Flex-start). If you can leverage GCP Flex-start allocations, the TPU
v6e-4 at $5.40/hr is a highly cost-efficient option for running 12B/31B model parameters.
────────────────────────────────────────────────────────────
> what has the best price / performance
10.7k in | 1.4k out | 732 thinking
● Bash(python /home/xbill/.gemini/antigravity-cli/brain/e5228a12-98ce-4044-8a61-118088127a...) (ctrl+o to
expand)
Based on a cross-platform comparison of the Gemma 4 12B model serving benchmarks, the Google Cloud TPU
v6e-1 (Flex-start) stands out as the configuration with the best price/performance ratio.
Here is the analytical breakdown of requests-per-second per dollar ($) across the benchmarked
configurations:
### 🏆 Price / Performance Rankings (Gemma 4 12B)
Rank | Configuration | Hourly Rate | Throughput (Peak) | Cost-Efficiency (Throughput / $)
-------|----------------------------|--------------|-------------------|----------------------------------
1 | 🥇 TPU v6e-1 (Flex-start) | $1.35 / hr | 72.83 req/s | 53.95 req/s / $
2 | 🥈 TPU v6e-1 (On-demand) | $2.70 / hr | 72.83 req/s | 26.97 req/s / $
3 | 🥉 GPU L4 × 8 QAT (Spot) | $2.40 / hr | 40.30 req/s | 16.79 req/s / $
4 | GPU L4 × 8 (Spot / FP16) | $2.40 / hr | 23.53 req/s | 9.80 req/s / $
5 | GPU L4 × 8 QAT (On-demand) | $8.00 / hr | 40.30 req/s | 5.04 req/s / $
──────
### 💡 Why TPU v6e-1 Wins on Price/Performance
1. Massive Efficiency Multiplier (3.2x to 10.7x):
• TPU v6e-1 (Flex-start) delivers 53.95 req/s per dollar , making it 3.2x more cost-effective than
the GPU L4 × 8 QAT Spot configuration, and 10.7x more cost-effective than the GPU L4 × 8 QAT On-demand
configuration.
2. Hardware/Software Integration:
• The combination of Trillium ML silicon with vLLM's compiler stack (using JAX/Flax compilation)
allows the TPU to execute model matrix multiplications much faster than general-purpose CUDA GPUs,
resulting in a higher processing throughput.
3. Flex-start VM Discount:
• Leveraging GCP's Flex-start VMs ( v2-alpha-tpuv6e ) cuts TPU cost in half (from $2.70/hr down to $1.
35/hr), making it competitive even with low-end GPU Spot instances while delivering high-tier
performance.
Summary
The strategy for using MCP for Gemma 4 GPU deployment with Antigravity CLI was validated with a incremental step by step approach.
A minimal stdio transport MCP Server was started from Python source code and validated with Antigravity CLI running as a MCP client in the same local environment. This Python server provided all of the management tools to deploy and troubleshoot TPU deployments.






Top comments (0)