I am saving the model to the disk every epoch. I am using python 2.7 so I’m doing it in the following way.
model_n_b = io.BytesIO()
torch.save(model.state_dict(), model_n_b)
with open(model_name, "wb") as f:
    f.write(model_n_b.getvalue())
    model_n_b.close()

which I’m not sure is correct, however, without saving (and without later deleting and loading the model object) the leak still occurs.
If I run only data loading, like
for batch in loader:
    pass
    # loss = model.loss()
    ...

there’s no leak