def set_dim_func_(inputs, data_format="DefaultFormat", axis=1): """set dim info""" shape = get_shape(input[1]) params = check_inputs(inputs, data_format, axis) axis = params.get("axis", (0, )) is_special5d = params.get("is_special5d", False) hash_key1 = str((tuple(shape), input[1].dtype)) if hash_key1 in set_dim_map_: return ct_util.set_dims_by_key(hash_key1, set_dim_map_), hash_key1 hash_key = str((len(shape), input[1].dtype, axis, is_special5d)) return ct_util.set_dims_by_key(hash_key, set_dim_map_)
def segment_max_set_dim_func(data, segment_ids, num_segments): key = [] key.append(tuple(data.shape)) key.append(data.dtype) hash_key = str((tuple(key))) return ct_util.set_dims_by_key(hash_key, segment_max_set_dim_map), hash_key
def load3d_set_dim(tensor_fmap, kernel, stride, pad): fmap_n, fmap_c1, fmap_h, fmap_w, fmap_c0 = tensor_fmap.shape filter_h, filter_w = kernel # calculate the tiling factor. ho = (fmap_h + pad[0] + pad[1] - filter_h) // (stride[0]) + 1 wo = (fmap_w + pad[2] + pad[3] - filter_w) // (stride[1]) + 1 mode = True if (ho.value * wo.value) % 16 == 0: h_cut = (ho * wo) // 16 if has_pad(pad): mode = False else: h_cut = (fmap_n * ho * wo) // 16 mode = False co_cut = filter_h * filter_w key = ((fmap_n, fmap_c1, fmap_h, fmap_w, fmap_c0), kernel, stride, pad) set_dims = ct_util.set_dims_by_key(str(key), load3d_set_dim_map) if set_dims == '': dims = () if mode and fmap_n.value > 1: dims += ((1, 0), ) dims += ((h_cut, 0), (co_cut, 0)) return ct_util.set_dims(dims), str(key) return set_dims, str(key)
def smooth_l1_loss_set_dim_func(prediction, _target, anchor_samples, _anchor_sample_correct, _delta): """dim function""" key = get_shape(prediction) hash_key = str((tuple(key), prediction.dtype, anchor_samples.dtype)) return ct_util.set_dims_by_key(hash_key, smooth_l1_loss_set_dim_map), hash_key
def fused_layernorm_set_dim_func(data, _gamma, _beta, begin_norm_axis, begin_params_axis): """dim function""" shape = [x.value for x in data.shape] hash_key = str( (tuple(shape), begin_norm_axis, begin_params_axis, data.dtype)) return ct_util.set_dims_by_key(hash_key, fused_layernorm_set_dim_map), hash_key
def transpose_set_dim_func(data, axes): key = [] shape = [x.value for x in data.shape] key.append(tuple(shape)) key.append(tuple(axes)) hash_key = str((tuple(key), data.dtype)) return ct_util.set_dims_by_key(hash_key, transpose_set_dim_map), hash_key
def set_dim_func_(dy, data, mean, var, gamma, eps=1e-3, data_format="DefaultFormat", axis=1): """set dim info""" shape = get_shape(data) params = check_inputs(dy, data, mean, var, gamma, data_format, axis) axis = params["axis"] is_special5d = params["is_special5d"] hash_key1 = str((tuple(shape), data.dtype)) if hash_key1 in set_dim_map_: return ct_util.set_dims_by_key(hash_key1, set_dim_map_), hash_key1 hash_key = str((len(shape), data.dtype, axis, is_special5d)) return ct_util.set_dims_by_key(hash_key, set_dim_map_), hash_key
def softmax_grad_set_dim_func(x, dy, axis): key = [] shape = [int(x.shape[i].value) for i in range(len(x.shape))] key.append(tuple(shape)) key.append(axis) dtype = x.dtype hash_key = str((tuple(key), dtype)) return ct_util.set_dims_by_key(hash_key, softmax_grad_set_dim_map), hash_key
def maxpool_grad_set_dim_func(x, y, dy, kernel, stride, pad): """dim func for maxpool grad""" key = str((tuple(x.shape), tuple(kernel), tuple(stride), pad)) attrs = {} if key in set_attr_map_.keys(): for attr in set_attr_map_[key]: attrs[attr[0]] = attr[1] if key in maxpool_grad_dim_map.keys(): return ct_util.set_dims_by_key(key, maxpool_grad_dim_map), key, attrs return "", key, attrs
def unsortedsegmentsum_set_dim_func(input_data, ids_tensor, num_segments): key = [] for x in input_data.shape: key.append(x) for x in ids_tensor.shape: key.append(x) key.append(num_segments) hash_key = str((tuple(key), input_data.dtype)) return ct_util.set_dims_by_key(hash_key, unsortedsegmentsum_set_dim_map), hash_key
def smooth_l1_loss_ad_set_dim_func(head, prediction, target, anchor_samples, anchor_sample_correct=0, delta=1.0): key = [] for x in prediction.shape: key.append(x) hash_key = str((tuple(key), prediction.dtype, anchor_samples.dtype)) return ct_util.set_dims_by_key(hash_key, smooth_l1_loss_ad_set_dim_map), hash_key
def encode_one_hot_set_dim_func(groundtruth_class, anchor_sample, class_num): """setdim function""" shape1 = [] shape2 = [] for x in groundtruth_class.shape: shape1.append(x) for x in anchor_sample.shape: shape2.append(x) hash_key = str( (tuple(shape1), tuple(shape2), class_num, groundtruth_class.dtype)) return ct_util.set_dims_by_key(hash_key, encode_one_hot_set_dim_map), hash_key
def set_dim_func_(input1): """ Tiling func. Args: input1:tvm.Tensor of type float32, 3d shape. Returns: Tiling parameter. """ shape1 = input1.shape hash_key = str((shape1)) if hash_key in set_dim_map_.keys(): print(set_dim_map_.keys()) return ct_util.set_dims_by_key(hash_key, set_dim_map_), hash_key
def fused_layer_norm_grad_set_dim_func(x, _dy, _variance, _mean, _gamma, begin_norm_axis, begin_params_axis): """dim function""" shape = get_shape(x) if begin_norm_axis < 0: begin_norm_axis = begin_norm_axis + len(shape) if begin_params_axis < 0: begin_params_axis = begin_params_axis + len(shape) hash_key = str((shape, begin_norm_axis, begin_params_axis, x.dtype)) attr_map = dict() attr_map["pragma_checkcoincident"] = 0 if hash_key in fused_layer_norm_grad_set_attr_map.keys(): for attr in fused_layer_norm_grad_set_attr_map[hash_key]: attr_map[attr] = 1 return ct_util.set_dims_by_key(hash_key, fused_layer_norm_grad_set_dim_map), hash_key, attr_map
def four2five_set_dim_func(data, format_, dst_type): """set dim info for attr.""" shape = get_shape(data) if format_ == 'NCHW': n, _, h, w = shape else: n, h, w, _ = shape shape[0] = 1 if h != 1 and w != 1: if format_ == 'NCHW' and shape[1] > 16: shape[1] = 1 if format_ == 'NHWC' and shape[-1] > 16: shape[-1] = 1 if n == 1: shape.remove(shape[0]) hash_key = str((tuple(shape), format_, data.dtype, dst_type)) return ct_util.set_dims_by_key(hash_key, four2five_set_dim_map), hash_key
def relu6_grad_set_dim_func(dy, features): shape = [x.value for x in dy.shape] hash_key = str((tuple(shape), dy.dtype)) return ct_util.set_dims_by_key(hash_key, relu6_grad_set_dim_map), hash_key
def add_set_dim_func(dy, A, w): shape1 = [x.value for x in dy.shape] shape2 = [x.value for x in w.shape] hash_key = gen_set_dim_key(dy, shape1, shape2) return [ct_util.set_dims_by_key(hash_key, add_set_dim_map), hash_key]
def fractal2two_set_dim_func(data, out_dtype, shape_original, format_): shape = [x for x in data.shape] hash_key = str((tuple(shape), format_, data.dtype)) return ct_util.set_dims_by_key(hash_key, fractal2two_set_dim_map), hash_key
def two2fractal_set_dim_func(data, format_): shape = [x for x in data.shape] hash_key = str((tuple(shape), format_, data.dtype)) return ct_util.set_dims_by_key(hash_key, two2fractal_set_dim_map), hash_key
def lamb_apply_optimizer_assign_set_dim_func(data): """set dim info for attr.""" shape = get_shape(data) hash_key = str((tuple(shape), data.dtype)) return ct_util.set_dims_by_key( hash_key, lamb_apply_optimizer_assign_set_dim_map), hash_key