---
title: "Unlocking Stable On-Policy RL on TPU with Bitwise-Zero Train"
description: "Reinforcement learning for large language models suffers from numerical instability when the sampler and trainer assign different logprobs to the same action, creating a hidden off-policy gap. This mismatch arises because floating-point addition is non-associative, and differing execution paths use different reduction orders and intermediate precision, especially in bfloat16. The authors’ Zero-TIM implementation closes this gap by locking within-shard kernel accumulation, ordering cross-shard reductions, standardising the logprob scoring tail, and wrapping serving kernels with custom differentiation rules. Verified across 64 TPU v5p chips, the approach records zero mean absolute sampler–trainer logprob difference at every logged step in a 200-step test. The implementation is open-source in Google’s Tunix library and provides a modular blueprint for bit-exact on-policy RL on TPU."
---

# Unlocking Stable On-Policy RL on TPU with Bitwise-Zero Train

[Google](https://yomu.fyi/company/google) · Yuxuan Zhang, Lin Chai, Lance Wang, Tianshu Bao, Weiren Yu · Nov 16, 2026

**Type:** Explainer

## Summary

Reinforcement learning for large language models suffers from numerical instability when the sampler and trainer assign different logprobs to the same action, creating a hidden off-policy gap. This mismatch arises because floating-point addition is non-associative, and differing execution paths use different reduction orders and intermediate precision, especially in bfloat16. The authors’ Zero-TIM implementation closes this gap by locking within-shard kernel accumulation, ordering cross-shard reductions, standardising the logprob scoring tail, and wrapping serving kernels with custom differentiation rules. Verified across 64 TPU v5p chips, the approach records zero mean absolute sampler–trainer logprob difference at every logged step in a 200-step test. The implementation is open-source in Google’s Tunix library and provides a modular blueprint for bit-exact on-policy RL on TPU.

## Context

Reinforcement learning for large language models suffers from numerical instability when the sampler and trainer assign different logprobs to the same action and token history, creating a hidden off-policy gap. This mismatch arises because floating-point addition is non-associative, and differing execution paths (sampler decode vs. trainer forward) use different reduction orders and intermediate precision, especially in bfloat16.

## Approach / What changed

A four-part recipe: (1) batch-invariant Pallas kernels that lock within-shard accumulation order and intermediate precision; (2) explicit cross-shard reduction order via ppermute; (3) standardised logprob scoring tail across decode, prefill, and trainer; (4) custom vector–Jacobian products that reuse serving kernels for forward evaluation and provide separate backward rules.

## Takeaways

- Floating-point non-associativity in bfloat16 reductions causes bitwise logprob differences between sampler and trainer, creating a hidden off-policy gap even when weights are identical.
- Zero-TIM uses batch-invariant Pallas kernels with fixed contraction-block order and float32 accumulation to make within-shard arithmetic independent of token-row count.
- A three-way comparison (sampler decode vs. prefill vs. trainer) systematically isolates whether the numerical gap originates within the serving engine or across the serving–training boundary.

## FAQ

### What is the Zero-TIM alignment contract?

The contract requires that sampler decode, serving prefill, and trainer forward all produce bitwise-identical logprobs for every sampled action under the same weights, token history, and sampling settings, with zero rounding or tolerance.

### Why compare three paths instead of two?

A three-way comparison isolates the source of mismatch: sampler decode vs. prefill checks that the serving engine agrees with itself, and prefill vs. trainer checks agreement across compilation and differentiation boundaries.

### Does Zero-TIM require merging sampler and trainer?

No. The recipe bridges separate serving and training pipelines by fixing within-shard kernel accumulation, ordering cross-shard reductions, standardising the logprob scoring tail, and wrapping serving kernels with custom differentiation rules.

**Tags:** [JAX](https://yomu.fyi/topic/jax), [LLMs](https://yomu.fyi/topic/llm), [Pallas](https://yomu.fyi/topic/pallas), [Reinforcement Learning](https://yomu.fyi/topic/reinforcement-learning), [TPU](https://yomu.fyi/topic/tpu)

- Source: [Google](https://developers.googleblog.com/unlocking-stable-on-policy-rl-on-tpu-with-bitwise-zero-traininference-mismatch)
- Source URL: https://developers.googleblog.com/unlocking-stable-on-policy-rl-on-tpu-with-bitwise-zero-traininference-mismatch
- Ingested by Yomu: 2026-11-16T18:00:17.836Z

[Read original post](https://developers.googleblog.com/unlocking-stable-on-policy-rl-on-tpu-with-bitwise-zero-traininference-mismatch)
