-
Notifications
You must be signed in to change notification settings - Fork 242
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
[compiler] enable new rng #12139
[compiler] enable new rng #12139
Conversation
b66a21e
to
70bd0d7
Compare
54355a8
to
d5d45a6
Compare
466aa3c
to
887be15
Compare
a2f9da9
to
57d245c
Compare
The seed can also be set globally using :func:`.set_global_seed`. This sets the | ||
seed globally for all subsequent Hail operations, and a pipeline will be | ||
guaranteed to have the same results if the global seed is set right beforehand: | ||
|
||
>>> hl.set_global_seed(0) | ||
>>> hl.eval(hl.array([hl.rand_unif(0, 1), hl.rand_unif(0, 1)])) # doctest: +SKIP_OUTPUT_CHECK | ||
[0.6830630912401323, 0.4035978197966855] | ||
>>> hl.reset_global_randomness() | ||
>>> hl.eval(hl.array([hl.rand_unif(0, 1), hl.rand_unif(0, 1)])) | ||
[0.9828239225846387, 0.49094525115847415] | ||
|
||
>>> hl.set_global_seed(0) | ||
>>> hl.eval(hl.array([hl.rand_unif(0, 1), hl.rand_unif(0, 1)])) # doctest: +SKIP_OUTPUT_CHECK | ||
[0.6830630912401323, 0.4035978197966855] |
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.
The text above references set_global_seed
which the code does not.
I think I'm a bit confused. The text above says that the global seed "is fixed for the entire session", but we appear to modify it here.
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.
Ah thanks, meant to remove all mentions of set_global_seed
2eac02d
to
40bd755
Compare
40bd755
to
0660e1f
Compare
I resolved conflicts. There were two issues in ir.py and one in aggregators.py. The former were resolved by: replace if with assert, add a new field about needing randomness. The latter is visible in the diff and switches from frozenset to set. |
Bumping this PR, I'd like it to land so I can nail down exactly why my flags PR is causing BN tests to fail. |
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.
Tiny comments. Python IR and Scala RNG changes are super clear, great work.
static_rng_uid = Env.next_static_rng_uid() | ||
else: | ||
if Env._hc is None or not Env._hc._user_specified_rng_nonce: | ||
warning('To ensure reproducible randomness across Hail sessions, ' |
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.
warning calls through to initialize, I think -- is this intentional? Fine if yes, just good to be aware.
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 didn't realize, but I think that's fine. The warning is saying you should really initialize manually before doing anything else, not to worry about what functions do or don't implicitly initialize.
@@ -383,7 +381,7 @@ def _spectral_moments(A, num_moments, p=None, moment_samples=500, block_size=128 | |||
# TODO: When moment_samples > n, we should just do a TSQR on A, and compute | |||
# the spectrum of R. | |||
assert moment_samples < n, '_spectral_moments: moment_samples must be smaller than num cols of A' | |||
G = hl.nd.zeros((n, moment_samples)).map(lambda n: hl.if_else(hl.rand_bool(0.5), -1, 1)) | |||
G = hl.rand_unif(-1, 1, size=(n, moment_samples)).map(lambda x: hl.sign(x)) |
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.
good change.
Env._seed_generator = hail.utils.HailSeedGenerator(seed) | ||
def next_static_rng_uid(): | ||
result = Env._static_rng_uid | ||
assert(result <= 0xFFFF_FFFF_FFFF_FFFF) |
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.
This should keep Konrad contained for at least a few years
hail/src/main/scala/is/hail/types/physical/PCanonicalNDArray.scala
Outdated
Show resolved
Hide resolved
# Conflicts: # hail/python/hail/ir/__init__.py # hail/python/hail/ir/ir.py # hail/python/test/hail/table/test_table.py # hail/python/test/hail/utils/test_google_fs_utils.py
This is still stacked on #12309 as well |
This seems to be triggering hail initialization somewhere it not to? |
055d8e2
to
b7314c1
Compare
Ah, it was just a new test file that used |
@tpoterba Tests are passing |
Ship it! |
Thank you both! |
Stacked on #12331 and #12309.Design doc here.