(idx, data, calc)
| 15 | scaler = GradScaler() |
| 16 | |
| 17 | def f(idx, data, calc): |
| 18 | x = mge.tensor(data, no_cache=True) |
| 19 | y = mge.tensor(data, no_cache=True) |
| 20 | |
| 21 | if is_trace: |
| 22 | calc = trace(calc) |
| 23 | |
| 24 | gm.attach([x, y]) |
| 25 | with gm: |
| 26 | loss = calc(x, y) |
| 27 | scaler.backward(gm, loss, unscale_grad=False) |
| 28 | np.testing.assert_equal(x.grad.numpy(), 2 * scaler.scale_factor) |
| 29 | scaler.unscale(filter(lambda t: t.grad is not None, gm.attached_tensors())) |
| 30 | # scaler.unscale(gm.attached_tensors()) |
| 31 | np.testing.assert_equal(x.grad.numpy(), 2) |
| 32 | |
| 33 | def double_variables(x, y): |
| 34 | z = x + 2 * y |
no test coverage detected