()
| 21 | |
| 22 | |
| 23 | def test_detach(): |
| 24 | net = Simple() |
| 25 | |
| 26 | optim = optimizer.SGD(net.parameters(), lr=1.0) |
| 27 | optim.clear_grad() |
| 28 | gm = ad.GradManager().attach(net.parameters()) |
| 29 | |
| 30 | dshape = (10, 10) |
| 31 | data = tensor(np.ones(dshape).astype(np.float32)) |
| 32 | with gm: |
| 33 | loss = net(data).sum() |
| 34 | gm.backward(loss) |
| 35 | optim.step() |
| 36 | np.testing.assert_equal(net.a.numpy(), np.array([1.0]).astype(np.float32)) |
| 37 | np.testing.assert_equal( |
| 38 | net.b.numpy(), np.array([1.0 - 10.0 * 10.0]).astype(np.float32) |
| 39 | ) |
nothing calls this directly
no test coverage detected