# Resume Training, but reset epochs

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fresume-training-but-reset-epochs%2F23208%3E%5C
**Category:** 🤗Transformers\
**Created:** [September 16, 2022, 7:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fresume-training-but-reset-epochs%2F23208 "2022-09-16T07:38:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![timbmg](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/timbmg/32/42495_2.png) [@timbmg](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftimbmg)%5C
**Post date:** [September 16, 2022, 7:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fresume-training-but-reset-epochs%2F23208%2F1 "2022-09-16T07:38:51Z")

</div>

I want to change the training dataset after each epoch. For this, I just have a loop, where I create a new Trainer object and after the first epoch call `Trainer.train` with `resume_from_checkpoint=True`. For each dataset, the training should be performed for a single epoch. However, in this loop, the training so not continued, because when resuming, the number of epochs the model has already been trained for is also re-loaded. How can i reset the number of epochs?

```python
for i, k in enumerate(sorted(train_datasets.keys())):
    train_dataset = train_datasets[k]
    trainer = Seq2SeqTrainer(
        model=model,
        args=training_args,
        train_datasets=train_dataset,
        eval_dataset=eval_dataset,
        tokenizer=tokenizer,
        data_collator=data_collator,
    )
    trainer.train(resume_from_checkpoint=i > 0)

```
