← Latest papers
🤖 AI

Fine-Tuning and Serving Gemma 4 31B on Google Cloud TPU: A Technical Comparison with GPU Baselines

This paper presents the first end-to-end demonstration of fine-tuning and serving Gemma 4 31B on Google Cloud TPUs, detailing the necessary code adaptations to port GPU-native workflows to the JAX stack and demonstrating that the TPU configuration achieves 1.61x faster training at 1.82x lower cost with comparable inference throughput and significantly reduced latency compared to H100 GPU baselines.

Original authors: Jatin Kishnani, Mayank Goel, Amit Singh, Pulkit Agrawal, Sairanjan Mishra

Published 2026-05-26
📖 5 min read🧠 Deep dive

Original authors: Jatin Kishnani, Mayank Goel, Amit Singh, Pulkit Agrawal, Sairanjan Mishra

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to teach a brilliant but very expensive robot (an AI model) a new skill: writing computer code for electronic circuits (Verilog). You have two options for the "school" where this training happens:

  1. The GPU School: Run by NVIDIA, using their famous H100 chips. This is the standard, well-trodden path with lots of experienced teachers.
  2. The TPU School: Run by Google, using their custom TPU chips. This is a newer, highly specialized campus that is faster and cheaper but requires you to learn a completely new language to get in.

This report from h2loop.ai is a "field guide" written by engineers who decided to try the Google TPU school. They took a 31-billion-parameter AI model (Gemma 4) and taught it to write code, then compared how well it worked against the standard NVIDIA school.

Here is the breakdown of their journey, explained simply:

1. The Language Barrier (The "Porting" Problem)

The biggest hurdle wasn't the hardware itself; it was the software.

  • The GPU School speaks PyTorch, a popular programming language that most AI developers already know.
  • The TPU School speaks JAX, a different language that requires a different way of thinking.

The authors had to translate their entire "lesson plan" from PyTorch to JAX. They had to:

  • Rearrange how the model's brain is split up across multiple chips (like organizing a library where books are scattered across 4 different rooms instead of 2).
  • Rename specific parts of the model because the TPU school calls things differently (e.g., calling a "q_proj" a "q_einsum").
  • Build a custom "bridge" to save their work, because the TPU school uses a different filing system (Orbax) than the rest of the world (Safetensors).

The Analogy: It's like moving a house. The furniture (the AI model) is the same, but the new house (TPU) has different doorways and floor plans. You have to disassemble the furniture, carry it through the new doors, and reassemble it, or it won't fit.

2. The Training Race (Teaching the Robot)

Once they got the model set up, they started the training race.

  • Speed: The TPU school was 1.6 times faster. It finished the training course in 3.3 hours, while the GPU school took 5.4 hours.
  • Cost: Because the TPU school charges less per hour and finishes faster, the total bill was 2.1 times cheaper.
    • GPU Bill: ~$119
    • TPU Bill: ~$56

Why was TPU faster?
Think of the TPU chips as a team of 4 runners passing a baton (data) to each other extremely quickly via a super-fast internal highway (ICI). The GPU school only had 2 runners. Even though the individual GPU runners were slightly faster, the TPU team's ability to coordinate and move data together made the whole team win.

3. The Exam (Did the Robot Learn?)

After training, they tested the robots on a Verilog coding exam.

  • The Result: The robot trained on GPUs scored slightly higher (about 5% better) on the hardest questions.
  • The Catch: The authors noted this difference is likely because the two schools graded the exams slightly differently (one ignored the "prompt" part of the question, the other didn't), not because one robot was inherently smarter. The difference wasn't statistically huge.

4. The Job Interview (Serving the Model)

After training, the model needs to be put to work, answering user questions in real-time. This is called "inference." They tested how fast the model could answer questions of different lengths.

  • Short Questions (Simple tasks):

    • The GPU school was slightly faster at answering very short questions.
    • It was also slightly cheaper per answer for these quick tasks.
    • Analogy: If you just need to buy a single coffee, the local shop (GPU) is slightly more efficient.
  • Long Questions (Complex tasks):

    • When the questions got long (4,000+ words), the TPU school absolutely crushed it.
    • Speed: The TPU was 23 times faster at starting to answer a long question (Time-to-First-Token).
    • Capacity: The TPU could handle 4 times more people asking long questions at the same time without slowing down.
    • Analogy: If you need to write a whole novel, the TPU school has a massive library and a team of writers who can work together seamlessly. The GPU school gets overwhelmed and starts dropping books.

5. The Final Verdict

The authors conclude that for their specific needs (training a large model and serving it to users), Google's TPU is the winner.

  • Training: TPU is the clear champion (Faster and much cheaper).
  • Inference: TPU is the champion for anything complex or long. For very simple, short tasks, the GPU is still slightly better.
  • Total Cost: When you add up the training cost and a day of serving users, the TPU setup was 1.8 times cheaper overall.

The Bottom Line:
Switching to the TPU school required a lot of hard work upfront (learning a new language, fixing the furniture, building bridges). But once they got settled, the school ran faster, cost less, and handled big, complex jobs much better than the traditional GPU school. For a company doing heavy AI work, the extra effort to switch was worth the savings and performance.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →