(
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",
)
| 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 | ) |
no test coverage detected