MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / worker

Function worker

imperative/python/test/integration/test_param_pack.py:39–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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()

Callers 1

test_param_packFunction · 0.70

Calls 8

SGDClass · 0.90
parametersMethod · 0.80
assert_equalMethod · 0.80
SimpleClass · 0.70
runFunction · 0.70
attachMethod · 0.45
GradManagerMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected