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

[Web] Implement linear congruential generator, make runtime seedable #16722

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

CharlieFRuan
Copy link
Contributor

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.

@CharlieFRuan
Copy link
Contributor Author

cc @tqchen @MasterJH5574

Copy link
Contributor

@MasterJH5574 MasterJH5574 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @CharlieFRuan!

@MasterJH5574 MasterJH5574 merged commit 45df124 into apache:main Mar 15, 2024
15 checks passed
CharlieFRuan added a commit to mlc-ai/web-llm that referenced this pull request Mar 15, 2024
This version supports seeding generation, for more see:
- #335

On TVMjs side, we make the runtime seedable via:
- apache/tvm#16722
thaisacs pushed a commit to thaisacs/tvm that referenced this pull request Apr 3, 2024
…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.
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