Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buggy interaction: remat, automatic partitioning, and unsafe rbg-based RNGs #21046

Open
froystig opened this issue May 3, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@froystig
Copy link
Member

froystig commented May 3, 2024

Description

Consider the interaction of the following features:

  1. jax.remat
  2. rbg or unsafe_rbg RNG implementations
  3. the XLA flag xla_tpu_spmd_rng_bit_generator_unsafe
  4. 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.

@froystig froystig added the bug Something isn't working label May 3, 2024
mattjj added a commit to mattjj/jax that referenced this issue May 3, 2024
mattjj added a commit to mattjj/jax that referenced this issue May 3, 2024
needs tests!

Co-authored-by: Roy Frostig <frostig@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants