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
97 changes: 74 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions src/exercises/ch07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -752,7 +752,7 @@ pub mod addons {
pub fn new(dataset: InstructionDataset, shuffle: bool) -> Self {
let mut remaining_indices = (0..dataset.len()).rev().collect::<Vec<_>>();
if shuffle {
remaining_indices.shuffle(&mut thread_rng());
remaining_indices.shuffle(&mut rng());
}
Self {
dataset,
Expand Down
4 changes: 2 additions & 2 deletions src/listings/ch02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -285,7 +285,7 @@ impl GPTDatasetIter {
pub fn new(dataset: GPTDatasetV1, shuffle: bool) -> Self {
let mut remaining_indices = (0..dataset.len()).rev().collect::<Vec<_>>();
if shuffle {
remaining_indices.shuffle(&mut thread_rng());
remaining_indices.shuffle(&mut rng());
}
Self {
dataset,
Expand Down
2 changes: 1 addition & 1 deletion src/listings/ch05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions src/listings/ch06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -466,7 +466,7 @@ impl SpamDatasetIter {
pub fn new(dataset: SpamDataset, shuffle: bool) -> Self {
let mut remaining_indices = (0..dataset.len()).rev().collect::<Vec<_>>();
if shuffle {
remaining_indices.shuffle(&mut thread_rng());
remaining_indices.shuffle(&mut rng());
}
Self {
dataset,
Expand Down
6 changes: 3 additions & 3 deletions src/listings/ch07/bonus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -80,7 +80,7 @@ pub fn generate_chosen_and_rejected_response<P: PromptFormatter>(
prompt_formatter: &P,
rng: &mut StdRng,
) -> anyhow::Result<PreferenceExample> {
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!(
Expand Down Expand Up @@ -238,7 +238,7 @@ impl PreferenceDatasetIter {
pub fn new(dataset: PreferenceDataset, shuffle: bool) -> Self {
let mut remaining_indices = (0..dataset.len()).rev().collect::<Vec<_>>();
if shuffle {
remaining_indices.shuffle(&mut thread_rng());
remaining_indices.shuffle(&mut rng());
}
Self {
dataset,
Expand Down
4 changes: 2 additions & 2 deletions src/listings/ch07/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -269,7 +269,7 @@ impl InstructionDatasetIter {
pub fn new(dataset: InstructionDataset, shuffle: bool) -> Self {
let mut remaining_indices = (0..dataset.len()).rev().collect::<Vec<_>>();
if shuffle {
remaining_indices.shuffle(&mut thread_rng());
remaining_indices.shuffle(&mut rng());
}
Self {
dataset,
Expand Down