()
| 37 | |
| 38 | @dist.launcher(n_gpus=2) |
| 39 | def worker(): |
| 40 | net = Simple(param_shape) |
| 41 | opt = SGD(net.parameters(), lr=0.1) |
| 42 | |
| 43 | allreduce_cb = dist.make_allreduce_cb("MEAN", dist.WORLD) |
| 44 | if threshold is not None: |
| 45 | allreduce_cb._param_pack_thd = threshold |
| 46 | gm = ad.GradManager().attach(net.parameters(), callbacks=[allreduce_cb]) |
| 47 | |
| 48 | def run(): |
| 49 | opt.clear_grad() |
| 50 | with gm: |
| 51 | x = tensor(data) |
| 52 | loss = net(x) |
| 53 | loss = loss.sum() |
| 54 | gm.backward(loss) |
| 55 | |
| 56 | for i in range(n_iters): |
| 57 | run() |
| 58 | |
| 59 | for p in net.params: |
| 60 | np.testing.assert_equal(p.grad.numpy(), np.ones_like(p.grad.numpy())) |
| 61 | |
| 62 | worker() |
no test coverage detected