Gemma 4 E2B in Pure JAX on a Colab TPU: Google's 4-Bit Export Against an Exact Repack
This article provides a step by step guide to a Colab notebook that serves Gemma 4 E2B on a single TPU v5e chip with a pure-JAX engine and compares two 4-bit builds of the same model against the weights Google trained. Every number below was measured in the notebook on a Colab v5e-1 runtime, and the executed notebook is committed. Google ships E2B in 4 bits as gemma-4-E2B-it-qat-w4a16-ct . Its…
This article outlines a step-by-step process that demonstrates the advantages of the Gemma 4 E2B 4-bit export compared to an exact re-pack of the same model when using a pure-JAX engine on a Google Colab TPU v5e chip. The measured results were obtained from a Colab v5e-1 runtime, and the notebook containing the execution is available for reference.
Google ships the Gemma 4 E2B model in 4-bit format as gemma-4-E2B-it-qat-w4a16-ct. During the export process, the weights are rounded once more onto a grid that the model was not trained on. On the other hand, a repack that stores the trained grid results in the model being 342.6 times closer to the original in terms of next-token predictions.
This notebook is part of the AI GDE Marathon: JAX on TPU Tutorial series, which covers JAX on the TPU backend. Colab's TPU runtimes are consistent with the source measurements, and every cell in the notebook compares the results to the reader's chip and prints the source result alongside it.
Two 4-bit builds of the same model were created: one using the Hugging Face approach and another built by repacking the trained grid values. The repack stores the trained grid values while Google's export rounds each weight a second time onto a grid that the model never trained on.
To gauge the differences between the models, 24 tensors from the first, middle, and last layers were analyzed, along with 5.7 million groups of 32 weights. The results showed that the repack model's weights were in much closer alignment with the trained values, while Google's export was significantly less accurate.
By feeding each model a fixed prompt and comparing their predicted next-token distributions, it became clear that the repack model achieved better results at every position compared to the stock build. Consequently, the repack model performed 99.29% better at matching the top token and 342.6 times better than the stock build in terms of overall performance.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to