示例#1
0
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)
示例#2
0
    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)
示例#3
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))
示例#4
0
 def test_get_private_flag():
     fluid.get_flags('FLAGS_use_mkldnn')
示例#5
0
 def test_get_flags_input_type():
     fluid.get_flags(flag)
示例#6
0
 def test_get_private_flag():
     fluid.get_flags('FLAGS_free_idle_chunk')