AttributeError: module 'torch.utils' has no attribute 'checkpoint'

I have it like this

import torch
bla bla bla
mels_self = torch.utils.checkpoint.checkpoint(self.decoder_self_run, mels, encoder_outputs, batch['text_lengths'], batch['mel_lengths'])


from torch.utils.checkpoint import checkpoint

same code works fine, why so?

1 Like

Which PyTorch version are you using (you can check it via print(torch.__version__)).
torch.utils.checkpoint was introduced some time ago, so I’ wondering if you are working with a really old PyTorch build. If so, could you update to the latest stable release (1.7.0) and retry your code?

Pytorch 1.6
So it works, but only if I import checkpoint separately.
I tried to update the version to 1.7, but another library raises an error.

1 Like

The problem still exists on 1.7

1 Like

I still cannot reproduce it in 1.7.0, so could you post an executable code snippet, which raises the issue in this PyTorch version, please?

Here is code

Thanks for the notebook.
It works fine when I uncomment

from torch.utils.checkpoint import checkpoint

Yes, but why I need this import?
Shouldnt it be covered by whole pytorch import?

I’m not completely sure how the import mechanism works in different Python versions and my understanding is that newer Python versions are more “flexible”. You could thus try it with e.g. Python3.8 and if it’s still not working would need to import the method directly (unsure if it’s a PyTorch limitation or the desired workflow in Python).