The propagation problem of the gradient encountered when tensor is partitioned and indexed

I want to run the following demo to verify my idea, but a bug appeared during the operation, and the prompt said"leaf variable has been moved into the graph interior".Because the loaded image occupies a lot, I need to use the intermediate variable recon to accept the data that has been calculated.I don’t know how to correct this error so that the program can run and the gradient can be passed correctly. I hope you can help me, thank you.

import torch
from torch.autograd import Variable

img = Variable(torch.rand(4, 4).float(), requires_grad=True)
recon = Variable(torch.zeros(4, 4).float(), requires_grad=True)
kernel = Variable(torch.rand(2, 2).float(), requires_grad=True)

for i in range(2):
	for j in range(2):
		recon[i*2:(i+1)*2, j*2:(j+1)*2] = kernel * (img[i*2:(i+1)*2, j*2:(j+1)*2])