Solved by ptrblck in post #4 
              
              
                The error points to a detached computation graph, which is created by recreating the rot_matrix tensor. 
If you want to use the theta values for the rot_matrix, you should use torch.cat or torch.stack and avoid creating a new tensor via torch.tensor.