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

Function worker

imperative/python/test/unit/core/test_autodiff.py:56–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55 @dist.launcher
56 def worker():
57 rank = dist.get_rank()
58 if rank == 0:
59 with Grad() as grad:
60 x = as_tensor(x_np)
61 grad.wrt(x, callback=save_to(x))
62 # need a placeholder to trace operator
63 remote_send(x, 1)
64 recv_x = remote_recv(1)
65 y = recv_x * recv_x
66 grad([y], [as_tensor(np.ones_like(x_np))])
67 np.testing.assert_almost_equal(x.grad.numpy(), x.numpy() * 2)
68 elif rank == 1:
69 with Grad() as grad:
70 recv_x = remote_recv(0)
71 remote_send(recv_x, 0)
72 grad([], [])
73
74 worker()
75

Callers 1

test_dist_gradFunction · 0.70

Calls 9

GradClass · 0.90
remote_sendFunction · 0.90
remote_recvFunction · 0.90
save_toFunction · 0.85
gradFunction · 0.85
get_rankMethod · 0.80
wrtMethod · 0.80
as_tensorFunction · 0.70
numpyMethod · 0.45

Tested by

no test coverage detected