jax
jax copied to clipboard
buggy interaction: remat, automatic partitioning, and unsafe `rbg`-based RNGs
Description
Consider the interaction of the following features:
-
jax.remat
-
rbg
orunsafe_rbg
RNG implementations - the XLA flag
xla_tpu_spmd_rng_bit_generator_unsafe
- automatic partitioning
remat
says: jax, you are free not to save the output of a random draw, instead only save the key and recompute random bits from it. The system is happy to do this because RNGs are by assumption functional and deterministic.
rbg
and unsafe_rbg
RNGs say: produce random bits from XLA's RngBitGenerator
HLO.
The XLA flag xla_tpu_spmd_rng_bit_generator_unsafe
says: random bits produced by a given key are allowed to vary based on the sharding of generated random bit arrays.
Automatic partitioning says: compiler, you are free to shard random bit arrays however makes sense, potentially sharding them differently when rematerializing them in the generated VJP.
Putting these together, random bits rematerialized (from the same random key) might be different between forward and backward passes in a VJP.
System info (python version, jaxlib version, accelerator, etc.)
0.4.27.dev
with 0.4.26
jaxlib.