{
  "id": 22622156,
  "title": "One Decorator, 6x Faster: JAX Basics for Inference in 30 Minutes",
  "url": "https://urgent.news/2026/11/29/one-decorator-6x-faster-jax-basics-for-inference-in-30-minutes",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-29T17:07:34.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/danielsamfdo/one-decorator-6x-faster-jax-basics-for-inference-in-30-minutes-46n4"
  },
  "original_language": null,
  "account": "JAX is a library that forms the foundation of Google's AI stack, including the model Gemma, and runs efficiently on TPUs. It consists of three key concepts: jit, grad, and sharding. This post, the first in Lane B, is a crucial foundation for understanding the rest of the material on Gemma, Keras, and TPU.\n\nJAX is not a framework to be learned, but rather three function transformations that can be composed. The source material shows measured results, with a fusion of elementwise chain under jit running 6.13 times faster than its eager counterpart, whereas a 4096x4096 matmul only improves by 1.21 times. This difference arises because a single BLAS call is already fast, leaving little room for optimization.\n\nJAX utilizes jit to compile functions, grad to differentiate them, and sharding to split computations across devices. jit watches the entire Python function first, then cooks it all in one pass, without returning to the 'sink' (i.e., recompiling). This is achieved by tracing the function, lowering the trace to XLA, and compiling it. The first call pays for this compilation, but subsequent calls benefit from the saved time.\n\nWhen jit is used as a serving decision, it becomes beneficial for inference loops, as the compilation tax is amortized over multiple calls. However, if a function is called only once, eager execution may be faster. The gradient-step computation example demonstrates this, with a 512x64 linear-loss gradient step taking 0.01ms under jit, compared to 17.80ms under eager execution.\n\nGrad, or differentiation, is also an essential aspect of JAX. It provides exact derivatives and composes well, allowing for multiple derivatives to be calculated with ease. For inference, the vmap function can be used to compute gradients across an entire batch in a single call, eliminating the need for Python loops.\n\nSharding, the third concept, is a memory decision based on arithmetic rather than fashion. It becomes necessary when the model cannot fit on a single device, such as in the case of larger Gemma models. The notebook demonstrates how to implement sharding using named sharding and a Mesh for two-way tensor parallelism for a 27B model in bf16.\n\nTwo significant changes were introduced in JAX 0.12. The legacy GSPMD partitioner has been removed, and the Shardy partitioner is now the default. Additionally, jax.pmap has been replaced with a wrapper around jit(shard_map), removing the old C++ pmap infrastructure and device_put_sharded and device_put_replicated functions.",
  "summary": "JAX is the library behind most of Google's AI stack — the same numerical core that trains Gemma and runs on TPUs — and it fits in three ideas: jit compiles your function, grad differentiates it, and sharding splits it across devices. This is GDE post #11, the first post in Lane B, and it is the one the rest of the lane stands on: every Gemma, Keras, and TPU post that follows assumes you can read…",
  "summary_source": "publisher",
  "key_points": [
    "JAX library forms Google's AI stack foundation, runs efficiently on TPUs",
    "jit, grad, and sharding are JAX's three key concepts for function transformations",
    "jit improves inference loops by 6.13x, while matmul only improves by 1.21x"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}