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

PRNG Seeding Guidance #2312

Open
lancelet opened this issue Sep 27, 2024 · 1 comment
Open

PRNG Seeding Guidance #2312

lancelet opened this issue Sep 27, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@lancelet
Copy link
Contributor

Request: can the documentation please provide guidance on setting the PRNG seed for consistent tensor initialization?

Running this code produces a different value on every run:

let device = NdArrayDevice::default();
let conv2d = Conv2dConfig::new([1, 1], [1, 1]).init::<NdArray>(&device);
dbg!(conv2d.weight.val().into_data().to_vec::<f32>().unwrap());

In many situations, having a different seed for each run is useful because it allows training from a different initialization. However, it is also frequently useful to fix the seed. For example, in testing scenarios, there are sometimes floating-point comparisons that succeed for particular seeds, but fail in a borderline way for others. To avoid spurious CI failures in such scenarios, fixing the seed to a "known good value for this test run, on my chosen CI backend" is an extremely useful bandaid.

@laggui
Copy link
Member

laggui commented Sep 27, 2024

Using the Backend::seed(seed) method should do the trick.

type B = NdArray;
let device = NdArrayDevice::default();
B::seed(42);
let conv2d = Conv2dConfig::new([1, 1], [1, 1]).init::<B>(&device);
dbg!(conv2d.weight.val().into_data().to_vec::<f32>().unwrap());

It's used across multiple unit tests and examples, but perhaps not documented enough 🤔 Perhaps a bit more info in the Backend section would help?

@laggui laggui added the documentation Improvements or additions to documentation label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants