whichever tensor is computationally involved is considered for autograd. For example,  weighted mask may be directly multipled with the 2D tensor, in which case,  the autograd will compute gradient for mask as well (if mask’s requires_grad = True).  In the other case (in your example) ,  tensor.shape is not used in any computation, but just as a constant to expand the dimensions of a particular tensor. Hence,  there is no gradient calculation related to tensor.shape (shape is not an operation, but just an attribute to hold size of the tensor).