()
| 283 | |
| 284 | |
| 285 | def 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()) |
nothing calls this directly
no test coverage detected