-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Support] Linear Congruential Random Engine #8642
Conversation
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.
Thanks Xiyou! It overall looks good to me, especially the random numbers in cpptests :-) Please fix the minor comments
The CI got stuck so I retriggered just now |
To be crystal clear, the engine cannot be "serialized" because it is stateless. Its state is managed by the outside environment via a pointer to |
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.
LGTM. Just a nit.
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.
Thanks Xiyou!
CC @areusch @electriclilies if you guys are interested in review |
Going to merge it in by the end of the day if there are no more comments :-) |
* Add linear congruential engine. * Fix typo. * Minor fix. * Fix comments and intros. * Change to unsigned. * Minor comment fix. * Fix unsigned rand state to signed.
* Add linear congruential engine. * Fix typo. * Minor fix. * Fix comments and intros. * Change to unsigned. * Minor comment fix. * Fix unsigned rand state to signed.
* Add linear congruential engine. * Fix typo. * Minor fix. * Fix comments and intros. * Change to unsigned. * Minor comment fix. * Fix unsigned rand state to signed.
…16722) This PR implements `LinearCongruentialGenerator` in TVMjs, following the C++ counterpart in #8642. The motivation is that we want to seed autoregressive generation to make results reproducible, supporting the OpenAI field `seed`. The main function is `nextInt()`, which generates a number `(0, 2^32 - 1)` non-inclusive. Subsequently, we change all `Math.random()` in `runtime.ts` to `this.rng.randomFloat()`, exposing API `Instance.setSeed()`. Unit tests are added for `LinearCongruentialGenerator` for testing seed and coverage.
…pache#16722) This PR implements `LinearCongruentialGenerator` in TVMjs, following the C++ counterpart in apache#8642. The motivation is that we want to seed autoregressive generation to make results reproducible, supporting the OpenAI field `seed`. The main function is `nextInt()`, which generates a number `(0, 2^32 - 1)` non-inclusive. Subsequently, we change all `Math.random()` in `runtime.ts` to `this.rng.randomFloat()`, exposing API `Instance.setSeed()`. Unit tests are added for `LinearCongruentialGenerator` for testing seed and coverage.
This PR introduce a new implementation of linear congruential engine and its test. This linear congruential engine is a drop-in replacement for and strictly corresponds to
std::minstd_rand
but designed to be serializable and strictly reproducible. Specifically implemented for meta schedule but also reusable for other purposes.The main differences are as follows:
int64_t
variable. Therefore, the state of the random engine can be serialized as a singleint64_t
.std::minstd_rand
.