예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)