Ejemplo n.º 1
0
 def test_pixel_shuffle(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_pixel_shuffle_impl]
     arg_dict["device"] = ["cpu", "cuda"]
     arg_dict["shape"] = [(2, 144, 5, 5), (11, 144, 1, 1)]
     arg_dict["h_upscale_factor"] = [2, 3, 4]
     arg_dict["w_upscale_factor"] = [2, 3, 4]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
     arg_dict["shape"] = [(8, 25, 18, 18), (1, 25, 2, 2)]
     arg_dict["h_upscale_factor"] = [5]
     arg_dict["w_upscale_factor"] = [5]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 2
0
    def test_tensordot_tensor_dim(test_case):
        def _test_tensor_dim(test_case, device):
            np_dim = np.array([[1, 2, 3], [1, 2, 3]], dtype=np.int)
            flow_dim = flow.tensor(np_dim).to(device)
            torch_dim = torch.tensor(np_dim).to(device)

            np_random_array = np.random.randn(2, 3, 4, 5)
            flow_tensor = flow.tensor(np_random_array).to(device)
            torch_tensor = torch.tensor(np_random_array).to(device)

            flow_result = flow.tensordot(flow_tensor,
                                         flow_tensor,
                                         dims=flow_dim)
            torch_result = torch.tensordot(torch_tensor,
                                           torch_tensor,
                                           dims=torch_dim)
            test_case.assertTrue(
                np.allclose(
                    flow_result.numpy(),
                    torch_result.cpu().numpy(),
                    rtol=0.0001,
                    atol=0.0001,
                ))

        arg_dict = OrderedDict()
        arg_dict["device"] = ["cpu", "cuda"]
        for arg in GenArgList(arg_dict):
            _test_tensor_dim(test_case, arg[0])
Ejemplo n.º 3
0
 def test_ones_like(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_ones_like_float, _test_ones_like_int]
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 4
0
 def test_argwhere(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_argwhere]
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6), (2, 3, 0, 4)]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 5
0
 def test_reflection_pad2d(test_case):
     arg_dict = OrderedDict()
     arg_dict["shape"] = [(1, 2, 3, 4), (8, 3, 4, 4)]
     arg_dict["padding"] = [2, (1, 1, 2, 2)]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         _test_reflection_pad2d(test_case, *arg)
Ejemplo n.º 6
0
 def test_cos(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_cos, _test_cos_backward]
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 3, 4, 5)]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 7
0
 def test_type_tensortype_cpu(test_case):
     # test tensor.type(x: tensortype) rather than tensor.type_tensortype
     arg_dict = OrderedDict()
     arg_dict["shape"] = [(1, 2), (3, 4, 5), (2, 3, 4, 5)]
     arg_dict["device"] = ["cpu", "cuda"]
     arg_dict["src_dtype"] = [
         flow.uint8,
         flow.int8,
         flow.int64,
         flow.int32,
         flow.float16,
         flow.float32,
         flow.float64,
     ]
     tensortype_dict = {
         flow.CharTensor: [flow.int8, flow.device("cpu")],
         flow.ByteTensor: [flow.uint8, flow.device("cpu")],
         flow.IntTensor: [flow.int32, flow.device("cpu")],
         flow.LongTensor: [flow.int64, flow.device("cpu")],
         flow.HalfTensor: [flow.float16, flow.device("cpu")],
         flow.FloatTensor: [flow.float32, flow.device("cpu")],
         flow.DoubleTensor: [flow.float64, flow.device("cpu")],
     }
     arg_dict["tgt_tensortype"] = list(tensortype_dict.keys())
     for arg in GenArgList(arg_dict):
         _test_type_tensortype(test_case, tensortype_dict, *arg)
Ejemplo n.º 8
0
    def test_reduce(test_case):
        arg_dict = OrderedDict()
        arg_dict["dst"] = [0, 1, 2, 3]
        arg_dict["device"] = ["cpu", "cuda"]

        for arg in GenArgList(arg_dict):
            _test_reduce(test_case, *arg)
Ejemplo n.º 9
0
 def test_triu(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_triu]
     arg_dict["diagonal"] = [2, -1]
     arg_dict["device"] = ["cuda", "cpu"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 10
0
 def test_autograd_interface(test_case):
     arg_dict = OrderedDict()
     arg_dict["case"] = [_test_autograd_backward, _test_autograd_grad]
     arg_dict["shape"] = [(2, 3), (2, 3, 4, 5)]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 11
0
 def test_expm1(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_expm1_impl]
     arg_dict["device"] = ["cpu", "cuda"]
     arg_dict["shape"] = [(1, ), (2, 3), (2, 3, 4), (2, 3, 4, 5)]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 12
0
 def test_global_ZeroPad2d(test_case):
     arg_dict = OrderedDict()
     arg_dict["padding"] = [2, (1, 1, 2, 2)]
     for arg in GenArgList(arg_dict):
         for placement in all_placement():
             for sbp in all_sbp(placement, max_dim=4):
                 _test_global_ZeroPad2d(test_case, placement, sbp, *arg)
Ejemplo n.º 13
0
 def test_in_top_k(test_case):
     arg_dict = OrderedDict()
     arg_dict["shape"] = [(2, 3), (3, 4), (5, 6)]
     arg_dict["k"] = [1, 2, 5]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         _test_in_top_k_impl(test_case, *arg)
Ejemplo n.º 14
0
 def test_gpu_fixed_dropout(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [
         fixed_gpu_seed_dropout_test,
     ]
     for arg in GenArgList(arg_dict):
         arg[0](test_case)
Ejemplo n.º 15
0
 def test_tensor_str_1n2d(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [
         _test_global_tensor_str_2d,
     ]
     arg_dict["device"] = ["cuda", "cpu"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 16
0
 def test_ConstantPad2d(test_case):
     arg_dict = OrderedDict()
     arg_dict["shape"] = [(1, 2, 3, 4), (8, 3, 4, 4)]
     arg_dict["padding"] = [2, (1, 1, 2, 2)]
     arg_dict["value"] = [0.0]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         _test_ZeroPad2d(test_case, *arg)
Ejemplo n.º 17
0
 def test_inplace_contiguous(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [
         _tets_inplace_contiguous,
     ]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 18
0
    def test_gather(test_case):
        arg_dict = OrderedDict()
        arg_dict["test_fun"] = [_test_fused_bias_add_gelu]
        arg_dict["channel"] = [2, 4, 6, 8]
        arg_dict["axis"] = [1]

        for arg in GenArgList(arg_dict):
            arg[0](test_case, *arg[1:])
Ejemplo n.º 19
0
 def test_list_indexing_using_scalar_tensor(test_case):
     arg_dict = OrderedDict()
     arg_dict["function_test"] = [
         _test_list_indexing_using_scalar_tensor,
     ]
     arg_dict["dtype"] = [flow.uint8, flow.int8, flow.int32, flow.int64]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 20
0
 def test_eager_boxing_1d_special_split_axis(test_case):
     arg_dict = OrderedDict()
     arg_dict["in_device"] = ["cpu", "cuda"]
     arg_dict["out_device"] = ["cpu", "cuda"]
     arg_dict["in_device_list"] = [[0, 1], [1, 2, 3], [0, 1, 2, 3]]
     arg_dict["out_device_list"] = [[0, 1, 3], [0, 1, 2, 3]]
     for arg in GenArgList(arg_dict):
         _test_eager_boxing_1d_special_split_axis(test_case, *arg)
Ejemplo n.º 21
0
 def test_eye_with_1n2d(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_eye_with_1n2d]
     arg_dict["n"] = [4, 3, 2]
     arg_dict["m"] = [4, 3, 2]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 22
0
 def test_clip_value(test_case):
     arg_dict = OrderedDict()
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)]
     arg_dict["device"] = ["cpu", "cuda"]
     arg_dict["clip_value"] = [0, 0.5, 1.0]
     for arg in GenArgList(arg_dict):
         _test_clip_grad_value_impl(test_case, *arg)
         _test_graph_clip_grad_value_impl(test_case, *arg)
Ejemplo n.º 23
0
 def test_clip_grad(test_case):
     arg_dict = OrderedDict()
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)]
     arg_dict["device"] = ["cpu", "cuda"]
     arg_dict["max_norm"] = [0, 0.5, 1.0]
     arg_dict["norm_type"] = ["inf", "-inf", 0.0, 1.0, 2.0, 3.5]
     for arg in GenArgList(arg_dict):
         _test_clip_grad_norm_impl(test_case, *arg)
Ejemplo n.º 24
0
 def test_nonzero(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_nonzero]
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6), (2, 3, 0, 4)]
     arg_dict["as_tuple"] = [True, False]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 25
0
 def test_masked_select(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [
         _test_masked_select, _test_masked_select_broadcast
     ]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 26
0
    def test_0d_randn(test_case):
        arg_dict = OrderedDict()
        arg_dict["test_fun"] = [_test_0d_rand]
        arg_dict["device"] = ["cpu", "cuda"]
        arg_dict["shape"] = [(2, 0, 4), (2, 0, 2)]

        for arg in GenArgList(arg_dict):
            arg[0](test_case, *arg[1:])
Ejemplo n.º 27
0
    def test_batch_gather(test_case):
        arg_dict = OrderedDict()
        arg_dict["test_fun"] = [_test_batch_gather]
        arg_dict["shape"] = [(3, 2, 2), (3, 2, 4, 2), (3, 3, 4, 2, 2), (4, 2)]
        arg_dict["device"] = ["cpu", "cuda"]

        for arg in GenArgList(arg_dict):
            arg[0](test_case, *arg[1:])
Ejemplo n.º 28
0
 def test_util_ops(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_isnan, _test_isinf]
     arg_dict["shape"] = [(2, 3, 4), (1, 2, 3)]
     arg_dict["dtype"] = [flow.float, flow.int]
     arg_dict["device"] = ["cpu", "cuda"]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 29
0
 def test_fuse_bias_add_dropout(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [_test_fused_bias_add_dropout]
     arg_dict["shape"] = [(16, 64, 72), (32, 16, 48)]
     arg_dict["axis"] = [0, 1, 2, -1, -2, -3]
     arg_dict["drop_prob"] = [0.0, 1.0]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])
Ejemplo n.º 30
0
 def test_cast(test_case):
     arg_dict = OrderedDict()
     arg_dict["test_fun"] = [
         _test_different_dtype,
     ]
     arg_dict["device"] = ["cpu", "cuda"]
     arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 3, 4, 5), (2, 0, 4)]
     for arg in GenArgList(arg_dict):
         arg[0](test_case, *arg[1:])