def test_copy_detached(self): x = State(k=torch.nn.Parameter(torch.rand(5, 3))) y = x.make_copy() y.k[:] = 0 print(x.k) print(y.k)
def test_copy_deep(self): x = State(k=np.asarray(["a", "b", "c"])) y = x.make_copy(deep=False) y.k[:] = "q" print(x.k) print(y.k)
def test_copy_non_detached(self): x = State(k=torch.nn.Parameter(torch.rand(5, 3))) y = x.make_copy(detach=False) l = y.k.sum() l.backward() print(x.k.grad)