Skip to content

Conversation

@CharlieFRuan
Copy link
Member

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
Member 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
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.
atebites-hub pushed a commit to atebites-hub/web-llm that referenced this pull request Oct 4, 2025
This version supports seeding generation, for more see:
- mlc-ai#335

On TVMjs side, we make the runtime seedable via:
- apache/tvm#16722
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