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

Function worker

imperative/python/test/integration/test_dp_correctness.py:150–179  ·  view source on GitHub ↗
(max_err)

Source from the content-addressed store, hash-verified

148
149 @dist.launcher
150 def worker(max_err):
151 net = MnistNet(has_bn=True)
152 net.load_state_dict(checkpoint["net_init"])
153 lr = checkpoint["sgd_lr"]
154 opt = SGD(net.parameters(), lr=lr)
155
156 gm = ad.GradManager().attach(
157 net.parameters(), callbacks=[dist.make_allreduce_cb("MEAN", dist.WORLD)]
158 )
159
160 # use same data and label for all gpu's
161 # such that the result does not depend on number of gpu
162 data_train = Tensor(data)
163 label_train = Tensor(label)
164
165 loss = train(data_train, label_train, net, opt, gm)
166
167 np.testing.assert_allclose(loss.numpy(), checkpoint["loss"], atol=max_err)
168
169 if dist.get_rank():
170 return
171 for param, param_ref in zip(
172 net.state_dict().items(), checkpoint["net_updated"].items()
173 ):
174 assert param[0] == param_ref[0]
175 if "bn" in param[0]:
176 ref = param_ref[1].reshape(param[1].shape)
177 np.testing.assert_allclose(param[1], ref, atol=max_err)
178 else:
179 np.testing.assert_allclose(param[1], param_ref[1], atol=max_err)
180
181 worker(max_err)
182

Callers 1

run_testFunction · 0.70

Calls 13

SGDClass · 0.90
TensorClass · 0.90
MnistNetClass · 0.85
parametersMethod · 0.80
get_rankMethod · 0.80
itemsMethod · 0.80
trainFunction · 0.70
load_state_dictMethod · 0.45
attachMethod · 0.45
GradManagerMethod · 0.45
numpyMethod · 0.45
state_dictMethod · 0.45

Tested by

no test coverage detected