Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ name = "fastnn"
path = "src/lib.rs"

[dependencies]
rand = "0.8" # weight init, dropout masks, shuffling
rand_distr = "0.4" # normal distribution
rand = "0.10" # weight init, dropout masks, shuffling
rand_distr = "0.6" # normal distribution
rayon = "1.8" # data parallelism on the CPU paths
libm = "0.2" # erff, for exact GELU
ureq = "2.9" # dataset download
Expand Down
8 changes: 4 additions & 4 deletions src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use std::cell::RefCell;

use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use rand::{RngExt, SeedableRng};
use rand_distr::StandardNormal;

thread_local! {
static RNG: RefCell<StdRng> = RefCell::new(StdRng::from_entropy());
static RNG: RefCell<StdRng> = RefCell::new(rand::make_rng());
}

/// Reseed this thread's generator so a run reproduces exactly.
Expand All @@ -25,7 +25,7 @@ pub fn with_rng<T>(f: impl FnOnce(&mut StdRng) -> T) -> T {

/// `n` samples from the uniform distribution on `[lo, hi)`.
pub fn uniform(n: usize, lo: f32, hi: f32) -> Vec<f32> {
with_rng(|rng| (0..n).map(|_| rng.gen_range(lo..hi)).collect())
with_rng(|rng| (0..n).map(|_| rng.random_range(lo..hi)).collect())
}

/// `n` samples from the standard normal distribution.
Expand All @@ -35,7 +35,7 @@ pub fn normal(n: usize) -> Vec<f32> {

/// `n` draws from Bernoulli(`p`), as a bitmask of `true` = kept.
pub fn bernoulli(n: usize, p: f32) -> Vec<bool> {
with_rng(|rng| (0..n).map(|_| rng.gen::<f32>() < p).collect())
with_rng(|rng| (0..n).map(|_| rng.random::<f32>() < p).collect())
}

/// Shuffle in place, using this thread's generator so `manual_seed` covers it.
Expand Down
Loading