我想问下autodiff中针对global data access的规则是写完以后不能读还是读完以后不能写,我看了官方文档认为应该是后者吧,那为何我的这段代码为何会报overwritten unexpectedly呢?
ratio = ti.field(dtype=real, shape=(n_points,), needs_grad=True)
@ti.kernel
def compute_ratio():
for i in range(n_points):
ratio[i] = 0.5 * ti.tanh(5 * x[i]) + 0.5
@ti.kernel
def compute_loss():
for i in range(n_points):
l[None] += (position[frames, i] - target_position[i]).norm() ** 2
l[None] += (velocity[frames, i] - target_velocity[i]).norm() ** 2
l[None] += ratio[i]
def loss(time_step):
compute_ratio()
compute_loss()
with ti.ad.Tape(l, validation=True, grad_check=[ratio]):
loss(time_step)