Solved by ptrblck in post #2 
              
              
                Variables are deprecated since PyTorch 0.4 so you should use tensors now. 
You would have to pass the input tensor to an optimizer, so that it can update the input (similar like you pass the model.parameters() to an optimizer). 
The same work flow applies as usual, i.e. you would zero out the gradie…