def func(): # Two loops, one with stop grad on without for i in range(n): ti.stop_grad(x) loss[None] += x[i]**2 for i in range(n): loss[None] += x[i]**2
def func(): # Two loops, one with stop grad on without for i in range(n): ti.stop_grad(x) ti.atomic_add(loss, x[i]**2) for i in range(n): ti.atomic_add(loss, x[i]**2)
def func(): for i in range(n): ti.stop_grad(x) loss[None] += x[i]**2