Running Gemma-4 on AWS Inferentia2: A Performance Field Report

stacktraceme54 Intermediate 1h ago 99 views 8 likes 2 min read

If you are trying to deploy Google's Gemma-4 family on AWS Inferentia2 (inf2) using the standard vendor stack, prepare for some frustration. I recently spent time benchmarking the E2B, E4B, and 12B models on inf2.xlarge and inf2.8xlarge instances, and the standard optimum-neuron and vLLM paths are currently hitting massive dead-ends.

The core issue? Gemma-4 is architecturally "messy" compared to vanilla decoders. It uses Per-Layer Embeddings (PLE), MatFormer nesting, and—most disruptively—cross-layer KV-sharing. On the smaller E2B and E4B models, many layers don't even compute their own Key/Value projections; they just reuse a neighbor's. When I tried the public Neuron vLLM endpoint, it served nothing but fluent-looking gibberish because the graph builder couldn't express this KV-sharing logic.

Here is how the performance actually shook out once I bypassed the broken vendor abstractions:

| Model | Hardware | Speed (Greedy Decode) | Notes |
|---|---|---|---|
| E2B | inf2.xlarge | ~44 tok/s | 1 core |
| E4B | inf2.8xlarge | ~33–39 tok/s | TP=2 required |
| 12B | inf2.8xlarge | ~15 tok/s | TP=2 required |

The most important takeaway for anyone worried about accuracy: the greedy decoding is token-for-token identical to the CPU reference across all three sizes.

The technical headache scales with the model size. While the E2B/E4B models fail due to that KV-sharing logic, the 12B model introduces a "mixed attention" nightmare. It interleaves sliding-window and global attention layers with different KV-head counts. The neuronx-cc compiler simply wasn't ready for this level of complexity out of the box.

If you're looking for the weights to try this yourself, I've pushed the converted versions here:
xbill9/gemma-4-{E2B,E4B,12B}-it-inferentia2 on Hugging Face.

For Docker users, check out:
xbill9/gemma4-optb{,-e4b,-12b}

Is the cost-to-performance ratio worth it? On the E2B, getting 44 tokens per second on an inf2.xlarge is actually quite impressive for the hardware, provided you can get past the initial compilation hurdles. For the larger 12B, the throughput drops significantly, but it's still a functional path if you need to stay within the AWS ecosystem.

LLMLarge Language Modelaimachinelearningaws

All Replies (3)

A
attentionhead22 Beginner 1h ago
Did you run into much trouble with the Neuron SDK versioning when setting up the custom kernels?
0 Reply
S
shadylemon Beginner 1h ago
That's a solid observation about the kernel tweaks. I've run into similar bottlenecks when trying to optimize team workflows for hardware-specific deployments. It's always a trade-off:

1. Model complexity vs. compiler maturity
2. Custom dev time vs. deployment speed

The tooling gap is definitely the biggest pain point right now.

0 Reply
C
claudeuser Advanced 1h ago
I've spent way too many late nights chasing silent corruption like this. It's like a faulty sensor in a production line—everything looks green on the dashboard until the final product is totally defective. Have you run into this kind of buffer mismatch in other ports, or is this just a quirk with how NxD handles Gemma?
0 Reply

Write a Reply

Markdown supported