We are not getting gradients after custom loss creation

We are playing with MNIST and we created an algorithm that uses splines to do inference.
The problem is that whenever we want to get the gradients of the “weights” of the loss function we obtain None values. The “weights” are initialized with require_grad=True .
Here’s a piece of code:
def training():
global alpha, trs

       for i in range(pos * bs, (pos + 1) * bs):
             ...
        
             pred = torch.tensor([torch.tensor([torch.dot(alpha[q], v[q]) for q in range(0, 1)])])
        
             pred.sum().backward()

             print(alpha.grad)

Here alpha.grad is None. The weights are the alpha’s variables and matXtr[i][j] is the input matrix X.
Again, we don’t understand why gradients are None.

Creating a new tensor will detach it from the computation graph, so use differentiable operations such as torch.stack or torch.cat.