# Saving model per some step when using Trainer

**URL:** <https://discuss.huggingface.co/t/saving-model-per-some-step-when-using-trainer/11553>\
**Category:** Intermediate\
**Created:** [November 10, 2021, 10:47am UTC](https://discuss.huggingface.co/t/saving-model-per-some-step-when-using-trainer/11553 "2021-11-10T10:47:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hieule246](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@hieule246](https://discuss.huggingface.co/u/hieule246)\
**Post date:** [November 10, 2021, 10:47am UTC](https://discuss.huggingface.co/t/saving-model-per-some-step-when-using-trainer/11553/1 "2021-11-10T10:47:35Z")

</div>

When using the `Trainer` and `TrainingArguments` from transformers, I notice that by default, the Trainer save a model every 500 steps. How can I change this value so that it save the model more/less frequent?  
here is a snipet that i use

```auto
  training_args = TrainingArguments(
        output_dir=output_directory, # output directory
        num_train_epochs=10, # total number of training epochs
        per_device_train_batch_size=16, # batch size per device during training
        per_device_eval_batch_size=64, # batch size for evaluation
        warmup_steps=500, # number of warmup steps for learning rate scheduler
        weight_decay=0.01, # strength of weight decay
        logging_dir=log_directory, # directory for storing logs
    )

    trainer = Trainer(
        model=model, # the instantiated 🤗 Transformers model to be trained
        args=training_args, # training arguments, defined above
        train_dataset=train_dataset, # training dataset
        eval_dataset=val_dataset # evaluation dataset
    )

    trainer.train()

```

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [November 10, 2021, 11:12am UTC](https://discuss.huggingface.co/t/saving-model-per-some-step-when-using-trainer/11553/2 "2021-11-10T11:12:14Z")

</div>

This is explained in the [documentation](https://huggingface.co/transformers/main_classes/trainer.html).

You can change the argument “save\_steps”, which defaults to 500.

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [November 10, 2021, 12:31pm UTC](https://discuss.huggingface.co/t/saving-model-per-some-step-when-using-trainer/11553/3 "2021-11-10T12:31:36Z")

</div>

You can also use a different `save_strategy` to never save, or save every epoch.

---

<div class="post-metadata">

**Author:** ![mayapati](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mayapati](https://discuss.huggingface.co/u/mayapati)\
**Post date:** [December 11, 2023, 8:59am UTC](https://discuss.huggingface.co/t/saving-model-per-some-step-when-using-trainer/11553/4 "2023-12-11T08:59:34Z")

</div>

How can I save each checkpoint at a different out\_dir, currently, my recent model is stored in same output dir as previous directory, I want to save every new model after steps to a different directory, can I specify out\_dir something like : '/model-{step-no. (or epoch no.)} ?
