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

Function test_concat

imperative/python/test/unit/quantization/test_module.py:285–320  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

283
284
285def test_concat():
286 normal_net = Float.Concat()
287 normal_net.eval()
288
289 qat_net = QAT.Concat()
290 qat_net.eval()
291 disable_observer(qat_net)
292
293 propagate_qconfig(qat_net, min_max_fakequant_qconfig)
294 init_qat_net(qat_net)
295
296 inps = []
297 inps_int8 = []
298 for i in range(3):
299 inp_scale = gen_inp_scale()
300 inps.append(mge.tensor(np.random.normal(size=(3, 3)).astype("float32")))
301 inps[i] = fake_quant_act(inps[i], inp_scale)
302 inps[i].qparams.update(create_qparams(QuantMode.SYMMERTIC, "qint8", inp_scale))
303 inps_int8.append(quant(inps[i], inp_scale))
304
305 qat_from_float = QAT.Concat.from_float_module(normal_net)
306 qat_from_float.eval()
307 disable_fake_quant(qat_from_float)
308 disable_observer(qat_from_float)
309
310 q_net = Q.Concat.from_qat_module(qat_net)
311 q_net.eval()
312
313 normal = normal_net(inps)
314 qat_without_fakequant = qat_from_float(inps)
315 fake_quant_normal = fake_quant_act(normal_net(inps), act_scale)
316 qat = qat_net(inps)
317 q = q_net(inps_int8).numpy() * act_scale
318 np.testing.assert_allclose(qat_without_fakequant, normal)
319 np.testing.assert_allclose(qat, fake_quant_normal.numpy())
320 np.testing.assert_allclose(q, fake_quant_normal.numpy())

Callers

nothing calls this directly

Calls 15

disable_observerFunction · 0.90
propagate_qconfigFunction · 0.90
create_qparamsFunction · 0.90
disable_fake_quantFunction · 0.90
gen_inp_scaleFunction · 0.85
ConcatMethod · 0.80
tensorMethod · 0.80
normalMethod · 0.80
init_qat_netFunction · 0.70
quantFunction · 0.70
evalMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected