RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

import pytorch3d.transforms
import torch
euler_angles = torch.nn.Parameter(torch.Tensor([0.1, 0.03,-0.2]))target = torch.eye(3)torch.autograd.set_detect_anomaly(True)
optimizer = torch.optim.Adam([euler_angles], lr=0.05)
optimizer.zero_grad()
z = torch.empty(4)
z[3] = 1.0
z[0] = euler_angles[0] * 1
z[1] = euler_angles[1]
z[2] = euler_angles[2] * z[3] # Error originates here
matrix = pytorch3d.transforms.euler_angles_to_matrix(z[:3], "XYZ")
loss = torch.sum((matrix - target)**2)
loss.backward()
optimizer.step()
z[2] = euler_angles[2] * z[3].clone()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store