Thank you so much for your reply! I change beta and cutoff to self.beta and self.cutoff, but I still got “None” for model.eta.grad. I think the reason is in the forward process, I use a function for X:
output[i,:] = RigidityExp.apply(sparse2tensor(X[i,:].reshape(1,-1)).double(), self.eta, self.beta, self.cutoff)

and the sparse2tensor function is:
def sparse2tensor(X):
    '''
    Input: X has shape(1, D)
           For Example, input X should be X_test_Distance[0,:].reshape(1,-1)
    '''
    D_in = X.shape[1]
    sparse =  stack_coo_matrix(X)
    matrix = sparse.toarray()
    D_total = matrix.shape[1]
    matrix = matrix.reshape(int(D_in), -1, int(D_total/D_in))
    tensor = torch.tensor(matrix, device=device, dtype=dtype)
    return tensor

Do you think this is the reason I cannot get the correct answer? Or do you have other idea?