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

Function test_func

imperative/python/test/unit/quantization/test_op.py:257–337  ·  view source on GitHub ↗
(
        N,
        IC,
        IH,
        IW,
        OC,
        KH,
        KW,
        SH,
        SW,
        PH,
        PW,
        DH,
        DW,
        groups=1,
        has_bias=True,
        conv_mode: str = "cross_correlation",
        compute_mode: str = "default",
    )

Source from the content-addressed store, hash-verified

255 rng = np.random.RandomState(seed=2021)
256
257 def test_func(
258 N,
259 IC,
260 IH,
261 IW,
262 OC,
263 KH,
264 KW,
265 SH,
266 SW,
267 PH,
268 PW,
269 DH,
270 DW,
271 groups=1,
272 has_bias=True,
273 conv_mode: str = "cross_correlation",
274 compute_mode: str = "default",
275 ):
276 inp_scale = np.float32(rng.uniform(low=0.04, high=0.06))
277 weight_scale = np.float32(rng.uniform(low=0.04, high=0.06))
278 bias_scale = inp_scale * weight_scale
279 out_scale = np.float32(rng.uniform(low=0.04, high=0.06))
280
281 inp_dtype = dtype.qint8(inp_scale)
282 weight_dtype = dtype.qint8(weight_scale)
283 bias_dtype = dtype.qint32(bias_scale)
284 out_dtype = dtype.qint8(out_scale)
285
286 inp_fp32 = rng.uniform(low=-1, high=1, size=(N, IC, IH, IW)).astype(np.float32)
287 weight_fp32 = rng.uniform(low=-1, high=1, size=(IC, OC, KH, KW)).astype(
288 np.float32
289 )
290 bias_fp32 = rng.uniform(low=-1, high=1, size=(1, OC, 1, 1)).astype(np.float32)
291
292 inp_int8 = dtype.convert_to_qint8(inp_fp32, inp_dtype)
293 weight_int8 = dtype.convert_to_qint8(weight_fp32, weight_dtype)
294 bias_int32 = dtype.convert_to_qint32(bias_fp32, bias_dtype)
295
296 inp_int8 = mge.tensor(inp_int8, dtype=inp_dtype)
297 weight_int8 = mge.Parameter(weight_int8, dtype=weight_dtype)
298 bias_int32 = mge.Parameter(bias_int32, dtype=bias_dtype)
299
300 inp_fp32 = inp_int8.astype("float32")
301 weight_fp32 = weight_int8.astype("float32")
302 bias_fp32 = bias_int32.astype("float32")
303
304 expected = F.conv_transpose2d(
305 inp_fp32,
306 weight_fp32,
307 bias_fp32 if has_bias else None,
308 stride=(SH, SW),
309 padding=(PH, PW),
310 dilation=(DH, DW),
311 groups=groups,
312 conv_mode=conv_mode,
313 compute_mode=compute_mode,
314 )

Callers 1

test_conv_transpose2dFunction · 0.70

Calls 6

forwardMethod · 0.95
ConvTranspose2dClass · 0.90
uniformMethod · 0.80
tensorMethod · 0.80
astypeMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected