{"record":{"id":"4e9bdaa49e64534f","repo":"tracel-ai/burn","slug":"step-should-be-called-no-more-than-i32-max","errorCode":null,"errorMessage":"`.step()` should be called no more than `i32::MAX + 1` times","messagePattern":"`\\.step\\(\\)` should be called no more than `i32::MAX \\+ 1` times","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-optim/src/lr_scheduler/step.rs","lineNumber":92,"sourceCode":"}\n\n/// Step learning rate scheduler.\n#[derive(Clone, Debug)]\npub struct StepLrScheduler {\n    init_lr: LearningRate,\n    step_size: usize,\n    gamma: f64,\n    // The index of the current iteration.\n    // `i32` is used for avoiding truncating the exponent when taking powers of `gamma`.\n    iter_idx: i32,\n}\n\nimpl LrScheduler for StepLrScheduler {\n    fn step(&mut self) -> LearningRate {\n        self.iter_idx = self\n            .iter_idx\n            .checked_add(1)\n            .expect(\"`.step()` should be called no more than `i32::MAX + 1` times\");\n        // Type casting below causes no truncation, as all the values fall within the ranges.\n        self.init_lr\n            * self\n                .gamma\n                .powi((self.iter_idx as usize / self.step_size) as i32)\n    }\n\n    fn to_record(&self) -> LrSchedulerRecord {\n        LrSchedulerRecord::from_state(&StepLrSchedulerState {\n            iter_idx: self.iter_idx,\n        })\n    }\n\n    fn load_record(&mut self, record: LrSchedulerRecord) {\n        if let Some(state) = record.into_state::<StepLrSchedulerState>() {\n            self.iter_idx = state.iter_idx;\n        }\n    }","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-optim/src/lr_scheduler/step.rs#L74-L110","documentation":"Overflow guard in `StepLrScheduler::step`: the iteration index is stored as `i32` (to avoid exponent truncation when applying `gamma^iter_idx`); calling step past `i32::MAX + 1` times would overflow, so the scheduler panics instead.","triggerScenarios":"Thrown at crates/burn-optim/src/lr_scheduler/step.rs:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Practically unreachable (over 2 billion steps); ignore unless running extreme step counts","Reset the scheduler from its record if you must continue beyond the limit","Change `iter_idx` to i64 in step.rs if the workload genuinely needs it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}