def test_fused_scale_tril_fw_bw(test_case): arg_dict = OrderedDict() arg_dict["device"] = ["gpu"] arg_dict["type_name"] = [ "float32", "float16", "double", "int32", "int64", ] arg_dict["shape"] = [(6, 6), (3, 6, 8)] arg_dict["diagonal"] = [-8, -1, 0, 1, 8] arg_dict["fill_value"] = [1.0, 0] arg_dict["scale"] = [5.0, 3] for arg in GenArgDict(arg_dict): if arg["device"] == "cpu" and arg["type_name"] == "float16": continue if isinstance(arg["fill_value"], float) and arg_dict["type_name"] not in [ "float32", "float16", "double", ]: continue _test_fused_scale_tril_fw_bw(test_case, **arg)
def test_masked_fill_fw_bw(test_case): arg_dict = OrderedDict() arg_dict["type_name"] = [ "float32", "float16", "double", "int8", "int32", "int64", ] arg_dict["device"] = ["gpu", "cpu"] arg_dict["x_shape"] = [ (2, 4), (1, 4), (2, 2, 4), (2, 1, 4), (2, 3, 2, 4), (2, 2, 3, 2, 4), ] arg_dict["mask_shape"] = [(2, 1, 2, 4)] arg_dict["value"] = [2.5, 3.3, -5.5] for arg in GenArgDict(arg_dict): if arg["device"] == "cpu" and arg["type_name"] == "float16": continue _test_masked_fill_fw_bw(test_case, **arg)
def test_element_wise_mul_fw_bw(test_case): arg_dict = OrderedDict() arg_dict["device"] = ["gpu", "cpu"] arg_dict["shape"] = [(96, 96)] arg_dict["type_name"] = ["float32", "double", "int8", "int32", "int64"] for arg in GenArgDict(arg_dict): _test_element_wise_mul_fw_bw(test_case, **arg)
def test_gather_nd_case_1(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(20, 10, 10, 3, 3)] arg_dict["index_shape"] = [(2, 3, 3)] arg_dict["device_type"] = ["gpu"] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_assign(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(10), (30, 4), (8, 256, 20)] arg_dict["dtype"] = [flow.float, flow.double] arg_dict["device_type"] = ["cpu", "gpu"] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_pad(test_case): arg_dict = OrderedDict() arg_dict["device_type"] = ["cpu", "gpu"] arg_dict["flow_op"] = [flow.pad] arg_dict["tf_op"] = [tf.pad] arg_dict["input_shape"] = [(2, 2, 1, 3), (1, 1, 2, 3)] arg_dict["op_args"] = [ Args( [([1, 2], [0, 0], [1, 2], [1, 1])], tf.constant([([1, 2], [0, 0], [1, 2], [1, 1])]), ), Args( [([0, 0], [30, 0], [0, 1], [1, 0]), 99999999999999999999999999999999], [ tf.constant(([0, 0], [30, 0], [0, 1], [1, 0])), "constant", 99999999999999999999999999999999, ], ), Args( [([10, 0], [0, 0], [10, 20], [0, 0])], tf.constant([([10, 0], [0, 0], [10, 20], [0, 0])]), ), ] for arg in GenArgDict(arg_dict): CompareOpWithTensorFlow(**arg)
def test_gather_nd_case_3(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(32, 60, 80, 25)] arg_dict["index_shape"] = [(128, 2)] arg_dict["device_type"] = ["gpu"] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_batchnorm_fp16(test_case): arg_dict = OrderedDict() arg_dict["device_type"] = ["gpu"] arg_dict["input_shape"] = [(2, 4, 3, 5)] arg_dict["input_minval"] = [-2] arg_dict["input_maxval"] = [2] arg_dict["op_args"] = [ Args([1]), Args([2]), Args([1, 0.95, 0.0001]), Args([1, 0.99, 0.001, False]), Args([1, 0.99, 0.001, False, False]), Args([]), Args([1, 0.95, 0.1]), ] for arg in GenArgDict(arg_dict): CompareFp16WithFp32(**arg, training=False, trainable=False, y_rtol=1e-3, y_atol=1e-3) CompareFp16WithFp32(**arg, training=True, trainable=True, y_rtol=1e-3, y_atol=1e-3, x_diff_rtol=1e-3, x_diff_atol=1e-3) CompareFp16WithFp32(**arg, training=False, trainable=True, y_rtol=1e-3, y_atol=1e-3, x_diff_rtol=1e-3, x_diff_atol=1e-3)
def test_outputs_int32(test_case): arg_dict = OrderedDict() arg_dict["device"] = test_device arg_dict["output"] = [train_int32] arg_dict["requires_grad"] = [False] for arg in GenArgDict(arg_dict): train(test_case, train_x, **arg)
def test_bias_add_nchw(test_case): arg_dict = OrderedDict() arg_dict["device_type"] = ["cpu", "gpu"] arg_dict["input_shapes"] = [((1, 20, 1, 11), (20, ))] arg_dict["op_args"] = [Args(["NCHW"])] for arg in GenArgDict(arg_dict): CompareBiasAddWithTensorFlow(**arg)
def test_batchnorm_relu(test_case): arg_dict = OrderedDict() arg_dict["input_shape"] = [(12, 16, 24, 32), (5, 7, 9, 11)] arg_dict["axis"] = [0, 1, 2, 3] arg_dict["data_type"] = [flow.float32, flow.float16] for arg in GenArgDict(arg_dict): _test_batchnorm_relu(test_case, **arg)
def test_gpu(self): d = OrderedDict({ "shape": [(96, 96), (3, 3)], "in_type": [flow.float32], "device": ["gpu"], }) for arg in GenArgDict(d): self.run_job(**arg)
def test_local_empty(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 3, 4, 5)] arg_dict["dtype"] = [flow.float32, flow.float16, flow.int32] arg_dict["device"] = ["cpu", "cuda"] arg_dict["requires_grad"] = [True, False] for arg in GenArgDict(arg_dict): _test_local_empty(test_case, **arg)
def test_with_empty_index(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(12, 13, 7)] arg_dict["index_shape"] = [(5, 10, 2)] arg_dict["dynamic_index_shape"] = [(5, 0, 2)] arg_dict["device_type"] = ["cpu", "gpu"] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_case_1(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(10,)] arg_dict["data_type"] = ["float32", "double", "int32"] arg_dict["device_type"] = ["gpu", "cpu"] arg_dict["device_num"] = [4] for arg in GenArgDict(arg_dict): _check_cast_to_static_shape(test_case, **arg)
def test_nn_batchnorm(test_case): arg_dict = OrderedDict() arg_dict["input_shape"] = [(2, 4, 3, 5)] arg_dict["data_type"] = ["float32"] arg_dict["axis"] = [1, -1] arg_dict["epsilon"] = [1.001e-5, 1e-4] for arg in GenArgDict(arg_dict): CompareNnBnWithTensorFlow(**arg)
def test_bias_add_nhwc(test_case): arg_dict = OrderedDict() arg_dict["device_type"] = ["cpu", "gpu"] arg_dict["input_shapes"] = [((30, 20, 5, 10), (10, )), ((2, 5, 7, 8), (8, ))] arg_dict["op_args"] = [Args(["NHWC"])] for arg in GenArgDict(arg_dict): CompareBiasAddWithTensorFlow(**arg)
def test_gather_nd_case_4(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(128, 64, 2, 16, 7)] arg_dict["index_shape"] = [(30, 10, 3)] arg_dict["device_type"] = ["gpu"] arg_dict["dynamic"] = [True] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_with_dynamic_index(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(25, 10)] arg_dict["index_shape"] = [(15, 1)] arg_dict["dynamic_index_shape"] = [(11, 1)] arg_dict["device_type"] = ["cpu", "gpu"] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_consistent_empty(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 3, 4, 5)] arg_dict["dtype"] = [flow.float32, flow.float16, flow.int32] arg_dict["placement"] = ["cpu", "cuda"] arg_dict["sbp"] = [flow.sbp.broadcast] arg_dict["requires_grad"] = [True, False] for arg in GenArgDict(arg_dict): _test_consistent_empty(test_case, **arg)
def test_where_case_3(test_case): arg_dict = OrderedDict() arg_dict["cond_shape"] = [[12, 25, 6]] arg_dict["x_shape"] = [[12, 1, 6]] arg_dict["y_shape"] = [[25, 1]] arg_dict["device_type"] = ["gpu", "cpu"] arg_dict["dynamic"] = [True, False] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_where_grad_case_2(test_case): arg_dict = OrderedDict() arg_dict["cond_shape"] = [[16, 1]] arg_dict["x_shape"] = [[4, 1, 20]] arg_dict["y_shape"] = [[8, 4, 16, 20]] arg_dict["device_type"] = ["gpu", "cpu"] arg_dict["dynamic"] = [True, False] for arg in GenArgDict(arg_dict): _compare_with_tf(test_case, **arg)
def test_gpu(self): d = OrderedDict({ "shape": [(96, 96), (3, 3)], "in_type": [flow.int64], "out_type": [flow.float32], "device": ["gpu"], }) for arg in GenArgDict(d): self.run_fuse_cast_scale_mlir(**arg)
def test_fused_scale_tril(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(5, 5), (4, 6)] arg_dict["diagonal"] = [-1, 0, 1] arg_dict["fill_value"] = [-1, 0, 1] arg_dict["scale"] = [-2.3, 0.7, 2] arg_dict["dtype"] = [flow.float32] for kwargs in GenArgDict(arg_dict): _test_fused_scale_tril(test_case, **kwargs)
def test_argwhere(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(10), (30, 4), (8, 256, 20)] arg_dict["value_dtype"] = [np.float32, np.int32, np.int8] arg_dict["index_dtype"] = [np.int32, np.int64] arg_dict["device_type"] = ["cpu", "gpu"] arg_dict["dynamic"] = [True, False] arg_dict["verbose"] = [False] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_sqrt(test_case): arg_dict = OrderedDict() arg_dict["device_type"] = ["gpu"] arg_dict["flow_op"] = [flow.math.sqrt] arg_dict["tf_op"] = [tf.math.sqrt] arg_dict["input_shape"] = [(10, 20, 30)] arg_dict["input_minval"] = [0] arg_dict["input_maxval"] = [100] for arg in GenArgDict(arg_dict): CompareOpWithTensorFlow(**arg)
def test_logical_slice_2dim_3d(test_case): var_shape = (30, 40) slice_tuples = [(10, 20, 3), (1, 30, 4)] arg_dict = OrderedDict() arg_dict["split_axis"] = list(range(2)) arg_dict["device_tag"] = ["cpu", "gpu"] arg_dict["flow_dtype"] = [flow.float] arg_dict["device_num"] = [3] for arg in GenArgDict(arg_dict): _test_logical_slice(test_case, var_shape, slice_tuples, **arg)
def test_argwhere_multi_iter(test_case): arg_dict = OrderedDict() arg_dict["iter_num"] = [2] arg_dict["shape"] = [(20, 4)] arg_dict["value_dtype"] = [np.float32, np.int32, np.int8] arg_dict["index_dtype"] = [np.int32, np.int64] arg_dict["device_type"] = ["cpu", "gpu"] arg_dict["verbose"] = [False] for arg in GenArgDict(arg_dict): _dynamic_multi_iter_compare(test_case, **arg)
def test_gather_nd(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(10,)] arg_dict["index_shape"] = [(5, 1)] arg_dict["dtype"] = ["float32", "int32", "double"] arg_dict["index_dtype"] = ["int32", "int64"] arg_dict["device_type"] = ["gpu", "cpu"] arg_dict["dynamic"] = [False, True] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)
def test_gather_nd_case_2(test_case): arg_dict = OrderedDict() arg_dict["shape"] = [(10, 8, 4)] arg_dict["index_shape"] = [(2, 2)] arg_dict["dtype"] = ["float32", "int32"] arg_dict["index_dtype"] = ["int32", "int64"] arg_dict["device_type"] = ["cpu", "gpu"] arg_dict["dynamic"] = [True] for arg in GenArgDict(arg_dict): _compare_with_np(test_case, **arg)