(self)
| 11 | for a, b in zip(list1, list2): |
| 12 | self.assertAlmostEqual(a, b, delta=tol) |
| 13 | def test_adam_w(self): |
| 14 | w = torch.tensor([0.1, -0.2, -0.1], requires_grad=True) |
| 15 | target = torch.tensor([0.4, 0.2, -0.5]) |
| 16 | criterion = torch.nn.MSELoss() |
| 17 | # No warmup, constant schedule, no gradient clipping |
| 18 | optimizer = optim.AdamW(params=[w], lr=2e-1, weight_decay=0.0) |
| 19 | for _ in range(100): |
| 20 | loss = criterion(w, target) |
| 21 | loss.backward() |
| 22 | optimizer.step() |
| 23 | w.grad.detach_() # No zero_grad() function on simple tensors. we do it ourselves. |
| 24 | w.grad.zero_() |
| 25 | self.assertListAlmostEqual(w.tolist(), [0.4, 0.2, -0.5], tol=1e-2) |
nothing calls this directly
no test coverage detected