def tearDownClass(cls): """Restore random seeds""" np.random.set_state(cls._np_rand_state) random.setstate(cls._py_rand_state) _set_use_system_allocator(cls._use_system_allocator) # unittest will to trigger IPUCompiledProgram.__del__ automatically global ipu_compiler_ref ipu_compiler_ref is not None and ipu_compiler_ref.clean()
def setUpClass(cls): cls._np_rand_state = np.random.get_state() cls._py_rand_state = random.getstate() cls.SEED = SEED np.random.seed(cls.SEED) random.seed(cls.SEED) cls._use_system_allocator = _set_use_system_allocator(True)
import subprocess import traceback import functools import pickle from contextlib import closing import paddle.fluid as fluid import paddle.fluid.unique_name as nameGen from paddle.fluid import core from six import string_types import paddle from paddle.fluid.tests.unittests.op_test import OpTest, _set_use_system_allocator from paddle.fluid.tests.unittests.test_sync_batch_norm_op import create_or_get_tensor _set_use_system_allocator(False) paddle.enable_static() SEED = 10 class TestSyncBatchNormRunnerBase(object): def get_model(self, main, startup, place, layout, seed, sync_bn=False, only_forward=False): raise NotImplementedError(
# See the License for the specific language governing permissions and # limitations under the License. from __future__ import print_function import unittest import numpy as np import paddle.fluid.core as core from paddle.fluid.op import Operator import paddle.fluid as fluid from paddle.fluid.tests.unittests.op_test import OpTest, _set_use_system_allocator from paddle.fluid.framework import grad_var_name from paddle.fluid.tests.unittests.test_batch_norm_op import TestBatchNormOpInference, TestBatchNormOpTraining, _reference_training, _reference_grad from mkldnn_op_test import check_if_mkldnn_batchnorm_primitives_exist_in_bwd _set_use_system_allocator(True) class TestMKLDNNBatchNormOpTraining(TestBatchNormOpTraining): def init_kernel_type(self): self.use_mkldnn = True self.data_formats = ["NCHW"] def ref_forward_backward(self, x, y_grad, scale, bias, mean, variance, epsilon, momentum, shape, data_layout): if data_layout != "NCHW" and data_layout != "NHWC": raise ValueError("Unknown data order.") # run forward y, saved_mean, saved_variance = _reference_training(