(self)
| 486 | _run_testing(x_0, s_0, b_0, rm_0, rv_0, m_0=1.0) |
| 487 | |
| 488 | def test_batchnorm_backward_dnnl(self): |
| 489 | dev = cpu_dev |
| 490 | N = 1 |
| 491 | C = 3 |
| 492 | H = 2 |
| 493 | W = 2 |
| 494 | |
| 495 | data_shape = [N, C, H, W] |
| 496 | param_shape = [1, C, 1, 1] |
| 497 | data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] |
| 498 | |
| 499 | x_0 = np.array(data, dtype=np.float32).reshape(data_shape) |
| 500 | y_0 = np.array(data, dtype=np.float32).reshape(data_shape) |
| 501 | dy_0 = np.array(data, dtype=np.float32).reshape(data_shape) |
| 502 | scale_0 = np.array([1] * C, dtype=np.float32).reshape(param_shape) |
| 503 | bias_0 = np.array([0] * C, dtype=np.float32).reshape(param_shape) |
| 504 | |
| 505 | mean_0 = x_0.mean(axis=(0, 2, 3), keepdims=True) |
| 506 | var_0 = x_0.var(axis=(0, 2, 3), keepdims=True) |
| 507 | |
| 508 | hndl = singa_api.BatchNormHandle( |
| 509 | 0.1, |
| 510 | tensor.Tensor(device=dev, data=x_0).data) |
| 511 | (dx_2_c, _, _) = singa_api.CpuBatchNormBackwardx( |
| 512 | hndl, |
| 513 | tensor.Tensor(device=dev, data=y_0).data, |
| 514 | tensor.Tensor(device=dev, data=dy_0).data, |
| 515 | tensor.Tensor(device=dev, data=x_0).data, |
| 516 | tensor.Tensor(device=dev, data=scale_0).data, |
| 517 | tensor.Tensor(device=dev, data=bias_0).data, |
| 518 | tensor.Tensor(device=dev, data=mean_0).data, |
| 519 | tensor.Tensor(device=dev, data=var_0).data, |
| 520 | ) |
| 521 | |
| 522 | dx_truth = np.array([[[[-1.0769e-05, -3.5985e-06], |
| 523 | [3.5985e-06, 1.0769e-05]], |
| 524 | [[-1.0769e-05, -3.5985e-06], |
| 525 | [3.5985e-06, 1.0769e-05]], |
| 526 | [[-1.0769e-05, -3.5985e-06], |
| 527 | [3.5985e-06, 1.0769e-05]]]]) |
| 528 | np.testing.assert_array_almost_equal( |
| 529 | tensor.to_numpy(_cTensor_to_pyTensor(dx_2_c)), dx_truth) |
| 530 | |
| 531 | return |
| 532 | |
| 533 | def test_softmax_api_dnnl_backend(self): |
| 534 | dev = cpu_dev |
nothing calls this directly
no test coverage detected