def check(): print("check: fluid.core.globals()['FLAGS_use_mkldnn']=", fluid.core.globals()["FLAGS_use_mkldnn"]) print("check: fluid.get_flags('FLAGS_use_mkldnn')=", fluid.get_flags(['FLAGS_use_mkldnn'])) print("check: DNNL_VERBOSE=", os.environ['DNNL_VERBOSE']) print("check: FLAGS_tracer_mkldnn_ops_on=", fluid.core.globals()['FLAGS_tracer_mkldnn_ops_on']) print("check: FLAGS_tracer_mkldnn_ops_off=", fluid.core.globals()['FLAGS_tracer_mkldnn_ops_off']) a_np = np.random.uniform(-2, 2, (10, 20, 30)).astype(np.float32) b_np = np.random.uniform(-5, 5, (10, 20, 30)).astype(np.float32) helper = LayerHelper(fluid.unique_name.generate(str("test")), act="relu") func = helper.append_activation with fluid.dygraph.guard(fluid.core.CPUPlace()): a = fluid.dygraph.to_variable(a_np) b = fluid.dygraph.to_variable(b_np) y = fluid.layers.elementwise_add(x=a, y=b) y = fluid.layers.matmul(x=y, y=b, transpose_y=True) res1 = func(y) np_res = np.add(a_np, b_np) np_res = np.matmul(np_res, np.transpose(b_np, (0, 2, 1))) np_res = np.maximum(np_res, 0) assert np.allclose(res1.numpy(), np_res, atol=1e-3)
def test_api(self): flags = { 'FLAGS_eager_delete_tensor_gb': 1.0, 'FLAGS_check_nan_inf': True } fluid.set_flags(flags) flags_list = ['FLAGS_eager_delete_tensor_gb', 'FLAGS_check_nan_inf'] flag = 'FLAGS_eager_delete_tensor_gb' res_list = fluid.get_flags(flags_list) res = fluid.get_flags(flag) self.assertTrue(res_list['FLAGS_eager_delete_tensor_gb'], 1.0) self.assertTrue(res_list['FLAGS_check_nan_inf'], True) self.assertTrue(res['FLAGS_eager_delete_tensor_gb'], 1.0)
def check(): print("check: _global_flags()['FLAGS_use_mkldnn']=", _global_flags()["FLAGS_use_mkldnn"]) print("check: fluid.get_flags('FLAGS_use_mkldnn')=", fluid.get_flags(['FLAGS_use_mkldnn'])) print("check: DNNL_VERBOSE=", os.environ['DNNL_VERBOSE']) a_np = np.random.uniform(-2, 2, (10, 20, 30)).astype(np.float32) helper = LayerHelper(fluid.unique_name.generate(str("test")), act="relu") func = helper.append_activation with fluid.dygraph.guard(fluid.core.CPUPlace()): a = fluid.dygraph.to_variable(a_np) res1 = func(a) res2 = np.maximum(a_np, 0) assert (np.array_equal(res1.numpy(), res2))
def test_get_private_flag(): fluid.get_flags('FLAGS_use_mkldnn')
def test_get_flags_input_type(): fluid.get_flags(flag)
def test_get_private_flag(): fluid.get_flags('FLAGS_free_idle_chunk')