Saving model per some step when using Trainer

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

  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


This is explained in the documentation.

You can change the argument “save_steps”, which defaults to 500.

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

1 Like