MCPcopy Create free account
hub / github.com/InternScience/InternAgent / _save_checkpoint

Method _save_checkpoint

tasks/AutoClsSST/code/experiment.py:265–287  ·  view source on GitHub ↗
(
            self,
            target_dir: str,
            epoch: int,
            optimizer: AdamW,
            best_score: float,
            training_stats: Dict[str, List]
    )

Source from the content-addressed store, hash-verified

263 )
264
265 def _save_checkpoint(
266 self,
267 target_dir: str,
268 epoch: int,
269 optimizer: AdamW,
270 best_score: float,
271 training_stats: Dict[str, List]
272 ) -> None:
273 checkpoint = {
274 "epoch": epoch,
275 "model": self.model.state_dict(),
276 "optimizer": optimizer.state_dict(),
277 "best_score": best_score,
278 **training_stats
279 }
280 torch.save(
281 checkpoint,
282 os.path.join(target_dir, "best.pth.tar")
283 )
284 logger.info("Model saved successfully")
285
286 # 记录最佳模型信息到TensorBoard
287 self.writer.add_text('Best Model', f'Epoch: {epoch}, Accuracy: {best_score:.4f}', epoch)
288
289 def _load_checkpoint(
290 self,

Callers 1

train_and_evaluateMethod · 0.95

Calls 2

state_dictMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected