Skip to content

Fix RNG seeding and reject generators nothing advances - #75

Merged
jessegrabowski merged 5 commits into
pymc-devs:mainfrom
jessegrabowski:rng-seeding-and-safety
Aug 10, 2026
Merged

Fix RNG seeding and reject generators nothing advances#75
jessegrabowski merged 5 commits into
pymc-devs:mainfrom
jessegrabowski:rng-seeding-and-safety

Conversation

@jessegrabowski

Copy link
Copy Markdown
Member

Compiling reseeded every generator it touched, so a seed the caller set never survived, and compiling a second function jumped the stream of one already drawing. Generators are left alone now unless you pass random_seed — deliberately the opposite of pymc's default, which is there for cached functions rather than training loops.

A Dropout applied twice in one network also shared a single generator between two draws, which pytensor treats as inconsistent and threads no update for, so the mask froze for the whole run. Each application gets its own generator now, and a graph that still draws from a generator nothing advances raises instead of warning.

Two draws off one generator leave it with no single next state, so pytensor threads no update for it; one generator per draw is how pymc avoids the same problem.
Reseeding on every compile discarded any seed the caller had set and jumped the stream of any function already drawing from that generator; pymc reseeds by default and offers random_seed=False for the same reason we now default to leaving them alone.
A rule that perturbs its step reads a generator the outputs never touch, so collecting from the outputs alone left it frozen and every step took the identical perturbation.
Supersedes a UserWarning that announced a silently frozen training run; the check is on the assembled updates, so a caller who advances the generator themselves still passes.
@codecov-commenter

codecov-commenter commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.39%. Comparing base (10aae8a) to head (ad01805).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #75      +/-   ##
==========================================
+ Coverage   93.65%   95.39%   +1.74%     
==========================================
  Files          45       45              
  Lines        1766     1782      +16     
==========================================
+ Hits         1654     1700      +46     
+ Misses        112       82      -30     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Each error message already says what happened and how to get out of it, and that is the copy a stuck user actually reads.
@jessegrabowski
jessegrabowski merged commit cf70a80 into pymc-devs:main Aug 10, 2026
7 checks passed
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.

2 participants