From 57738bbefac79d3b006291cc55d728790e3938bf Mon Sep 17 00:00:00 2001 From: nerdai Date: Thu, 27 Feb 2025 13:46:55 -0500 Subject: [PATCH] update rand package --- Cargo.lock | 97 +++++++++++++++++++++++++++++--------- Cargo.toml | 2 +- src/exercises/ch07.rs | 4 +- src/listings/ch02.rs | 4 +- src/listings/ch05.rs | 2 +- src/listings/ch06.rs | 4 +- src/listings/ch07/bonus.rs | 6 +-- src/listings/ch07/mod.rs | 4 +- 8 files changed, 87 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c53a47..07e8768 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,7 +39,7 @@ dependencies = [ "getrandom 0.2.15", "once_cell", "version_check", - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -557,7 +557,7 @@ dependencies = [ "memmap2", "num-traits", "num_cpus", - "rand", + "rand 0.8.5", "rand_distr", "rayon", "safetensors", @@ -580,7 +580,7 @@ dependencies = [ "image", "memmap2", "parquet", - "rand", + "rand 0.8.5", "thiserror 1.0.68", "tokenizers 0.19.1", ] @@ -597,7 +597,7 @@ dependencies = [ "indicatif", "log", "num_cpus", - "rand", + "rand 0.8.5", "reqwest", "serde", "serde_json", @@ -1598,7 +1598,7 @@ dependencies = [ "cfg-if", "crunchy", "num-traits", - "rand", + "rand 0.8.5", "rand_distr", ] @@ -1664,7 +1664,7 @@ dependencies = [ "log", "native-tls", "num_cpus", - "rand", + "rand 0.8.5", "reqwest", "serde", "serde_json", @@ -2322,7 +2322,7 @@ dependencies = [ "phf", "plotly", "polars", - "rand", + "rand 0.9.0", "reqwest", "rstest", "serde", @@ -2902,7 +2902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ "phf_shared", - "rand", + "rand 0.8.5", ] [[package]] @@ -2964,7 +2964,7 @@ dependencies = [ "erased-serde", "once_cell", "plotly_derive", - "rand", + "rand 0.8.5", "rinja", "serde", "serde_json", @@ -3105,7 +3105,7 @@ dependencies = [ "polars-row", "polars-schema", "polars-utils", - "rand", + "rand 0.8.5", "rand_distr", "rayon", "regex", @@ -3147,7 +3147,7 @@ dependencies = [ "polars-row", "polars-time", "polars-utils", - "rand", + "rand 0.8.5", "rayon", ] @@ -3405,7 +3405,7 @@ dependencies = [ "polars-plan", "polars-time", "polars-utils", - "rand", + "rand 0.8.5", "regex", "serde", "sqlparser", @@ -3433,7 +3433,7 @@ dependencies = [ "polars-parquet", "polars-plan", "polars-utils", - "rand", + "rand 0.8.5", "rayon", "recursive", "slotmap", @@ -3482,7 +3482,7 @@ dependencies = [ "num-traits", "once_cell", "polars-error", - "rand", + "rand 0.8.5", "raw-cpuid 11.2.0", "rayon", "stacker", @@ -3517,7 +3517,7 @@ version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -3575,8 +3575,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.2", + "zerocopy 0.8.20", ] [[package]] @@ -3586,7 +3597,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.2", ] [[package]] @@ -3598,6 +3619,16 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "rand_core" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a509b1a2ffbe92afab0e55c8fd99dea1c280e8171bd2d88682bb20bc41cbc2c" +dependencies = [ + "getrandom 0.3.1", + "zerocopy 0.8.20", +] + [[package]] name = "rand_distr" version = "0.4.3" @@ -3605,7 +3636,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", ] [[package]] @@ -4583,7 +4614,7 @@ dependencies = [ "monostate", "onig", "paste", - "rand", + "rand 0.8.5", "rayon", "rayon-cond", "regex", @@ -4615,7 +4646,7 @@ dependencies = [ "monostate", "onig", "paste", - "rand", + "rand 0.8.5", "rayon", "rayon-cond", "regex", @@ -5429,7 +5460,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "byteorder", - "zerocopy-derive", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde3bb8c68a8f3f1ed4ac9221aad6b10cece3e60a8e2ea54a6a2dec806d0084c" +dependencies = [ + "zerocopy-derive 0.8.20", ] [[package]] @@ -5443,6 +5483,17 @@ dependencies = [ "syn", ] +[[package]] +name = "zerocopy-derive" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eea57037071898bf96a6da35fd626f4f27e9cee3ead2a6c703cf09d472b2e700" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zerofrom" version = "0.1.4" @@ -5541,7 +5592,7 @@ dependencies = [ "lzma-rs", "memchr", "pbkdf2", - "rand", + "rand 0.8.5", "sha1", "thiserror 2.0.7", "time", diff --git a/Cargo.toml b/Cargo.toml index 7fd46e5..ebc3fb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ ndarray = "0.16.1" phf = { version = "0.11.3", features = ["macros"] } plotly = "0.12.1" polars = { version = "0.46.0", features = ["csv", "dtype-struct", "lazy", "parquet", "rows"] } -rand = "0.8.5" +rand = "0.9.0" reqwest = { version = "0.12.12", features = ["blocking", "json"] } rstest = "0.24.0" serde = { version = "1.0.217", features = ["derive"] } diff --git a/src/exercises/ch07.rs b/src/exercises/ch07.rs index 7dba671..e6b4e58 100644 --- a/src/exercises/ch07.rs +++ b/src/exercises/ch07.rs @@ -662,7 +662,7 @@ pub mod addons { DEFAULT_PAD_TOKEN_ID, }; use candle_core::{Device, Result, Tensor}; - use rand::{seq::SliceRandom, thread_rng}; + use rand::{rng, seq::SliceRandom}; use std::rc::Rc; use tiktoken_rs::CoreBPE; @@ -752,7 +752,7 @@ pub mod addons { pub fn new(dataset: InstructionDataset, shuffle: bool) -> Self { let mut remaining_indices = (0..dataset.len()).rev().collect::>(); if shuffle { - remaining_indices.shuffle(&mut thread_rng()); + remaining_indices.shuffle(&mut rng()); } Self { dataset, diff --git a/src/listings/ch02.rs b/src/listings/ch02.rs index afb4dd4..2222e84 100644 --- a/src/listings/ch02.rs +++ b/src/listings/ch02.rs @@ -3,7 +3,7 @@ use candle_core::{Device, Result, Tensor}; use candle_datasets::{batcher::IterResult2, Batcher}; use fancy_regex::{Captures, Regex}; -use rand::{seq::SliceRandom, thread_rng}; +use rand::{rng, seq::SliceRandom}; use std::collections::HashMap; use std::fs; use std::rc::Rc; @@ -285,7 +285,7 @@ impl GPTDatasetIter { pub fn new(dataset: GPTDatasetV1, shuffle: bool) -> Self { let mut remaining_indices = (0..dataset.len()).rev().collect::>(); if shuffle { - remaining_indices.shuffle(&mut thread_rng()); + remaining_indices.shuffle(&mut rng()); } Self { dataset, diff --git a/src/listings/ch05.rs b/src/listings/ch05.rs index 2e7cb48..c6ada23 100644 --- a/src/listings/ch05.rs +++ b/src/listings/ch05.rs @@ -10,7 +10,7 @@ use candle_nn::{ops::softmax, Optimizer, VarMap}; use itertools::Itertools; use plotly::{common::Mode, layout::Axis, Layout, Plot, Scatter}; use rand::{ - distributions::{Distribution, WeightedIndex}, + distr::{weighted::WeightedIndex, Distribution}, rngs::StdRng, SeedableRng, }; diff --git a/src/listings/ch06.rs b/src/listings/ch06.rs index 41a1a78..72378bb 100644 --- a/src/listings/ch06.rs +++ b/src/listings/ch06.rs @@ -14,7 +14,7 @@ use hf_hub::api::sync::Api; use plotly::{common::Mode, layout::Axis}; use plotly::{Layout, Plot, Scatter}; use polars::prelude::*; -use rand::{seq::SliceRandom, thread_rng}; +use rand::{rng, seq::SliceRandom}; use std::cmp; use std::fs::{create_dir_all, remove_file, rename, File}; use std::io; @@ -466,7 +466,7 @@ impl SpamDatasetIter { pub fn new(dataset: SpamDataset, shuffle: bool) -> Self { let mut remaining_indices = (0..dataset.len()).rev().collect::>(); if shuffle { - remaining_indices.shuffle(&mut thread_rng()); + remaining_indices.shuffle(&mut rng()); } Self { dataset, diff --git a/src/listings/ch07/bonus.rs b/src/listings/ch07/bonus.rs index 2a3d461..f18d300 100644 --- a/src/listings/ch07/bonus.rs +++ b/src/listings/ch07/bonus.rs @@ -7,7 +7,7 @@ use super::{ use crate::listings::ch05::generate_and_print_sample; use candle_core::{Device, IndexOp, ModuleT, Result, Tensor, D}; use candle_nn::Optimizer; -use rand::{rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; +use rand::{rng, rngs::StdRng, seq::SliceRandom, Rng, SeedableRng}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, NoneAsEmptyString}; use std::{path::Path, rc::Rc}; @@ -80,7 +80,7 @@ pub fn generate_chosen_and_rejected_response( prompt_formatter: &P, rng: &mut StdRng, ) -> anyhow::Result { - let u: f32 = rng.gen_range(0.0..1.0); + let u: f32 = rng.random_range(0.0..1.0); let politeness = if u < 0.5 { "polite" } else { "impolite" }; let prompt = format!( @@ -238,7 +238,7 @@ impl PreferenceDatasetIter { pub fn new(dataset: PreferenceDataset, shuffle: bool) -> Self { let mut remaining_indices = (0..dataset.len()).rev().collect::>(); if shuffle { - remaining_indices.shuffle(&mut thread_rng()); + remaining_indices.shuffle(&mut rng()); } Self { dataset, diff --git a/src/listings/ch07/mod.rs b/src/listings/ch07/mod.rs index 2d74a93..9b2749d 100644 --- a/src/listings/ch07/mod.rs +++ b/src/listings/ch07/mod.rs @@ -9,8 +9,8 @@ use bytes::Bytes; use candle_core::{Device, Result, Tensor}; use candle_nn::ModuleT; use hf_hub::api::sync::Api; +use rand::{rng, seq::SliceRandom}; use rand::{rngs::StdRng, SeedableRng}; -use rand::{seq::SliceRandom, thread_rng}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, NoneAsEmptyString}; use std::{ @@ -269,7 +269,7 @@ impl InstructionDatasetIter { pub fn new(dataset: InstructionDataset, shuffle: bool) -> Self { let mut remaining_indices = (0..dataset.len()).rev().collect::>(); if shuffle { - remaining_indices.shuffle(&mut thread_rng()); + remaining_indices.shuffle(&mut rng()); } Self { dataset,