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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed — dependencies
- Bumped `rand` 0.9 → 0.10.2 and `rand_distr` 0.5 → 0.6.0. `candle-core` still
pulls `rand` 0.9 / `rand_distr` 0.5 for itself; the crate now depends on both
major lines.
- Migrated call sites for rand 0.10: `Rng` → `RngExt`, `StdRng::from_os_rng()` →
`rand::make_rng::<StdRng>()` (typed), and `&mut impl Rng` bounds on sampling /
training helpers to `RngExt`.

### Fixed — checkpointing
- **Resume was implicit and could silently do nothing.** `train()` loaded any checkpoint it
found with no flag and no way to opt out, restoring the step counter with it — so
Expand Down
101 changes: 83 additions & 18 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ureq = { version = "3", features = ["json"] }
gemm = { version = "0.19", features = ["f16"] }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
rand = "0.9"
rand_distr = "0.5"
rand = "0.10"
rand_distr = "0.6"
bytemuck = "1.25.2"
half = "2.7"
clap = { version = "4.6.4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/generation/codegen_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl CodeGenGenerator {
// same value at every step.
let mut rng = match self.seed {
Some(seed) => StdRng::seed_from_u64(seed),
None => StdRng::from_os_rng(),
None => rand::make_rng::<StdRng>(),
};

let mut cache: Option<Vec<KVCache>> = None;
Expand Down
5 changes: 2 additions & 3 deletions src/generation/glm_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::generation::sampling::sample;
use crate::glm::attention_mask::build_glm_mask;
use crate::glm::model::GLMModel;
use rand::rngs::StdRng;
use rand::SeedableRng;

pub struct GLMGenerator {
model: GLMModel,
Expand Down Expand Up @@ -48,7 +47,7 @@ impl GLMGenerator {
/// No blanks — generates new tokens after the prompt.
pub fn generate(&self, prompt_token_ids: &[u32]) -> Result<Vec<u32>> {
let device = self.model.embedding.weight.device();
let mut rng = StdRng::from_os_rng();
let mut rng: StdRng = rand::make_rng();
let mut generated = prompt_token_ids.to_vec();

for _step in 0..self.max_new_tokens {
Expand Down Expand Up @@ -89,7 +88,7 @@ impl GLMGenerator {
/// - earlier positions within the same blank (causal within-span)
pub fn fill_blanks(&self, context: &[u32], blank_lens: &[usize]) -> Result<Vec<u32>> {
let device = self.model.embedding.weight.device();
let mut rng = StdRng::from_os_rng();
let mut rng: StdRng = rand::make_rng();
let total_blank_tokens: usize = blank_lens.iter().sum();

let mut all_tokens = context.to_vec();
Expand Down
4 changes: 2 additions & 2 deletions src/generation/sampling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use candle_core::{DType, Result, Tensor};
use rand::Rng;
use rand::RngExt;

/// Sample one token from `logits`.
///
Expand All @@ -12,7 +12,7 @@ pub fn sample(
top_p: f64,
repetition_penalty: f64,
seen_tokens: &[u32],
rng: &mut impl Rng,
rng: &mut impl RngExt,
) -> Result<u32> {
let logits = if logits.dtype() != DType::F32 {
logits.to_dtype(DType::F32)?
Expand Down
2 changes: 1 addition & 1 deletion src/training/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::tokenizer::CodeGenTokenizer;
use candle_core::Result;
use rand::rngs::StdRng;
use rand::seq::SliceRandom;
use rand::Rng;
use rand::RngExt;
use rand::SeedableRng;
use std::io::Read;
use std::path::Path;
Expand Down
4 changes: 2 additions & 2 deletions src/training/train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use candle_core::{DType, Device, Result, Tensor, Var};
use candle_nn::{AdamW, Optimizer, ParamsAdamW};
use half;
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use rand::{RngExt, SeedableRng};
use safetensors::tensor::TensorView;
use safetensors::SafeTensors;

Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct GLMTrainer {
/// Corrupt a sequence for masked denoising: some positions are replaced by the
/// mask token or a random token, and their originals become the labels.
/// Positions left alone get `-1`, which [`cross_entropy_loss`] ignores.
fn corrupt(config: &GLMConfig, tokens: &[u32], rng: &mut impl Rng) -> (Vec<u32>, Vec<i64>) {
fn corrupt(config: &GLMConfig, tokens: &[u32], rng: &mut impl RngExt) -> (Vec<u32>, Vec<i64>) {
let mask_token_id = config.vocab_size as u32 - 1;
let mut inputs = tokens.to_vec();
let mut labels = vec![-1i64; tokens.len()];
Expand Down