I have got that! The problem has fixed. Just add an operation will be enough.
import torch
from torch.autograd import Variable
import numpy as np
import torch.nn as nn


x = Variable(torch.Tensor(3, 5).normal_(), requires_grad=True)
y= Variable(torch.Tensor(3, 5).normal_(), requires_grad=True)

a = x + 0
b = y + 0

for i in range(b.size()[0]):
    for j in range(a.size()[0]):
        b[i] = b[i] + a[j]
        
b.backward(torch.Tensor(3, 5).normal_())

What I want to know is whether pytorch’s autograd supports doing operation on part of the variables. That’s what I need in my future project. Actually, it does support.
Thank you very much for your help and patience.
Best,
Yikang