Urgent.News

What's breaking now, across hundreds of outlets.

AI

One Decorator, 6x Faster: JAX Basics for Inference in 30 Minutes

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…

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.

JAX 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.

JAX 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.

When 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.

Grad, 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.

Sharding, 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.

Two 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.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

We let Claude Code edit our Instagram reels. The edit is a TypeScript file

I sent two messages and got a finished 25 second reel back, scheduled for Thursday. It cost us $0.30 in generations and 23 minutes of waiting. Nobody opened a timeline.

  • Claude Code edited Instagram reels using a TypeScript file
  • Process involved writing, rendering, and fixing issues
  • Tool End Frame documented successful and unsuccessful results

Before an AI Agent Automates a Salesforce Process, Let the Team Flag What Breaks

On LinkedIn I shared a story about a meeting with eight people. All eight knew the AI agent project on the table made no sense, and nobody said it.

  • Team member with process experience proposed fix months prior but was ignored.
  • Salesforce setup allows team members to flag process issues in two minutes.
  • Report review before AI agent project to address manual workarounds.

More from Sunday, 29 November 2026 →