Save model each epoch

I want to save model for each epoch

but my training process is using model.fit();
not using for loop
the following is my code:
model.fit(inputs, targets, optimizer, ctc_loss, batch_size, epoch=epochs)
torch.save(model.state_dict(), os.path.join(model_dir, ‘savedmodel.pt’))

any suggestion to save model for each epoch

thanks in advance

Did you define the fit method manually or are you using a higher-level API?
In the former case, you could just copy-paste the saving code into the fit function. In the latter case, I would assume that the library might provide some “on epoch end” - callbacks, which could be used to save the model.