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

Fix PRNG handling in nn.jit under nn.scan. #4359

Merged
merged 1 commit into from
Nov 8, 2024
Merged

Conversation

copybara-service[bot]
Copy link

@copybara-service copybara-service bot commented Nov 6, 2024

Fix PRNG handling in nn.jit under nn.scan.

  • nn.scan does an abstract eval before compilation to check for constants that are then traced out. Before this change, the abstract eval increments static RNG counters, which creates a side-effect where RNG counters are not properly updated once inner functions are jitted (i.e., under nn.jit).
  • In this fix, we cache the impact a first pass through nn.scan and nn.jit would have on rng counters and "replay" that impact on subsequent passes so that rng state remains unaffected.
  • This solution doesn't affect PRNG derivations outside this isolated case and is a placeholder while a more permanent solution, which would affect PRNG derivations, is worked out.

Copy link

google-cla bot commented Nov 6, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@copybara-service copybara-service bot changed the title Fix PRNG handling of nn.jit under nn.scan. Fix PRNG handling in nn.jit under nn.scan. Nov 6, 2024
* `nn.scan` does an abstract eval before compilation to check for constants that are then traced out. Before this change, the abstract eval increments static RNG counters, which creates a side-effect where RNG counters are not properly updated once inner functions are jitted (i.e., under `nn.jit`).
* In this fix, we cache the impact a first pass through `nn.scan` and `nn.jit` would have on rng counters and "replay" that impact on subsequent passes so that rng state remains unaffected.
* This solution doesn't affect PRNG derivations outside this isolated case and is a placeholder while a more permanent solution, which would affect PRNG derivations, is worked out.

PiperOrigin-RevId: 694463650
@copybara-service copybara-service bot merged commit 0f631a2 into main Nov 8, 2024
1 check was pending
@copybara-service copybara-service bot deleted the test_692231015 branch November 8, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant