# Checkpointing in each step

**URL:** <https://discuss.huggingface.co/t/checkpointing-in-each-step/3293>\
**Category:** 🤗Transformers\
**Created:** [January 19, 2021, 6:27pm UTC](https://discuss.huggingface.co/t/checkpointing-in-each-step/3293 "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](https://discuss.huggingface.co/u/julia)\
**Post date:** [January 19, 2021, 6:27pm UTC](https://discuss.huggingface.co/t/checkpointing-in-each-step/3293/1 "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](https://discuss.huggingface.co/u/valhalla)\
**Post date:** [January 20, 2021, 7:29am UTC](https://discuss.huggingface.co/t/checkpointing-in-each-step/3293/2 "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
