{"record":{"id":"b64b5c66c54df48b","repo":"tracel-ai/burn","slug":"can-load-model-checkpoint","errorCode":null,"errorMessage":"Can load model checkpoint.","messagePattern":"Can load model checkpoint\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-train/src/learner/base.rs","lineNumber":200,"sourceCode":"                    self.lr_scheduler\n                        .save(epoch, learner.lr_scheduler.to_record())\n                        .expect(\"Can save learning rate scheduler checkpoint.\");\n                }\n            }\n        }\n    }\n\n    /// Load a training checkpoint.\n    ///\n    /// No device is taken: checkpoints are device-free burnpack records (file-backed bytes). On\n    /// load, the model keeps the device of the learner's existing parameters, and the optimizer\n    /// state is migrated to each parameter's device on the next step. The training device is fixed\n    /// earlier, when the learner's model is created/forked.\n    pub fn load_checkpoint(&self, mut learner: Learner<M>, epoch: usize) -> Learner<M> {\n        let record = self\n            .model\n            .restore(epoch)\n            .expect(\"Can load model checkpoint.\");\n        learner.load_model(record);\n\n        let record = self\n            .optim\n            .restore(epoch)\n            .expect(\"Can load optimizer checkpoint.\");\n        learner.load_optim(record);\n\n        let record = self\n            .lr_scheduler\n            .restore(epoch)\n            .expect(\"Can load learning rate scheduler checkpoint.\");\n        learner.load_scheduler(record);\n\n        learner\n    }\n}\n","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-train/src/learner/base.rs#L182-L218","documentation":"`Learner::load_checkpoint` restores the model record for a given epoch via the model checkpointer's `restore(epoch)` and unwraps it with expect(). If no model checkpoint exists for that epoch or the file cannot be read/deserialized, the process panics with this message.","triggerScenarios":"Calling load_checkpoint(learner, epoch) when the model checkpoint file for `epoch` was never saved (wrong epoch number, training crashed before that epoch) or cannot be deserialized (architecture changed, different burn version/recorder format, corrupted file).","commonSituations":"Resuming from an epoch that wasn't checkpointed (e.g. keepN deleted it); switching model structure or tensor backend between save and load; loading checkpoints written by an older burn version; path mismatch between the saving and resuming jobs.","solutions":["Confirm a checkpoint for that exact epoch exists in the directory (list files) and use the highest saved epoch otherwise.","Check the checkpoint wasn't pruned by keepN/keepOld settings; keep the needed epoch or use an existing one.","Ensure the model architecture and burn crate version match the ones used at save time; retrain or regenerate the checkpoint if they changed.","Use the same recorder settings (path prefix, format) as the saving run.","If the file is corrupt, restore from backup or fall back to another epoch."],"exampleFix":"// before\nlearner::load_checkpoint(learner, 20); // only epochs 15..=19 were kept\n// after\nlet epoch = latest_saved_epoch(&checkpoint_dir); // scan dir for saved epochs\nlearner::load_checkpoint(learner, epoch);","handlingStrategy":"validation","validationCode":"fn saved_epochs(dir: &str, prefix: &str) -> Vec<usize> {\n    std::fs::read_dir(dir).unwrap()\n        .filter_map(|e| e.ok().file_name().into_string().ok())\n        .filter_map(|n| n.strip_prefix(prefix)?.split('-').next()?.parse().ok())\n        .collect()\n}\nlet epochs = saved_epochs(&checkpoint_dir, \"model\");\nassert!(epochs.contains(&epoch), \"epoch {epoch} not checkpointed; available: {epochs:?}\");","typeGuard":"fn epoch_checkpoints_exist(dir: &str, epoch: usize) -> bool {\n    [\"model\", \"optim\", \"scheduler\"].iter().all(|p| Path::new(dir).join(format!(\"{p}-{epoch}\")).exists())\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| learner::load_checkpoint(learner, epoch)));\nmatch result {\n    Ok(l) => l,\n    Err(_) => { eprintln!(\"resume failed for epoch {epoch}; falling back to latest\"); learner }\n}","preventionTips":["Resume from the highest epoch actually present on disk, not a hard-coded number.","Keep model/optimizer/scheduler checkpointers configured identically to the saving run.","Pin the burn crate version between the saving and resuming jobs; checkpoints aren't guaranteed portable across versions.","Set keepN/keepOld so the epochs you plan to resume from are retained."],"tags":["rust","panic","checkpoint","deserialization","resume-training"],"backgroundTag":"checkpoint-not-found","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"}