The test code snippet shown as follows (Pytorch v0.3.1):
import torch
import torch.nn as nn
from torch.autograd import Variable
m = nn.Conv2d(1,1,kernel_size=3, stride=1, padding=1, bias=False)
m.weight.data.fill_(1)
a = torch.ones(1,1,5,5)
input_var = Variable(a, requires_grad=True)
output = m(input_var)
m.zero_grad()
input_var.data.fill_(0)
output.sum().backward()
print(m.weight.grad.data, input_var.grad.data)

The output:
(0 ,0 ,.,.) = 
  16  20  16
  20  25  20
  16  20  16
[torch.FloatTensor of size 1x1x3x3]
 
(0 ,0 ,.,.) = 
  4  6  6  6  4
  6  9  9  9  6
  6  9  9  9  6
  6  9  9  9  6
  4  6  6  6  4
[torch.FloatTensor of size 1x1x5x5]

The magic thing is that the in-place operation input_var.data.fill_(0) doesn’t affect the gradient of convolutional weights. Then what data is in use when backward?
Based on my understanding, computing the gradient of conv weights relies on the input variable. And the in-place operation on leaf Variable is not permitted (input_var.zero_()). It drives me to think the mechanism of autograd. Could anyone explain it? Thanks a lot.
Update: the input data change with cuda would affect the gradients.