Maybe move the requieres_grad to the Parameter(), it‘s currently in the inner bracket of torch.rand() and check the is_leaf() before and after. Maybe this note in the docs helps (and the docs to .is_leaf):
https://pytorch.org/docs/stable/autograd.html#torch.Tensor.requires_grad 28