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

Function run_syncbn

imperative/python/test/integration/test_bn.py:153–178  ·  view source on GitHub ↗
(trace_mode)

Source from the content-addressed store, hash-verified

151
152
153def run_syncbn(trace_mode):
154 x = F.ones([2, 16, 4, 4], dtype="float32")
155
156 net = Sequential(
157 Conv2d(16, 16, 1), SyncBatchNorm(16), Conv2d(16, 16, 1), SyncBatchNorm(16),
158 )
159
160 gm = ad.GradManager().attach(
161 net.parameters(), callbacks=dist.make_allreduce_cb("MEAN")
162 )
163 opt = optimizer.SGD(net.parameters(), 1e-3)
164
165 def train_func(x):
166 with gm:
167 y = net(x)
168 loss = y.mean()
169 gm.backward(loss)
170 opt.step().clear_grad()
171 return loss
172
173 if trace_mode is not None:
174 train_func = trace(train_func, symbolic=trace_mode)
175
176 for _ in range(3):
177 loss = train_func(x)
178 loss.numpy()
179
180
181@pytest.mark.require_ngpu(2)

Callers 1

workerFunction · 0.85

Calls 11

SequentialClass · 0.90
Conv2dClass · 0.90
SyncBatchNormClass · 0.90
traceClass · 0.90
onesMethod · 0.80
parametersMethod · 0.80
train_funcFunction · 0.70
attachMethod · 0.45
GradManagerMethod · 0.45
SGDMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected