Search code examples
pytorchvolatile

volatile was removed and now has no effect. Use with torch.no_grad(): instead


I have got this error, can you help me please? This is my error in utils.py file

 content/gdrive/My Drive/DeepFakeDetection/utils.py:21: UserWarning:
 volatile was removed and now has no effect. Use with torch.no_grad():
 instead. return Variable(x, volatile=volatile)

And this is my code in utils.py file

 def to_var(x, volatile=False):
 
     if torch.cuda.is_available(): 
        x = x.cuda() 
     return Variable(x, volatile=volatile)

Thank you


Solution

  • I changed it to this:

    def to_var(x, volatile=False):
    >     
    >     with torch.no_grad():
    >         
    >         if torch.cuda.is_available():
    >             x = x.cuda()
    >     return x