-
Notifications
You must be signed in to change notification settings - Fork 12
Make particle Gibbs deterministic across architectures #109
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
Conversation
0de34e8
to
8dc147c
Compare
8dc147c
to
d98ba71
Compare
Pull Request Test Coverage Report for Build 12891599012Details
💛 - Coveralls |
a765ccb
to
f7abf64
Compare
N_SAMPLES = 50 | ||
N_SAMPLES = 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to bump this to get the test to pass.
It's not possible to put in a test that checks that it's the same result across architectures (we could compare to a fixed value, but that would be very brittle). But this at least demonstrates that sampling a Turing model with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work figuring this out! This has been bugging me, too, for a while now.
@FredericWantiez implemented this splittable pseudo-random number generator (PRNG). The splitting step requires some attention since not all splitting is valid. See 1. There is a package for this splittable PRNGs, which we could depend on: https://github.com/Julia-Tempering/SplittableRandoms.jl See, also: https://github.com/janestreet/splittable_random Footnotes
|
Thank you, @yebai, I was reading this over lunch :) For context, the RNG stream being used right now is Philox which is described here: https://www.thesalmons.org/john/random123/papers/random123sc11.pdf I'm not really certain that our original implementation of So it seems to me that this is at least no worse, and maybe we could rework the RNG system in another PR, perhaps? Let me know what you think. |
Does SplittableRandoms.jl provide enough functionality for our purpose? If so, it's okay to depend on it -- it is a very lightweight package without any dependencies other than the Julia standard library. |
Thanks @penelopeysm for the fix. I don't think there was an implementation of |
I'm in favour of switching over, and I think that it does have exactly the right functionality, but looking at AdvancedPS right now, it seems to me that that would require a fairly substantial reworking of the whole I'd prefer to merge this and open another issue for that (unless there are concerns over this PR itself, of course). |
We could also tweak |
@penelopeysm feel free to merge and open an issue for it. |
Fixes #108
The problem was in this function
split
:AdvancedPS.jl/src/rng.jl
Lines 33 to 41 in 379336b
Here,
UInt(1)
givesUInt64
on 64-bit systems., andUInt32
on 32-bit. Thus, the result ofhash
was different, despite ensuring that we convert back to the same type at the end.The 'simple' solution of replacing
UInt
withUInt64
doesn't work, because on 32-bit systems,hash(::UInt64, ::UInt64)
is not defined.This PR therefore uses a pseudo-random number generator to deterministically generate new values of type
T
from the original value.