# Checkpointing in each step

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcheckpointing-in-each-step%2F3293%3E%5C
**Category:** 🤗Transformers\
**Created:** [January 19, 2021, 6:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcheckpointing-in-each-step%2F3293 "2021-01-19T18:27:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julia](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@julia](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjulia)%5C
**Post date:** [January 19, 2021, 6:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcheckpointing-in-each-step%2F3293%2F1 "2021-01-19T18:27:00Z")

</div>

Hi  
I use finetune\_trainer.py, it saves the best model during checkpoints given an evaluation metric, so sometimes it calls the \_save\_checkpoint, but if the metric is not higher than the best saved one it would not save the cehckpoint in huggingface code, what I need is to write a callback, that save model+optimizer+scheduler to be called write after each time it calls the save\_checkpoint to keep a copy of last updated model in the folder. I am not sure how to access optimizer/model/scheduler in the callbacks, I appreciate your input on this. thanks

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvalhalla)%5C
**Post date:** [January 20, 2021, 7:29am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcheckpointing-in-each-step%2F3293%2F2 "2021-01-20T07:29:25Z")

</div>

you could use `save_stpes` arg to specify the number of update steps after which to save the checkpoint. If you use

```bash
--evaluation_strategy steps
--eval_steps 50
--save_steps 50

```

then it will eval and save checkpoint after every 50 steps
