From 4b2e90d31c12ce1c15295ea9f956d93c21684ee4 Mon Sep 17 00:00:00 2001 From: co63oc Date: Thu, 18 Jan 2024 11:31:56 +0800 Subject: [PATCH] Fix minimun minimum (#60920) --- python/paddle/sparse/creation.py | 4 +- python/paddle/sparse/nn/layer/activation.py | 2 +- python/paddle/sparse/nn/layer/conv.py | 40 +++++++++---------- python/paddle/sparse/nn/layer/norm.py | 2 +- python/paddle/sparse/unary.py | 4 +- python/paddle/static/input.py | 2 +- python/paddle/static/io.py | 26 ++++++------ python/paddle/static/nn/common.py | 16 ++++---- python/paddle/static/nn/control_flow.py | 24 +++++------ .../static/quantization/cal_kl_threshold.py | 2 +- .../post_training_quantization.py | 22 +++++----- python/paddle/static/quantization/quanter.py | 6 +-- .../static/quantization/quantization_pass.py | 12 +++--- python/paddle/tensor/array.py | 16 ++++---- 14 files changed, 89 insertions(+), 89 deletions(-) diff --git a/python/paddle/sparse/creation.py b/python/paddle/sparse/creation.py index f5a7fe306723f..89ee841053a97 100644 --- a/python/paddle/sparse/creation.py +++ b/python/paddle/sparse/creation.py @@ -155,7 +155,7 @@ def sparse_coo_tensor( shape = list(shape) if shape < min_shape: raise ValueError( - f"the minimun shape required is {min_shape}, but get {shape}" + f"the minimum shape required is {min_shape}, but get {shape}" ) if len(shape) != sparse_dim + dense_dim: raise ValueError( @@ -188,7 +188,7 @@ def sparse_csr_tensor( r""" Constructs a sparse ``paddle.Tensor`` in CSR(Compressed Sparse Row) format according to the ``crows``, ``cols`` and ``values``. - Currently, the crows and cols of each batch must be incrementd. + Currently, the crows and cols of each batch must be incremented. Args: crows(list|tuple|ndarray|Tensor): 1-D array, each element in the rows represents the diff --git a/python/paddle/sparse/nn/layer/activation.py b/python/paddle/sparse/nn/layer/activation.py index eedecc7a3b1d2..ec01db4fc0dc7 100644 --- a/python/paddle/sparse/nn/layer/activation.py +++ b/python/paddle/sparse/nn/layer/activation.py @@ -72,7 +72,7 @@ class Softmax(Layer): Only support axis=-1 for SparseCsrTensor, which is faster when read data by row (axis=-1). - Transform x to dense matix, and :math:`i` is row index, :math:`j` is column index. + Transform x to dense matrix, and :math:`i` is row index, :math:`j` is column index. If axis=-1, We have: .. math:: diff --git a/python/paddle/sparse/nn/layer/conv.py b/python/paddle/sparse/nn/layer/conv.py index d3295148fbc15..6ed3c840f39e9 100644 --- a/python/paddle/sparse/nn/layer/conv.py +++ b/python/paddle/sparse/nn/layer/conv.py @@ -238,7 +238,7 @@ def extra_repr(self): class Conv3D(_Conv3D): r""" - **Sparse Convlution3d Layer** + **Sparse Convolution3d Layer** The Sparse convolution3d layer calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output) are multidimensional SparseCooTensors with a shape of @@ -267,11 +267,11 @@ class Conv3D(_Conv3D): stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must contain three integers, (stride_D, stride_H, stride_W). Otherwise, the stride_D = stride_H = stride_W = stride. The default value is 1. - padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms. + padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms. 1. a string in ['valid', 'same']. - 2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding` - 3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...]. - 4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions. + 2. an int, which means each spatial dimension(depth, height, width) is zero padded by size of `padding` + 3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...]. + 4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions. 5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0). The default value is 0. dilation(int|list|tuple, optional): The dilation size. If dilation is a list/tuple, it must @@ -373,7 +373,7 @@ def __init__( class Conv2D(_Conv2D): r""" - **Sparse Convlution2d Layer** + **Sparse Convolution2d Layer** The Sparse convolution2d layer calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and @@ -403,12 +403,12 @@ class Conv2D(_Conv2D): stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must contain three integers, (stride_H, stride_W). Otherwise, the stride_H = stride_W = stride. The default value is 1. - padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms. + padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms. 1. a string in ['valid', 'same']. - 2. an int, which means each spartial dimension(height, width) is zero paded by size of `padding` - 3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...]. - 4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions. + 2. an int, which means each spatial dimension(height, width) is zero padded by size of `padding` + 3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...]. + 4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions. 5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0). @@ -508,7 +508,7 @@ def __init__( class SubmConv3D(_Conv3D): r""" - **Submanifold Sparse Convlution3d Layer** + **Submanifold Sparse Convolution3d Layer** The submanifold sparse convolution3d layer calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output) are multidimensional SparseCooTensors with a shape of @@ -537,11 +537,11 @@ class SubmConv3D(_Conv3D): stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must contain three integers, (stride_D, stride_H, stride_W). Otherwise, the stride_D = stride_H = stride_W = stride. The default value is 1. - padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms. + padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms. 1. a string in ['valid', 'same']. - 2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding` - 3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...]. - 4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions. + 2. an int, which means each spatial dimension(depth, height, width) is zero padded by size of `padding` + 3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...]. + 4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions. 5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0). The default value is 0. dilation(int|list|tuple, optional): The dilation size. If dilation is a list/tuple, it must @@ -648,7 +648,7 @@ def __init__( class SubmConv2D(_Conv2D): r""" - **Submanifold Sparse Convlution2d Layer** + **Submanifold Sparse Convolution2d Layer** The submanifold sparse convolution2d layer calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and @@ -678,12 +678,12 @@ class SubmConv2D(_Conv2D): stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must contain two integers, (stride_H, stride_W). Otherwise, the stride_H = stride_W = stride. The default value is 1. - padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms. + padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms. 1. a string in ['valid', 'same']. - 2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding` - 3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...]. - 4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions. + 2. an int, which means each spatial dimension(depth, height, width) is zero padded by size of `padding` + 3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...]. + 4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions. 5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0). diff --git a/python/paddle/sparse/nn/layer/norm.py b/python/paddle/sparse/nn/layer/norm.py index 4b9b4087bd1b5..c83ce82f80686 100644 --- a/python/paddle/sparse/nn/layer/norm.py +++ b/python/paddle/sparse/nn/layer/norm.py @@ -260,7 +260,7 @@ class SyncBatchNorm(paddle.nn.SyncBatchNorm): epsilon(float, optional): The small value added to the variance to prevent division by zero. Default: 1e-5. momentum(float, optional): The value used for the moving_mean and moving_var computation. Default: 0.9. weight_attr(ParamAttr|bool, optional): The parameter attribute for Parameter `scale` - of this layer. If it is set to None or one attribute of ParamAttr, this layerr + of this layer. If it is set to None or one attribute of ParamAttr, this layer will create ParamAttr as param_attr. If the Initializer of the param_attr is not set, the parameter is initialized with Xavier. If it is set to False, this layer will not have trainable scale parameter. Default: None. diff --git a/python/paddle/sparse/unary.py b/python/paddle/sparse/unary.py index 9f9bafc135b63..ddb8fc669e8f8 100644 --- a/python/paddle/sparse/unary.py +++ b/python/paddle/sparse/unary.py @@ -953,7 +953,7 @@ def slice(x, axes, starts, ends, name=None): ``starts`` or ``ends`` such as :math:`-i`, it represents the reverse position of the axis :math:`i-1` (here 0 is the initial position). If the value passed to ``starts`` or ``ends`` is greater than the number of elements - in the dimenstion (n), it represents n. + in the dimension (n), it represents n. For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX. The size of ``axes`` must be equal to ``starts`` and ``ends``. @@ -1039,7 +1039,7 @@ def pca_lowrank(x, q=None, center=True, niter=2, name=None): Args: x (Tensor): The input tensor. Its shape should be `[N, M]`, - N and M can be arbitraty positive number. + N and M can be arbitrary positive number. The data type of x should be float32 or float64. q (int, optional): a slightly overestimated rank of :math:`X`. Default value is :math:`q=min(6,N,M)`. diff --git a/python/paddle/static/input.py b/python/paddle/static/input.py index f8ee2b9bfafbd..554aaf28a1cbd 100644 --- a/python/paddle/static/input.py +++ b/python/paddle/static/input.py @@ -207,7 +207,7 @@ class InputSpec: def __init__(self, shape, dtype='float32', name=None, stop_gradient=False): # replace `None` in shape with -1 self.shape = self._verify(shape) - # convert dtype into united represention + # convert dtype into united representation if dtype is not None: if isinstance(dtype, (np.dtype, str)): dtype = convert_np_dtype_to_dtype_(dtype) diff --git a/python/paddle/static/io.py b/python/paddle/static/io.py index 7426dc0b05b0f..64ee380b4b392 100644 --- a/python/paddle/static/io.py +++ b/python/paddle/static/io.py @@ -197,7 +197,7 @@ def normalize_program(program, feed_vars, fetch_vars, **kwargs): feed_vars(Tensor | list[Tensor]): Variables needed by inference. fetch_vars(Tensor | list[Tensor]): Variables returned by inference. kwargs: Supported keys including ``skip_prune_program``. - - skip_prune_program(bool): whether to skip prunning program. Defaults to False. + - skip_prune_program(bool): whether to skip pruning program. Defaults to False. Returns: Program: Normalized/Optimized program. @@ -211,7 +211,7 @@ def normalize_program(program, feed_vars, fetch_vars, **kwargs): >>> path_prefix = "./infer_model" - # User defined network, here a softmax regession example + # User defined network, here a softmax regression example >>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32') >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') >>> predict = paddle.static.nn.fc(image, 10, activation='softmax') @@ -283,10 +283,10 @@ def normalize_program(program, feed_vars, fetch_vars, **kwargs): # remove backward block copy_program.blocks.pop(backward_block_id) # update attrs ``blocks`` - reserverd_blocks = [] + reserved_blocks = [] for block_id in sub_blocks_ids[:-1]: - reserverd_blocks.append(copy_program.block(block_id)) - op._update_desc_attr("blocks", reserverd_blocks) + reserved_blocks.append(copy_program.block(block_id)) + op._update_desc_attr("blocks", reserved_blocks) for idx in remove_op_idx[::-1]: global_block._remove_op(idx) @@ -332,7 +332,7 @@ def serialize_program(feed_vars, fetch_vars, **kwargs): >>> path_prefix = "./infer_model" - # User defined network, here a softmax regession example + # User defined network, here a softmax regression example >>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32') >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') >>> predict = paddle.static.nn.fc(image, 10, activation='softmax') @@ -391,7 +391,7 @@ def serialize_persistables(feed_vars, fetch_vars, executor, **kwargs): >>> path_prefix = "./infer_model" - # User defined network, here a softmax regession example + # User defined network, here a softmax regression example >>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32') >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') >>> predict = paddle.static.nn.fc(image, 10, activation='softmax') @@ -431,7 +431,7 @@ def _serialize_persistables(program, executor): "variables in your model to save" ) return None - # create a new program and clone persitable vars to it + # create a new program and clone persistable vars to it save_program = Program() save_block = save_program.global_block() save_var_map = {} @@ -543,7 +543,7 @@ def save_inference_model( >>> path_prefix = "./infer_model" - # User defined network, here a softmax regession example + # User defined network, here a softmax regression example >>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32') >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') >>> predict = paddle.static.nn.fc(image, 10, activation='softmax') @@ -644,7 +644,7 @@ def deserialize_program(data): >>> path_prefix = "./infer_model" - # User defined network, here a softmax regession example + # User defined network, here a softmax regression example >>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32') >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') >>> predict = paddle.static.nn.fc(image, 10, activation='softmax') @@ -693,7 +693,7 @@ def deserialize_persistables(program, data, executor): >>> path_prefix = "./infer_model" - # User defined network, here a softmax regession example + # User defined network, here a softmax regression example >>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32') >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') >>> predict = paddle.static.nn.fc(image, 10, activation='softmax') @@ -1620,7 +1620,7 @@ def load(program, model_path, executor=None, var_list=None): program_var_list = program.list_vars() program_var_name_set = {var.name for var in program_var_list} - # check all the variable inlcuded in program + # check all the variable included in program for var in var_list: if var.name not in program_var_name_set: raise LookupError( @@ -1804,7 +1804,7 @@ def set_program_state(program, state_dict): unused_para_list.append(k) if len(unused_para_list) > 0: warnings.warn( - "This list is not set, Because of Paramerter not found in program. There are: {}".format( + "This list is not set, Because of Parameter not found in program. There are: {}".format( " ".join(unused_para_list) ) ) diff --git a/python/paddle/static/nn/common.py b/python/paddle/static/nn/common.py index 837420900502c..65f21a169cb63 100644 --- a/python/paddle/static/nn/common.py +++ b/python/paddle/static/nn/common.py @@ -496,7 +496,7 @@ def data_norm( should do model average when model average is enabled. Default: True. slot_dim (int, optional): The embedding dimension of one slot. Slot is a set of one specific feature. In pslib mode, we distinguish feature ids by slot and pull their embeddings from parameter server (pslib). The first - place of the embedding is the historical show number (occurence time of this feature id with a label 0). + place of the embedding is the historical show number (occurrence time of this feature id with a label 0). If the input of this op is concated by slot-wise embeddings, and the show number is zero when this slot is new or empty, the normalization result may be impractical. To avoid this, we add slot_dim to locate the show number and judge if the show number is zero. If so, we choose to skip normalization on this @@ -920,7 +920,7 @@ def conv2d( num_channels = input.shape[3] if channel_last else input.shape[1] if num_channels < 0: raise ValueError( - "The channel dimmention of the input({}) should be defined. " + "The channel dimension of the input({}) should be defined. " "Received: {}.".format(str(input.shape), str(num_channels)) ) assert param_attr is not False, "param_attr should not be False here." @@ -1236,7 +1236,7 @@ def conv3d( num_channels = input.shape[4] if channel_last else input.shape[1] if num_channels < 0: raise ValueError( - "The channel dimmention of the input({}) should be defined. " + "The channel dimension of the input({}) should be defined. " "Received: {}.".format(str(input.shape), str(num_channels)) ) @@ -2811,11 +2811,11 @@ def batch_norm( variance_out = variance if in_dygraph_mode(): - inputs_has_MomemtumTensor = False + inputs_has_MomentumTensor = False attrs_has_momentum = False tmp_tensor_type = core.eager.Tensor if isinstance(momentum, tmp_tensor_type): - inputs_has_MomemtumTensor = True + inputs_has_MomentumTensor = True else: attrs_has_momentum = True @@ -2848,7 +2848,7 @@ def batch_norm( 'use_global_stats', use_global_stats, ) - if inputs_has_MomemtumTensor: + if inputs_has_MomentumTensor: batch_norm_out, _, _, _, _, _ = paddle._legacy_C_ops.batch_norm( input, scale, @@ -3426,7 +3426,7 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None): Input(Weight) is the weight of conv layer, default 0. power_iters(int): number of power iterations to calculate spectral norm, default 1. eps(float): epsilon for numerical stability in calculating norms, it will be added to - the denominator to aviod divide zero. Default 1e-12. + the denominator to avoid divide zero. Default 1e-12. name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default. @@ -3880,7 +3880,7 @@ def sparse_embedding( If :math:`padding\_idx < 0`, the :math:`padding\_idx` will automatically be converted to :math:`vocab\_size + padding\_idx` . It will output all-zero padding data whenever lookup encounters :math:`padding\_idx` in id. And the padding data will not be updated - while training. If set None, it makes no efe mfect to output. Default: None. + while training. If set None, it makes no effect to output. Default: None. is_test(bool, optional): Training or prediction mode. In prediction mode (is_test=False), the output is not initialized and created, and it is filled with 0 and returned. Default: False. entry(str, optional): Entry config with parameter server whose value is ProbabilityEntry, diff --git a/python/paddle/static/nn/control_flow.py b/python/paddle/static/nn/control_flow.py index 7f6f607e0ed4e..2e3a4f3de69dd 100644 --- a/python/paddle/static/nn/control_flow.py +++ b/python/paddle/static/nn/control_flow.py @@ -283,7 +283,7 @@ def append_conditional_block_grad( `conditional_block_grad` is appended manually. Args: - parent_block (Block): The block that `conditional_block_op` blongs to. + parent_block (Block): The block that `conditional_block_op` belongs to. inside_block (Block): The sub block of `conditional_block_op`. conditional_block_op (Operator): The forward op conditional_block. ''' @@ -397,7 +397,7 @@ def is_ignore_vars(op, var_name): # Step1: update inner_inputs and inner_outputs # NOTE: Here assumes that all variables are input or output of Ops, - # but some variables are created without appendding a real op. + # but some variables are created without appending a real op. # For example, in `arr = create_array(dtype)`, `arr` is not a output of a op. for op in current_block.ops: assert isinstance(op, Operator) @@ -614,7 +614,7 @@ def has_shape_diff(x_var, y_var): and has_shape_diff(input, output) ): warnings.warn( - "In dy2static mode, we attemp to assign a variable with shape {} into a variable with shape{}, which is not always right.".format( + "In dy2static mode, we attempt to assign a variable with shape {} into a variable with shape{}, which is not always right.".format( input.shape, output.shape ) ) @@ -1123,7 +1123,7 @@ def cond(pred, true_fn=None, false_fn=None, name=None, return_names=None): ``None`` in this case. ``true_fn`` and ``false_fn`` should return same nest structure of tensors - or both return ``None`` if user doens't like to return anything. A nest + or both return ``None`` if user doesn't like to return anything. A nest structure of tensors in PaddlePaddle is tensor(s), or tuple of tensors, or list of tensors. @@ -1319,13 +1319,13 @@ def cond(pred, true_fn=None, false_fn=None, name=None, return_names=None): # Merge true and false output if they are not None if return_names is None: - is_dy2staic = False + is_dy2static = False return_names = ["no name"] * len(_to_sequence_except_dict(true_output)) else: """ dy2static will set the return_names and expand the return values to UndefinedVar. """ - is_dy2staic = True + is_dy2static = True # TODO: expand_undefined_var will replace None to Undefinedvar(), to fix cases like: # a = None @@ -1371,7 +1371,7 @@ def check_ret_none(seq_true, seq_false, seq_names): and f_true[idx] is not None ): warnings.warn( - "In cond : Var '{}' or part of it is set differently in ifelse branchs, " + "In cond : Var '{}' or part of it is set differently in ifelse branches, " "<{}, {}> in true branch and <{}, {}> in false branch. Set var to " "'None' in ifelse block might lead to error.".format( f_name, @@ -1388,7 +1388,7 @@ def check_ret_none(seq_true, seq_false, seq_names): _to_sequence_except_dict(return_names), ) - if is_dy2staic: + if is_dy2static: true_output, false_output = change_none_to_undefinedvar( true_output, false_output ) @@ -1542,7 +1542,7 @@ def start_select_input(): return select_input(inputs, mask) except Exception as e: raise RuntimeError( - f"Exceptions throwed while doing select_input on {name}:\n{e}" + f"Exceptions thrown while doing select_input on {name}:\n{e}" ) if isinstance(false_var, UndefinedVar) and isinstance( @@ -1640,7 +1640,7 @@ def map_fn(n1, n2, name, order): if n1 is None and n2 is not None: if order == 0: warnings.warn( - "In cond : Var '{}' or part of it is set differently in ifelse branchs, " + "In cond : Var '{}' or part of it is set differently in ifelse branches, " "<{}, {}> in true branch and <{}, {}> in false branch. Set var to " "'None' in ifelse block might lead to error.".format( name, type(n1), n1, type(n2), n2 @@ -1648,7 +1648,7 @@ def map_fn(n1, n2, name, order): ) else: warnings.warn( - "In cond : Var '{}' or part of it is set differently in ifelse branchs, " + "In cond : Var '{}' or part of it is set differently in ifelse branches, " "<{}, {}> in true branch and <{}, {}> in false branch. Set var to " "'None' in ifelse block might lead to error.".format( name, type(n2), n2, type(n1), n1 @@ -1726,7 +1726,7 @@ def Print( summarize (int, optional): Number of elements in the tensor to be print. If it's value is -1, then all elements in the tensor will be print. print_tensor_name (bool, optional): Print the tensor name. Default: True. - print_tensor_type (bool, optional): Print the tensor type. Defaultt: True. + print_tensor_type (bool, optional): Print the tensor type. Default: True. print_tensor_shape (bool, optional): Print the tensor shape. Default: True. print_tensor_layout (bool, optional): Print the tensor layout. Default: True. print_tensor_lod (bool, optional): Print the tensor lod. Default: True. diff --git a/python/paddle/static/quantization/cal_kl_threshold.py b/python/paddle/static/quantization/cal_kl_threshold.py index c8101a892cfde..bf788d3070ea7 100644 --- a/python/paddle/static/quantization/cal_kl_threshold.py +++ b/python/paddle/static/quantization/cal_kl_threshold.py @@ -80,7 +80,7 @@ def safe_entropy(reference_distr_P, P_sum, candidate_distr_Q, Q_sum): def cal_kl_threshold(hist, bin_width, bits): ''' - Using the KL-divergenc method to get the more precise threshold. + Using the KL-divergence method to get the more precise threshold. Args: hist(List): The hist of the tensor. diff --git a/python/paddle/static/quantization/post_training_quantization.py b/python/paddle/static/quantization/post_training_quantization.py index 9fa7188b05572..04b94655a4d83 100644 --- a/python/paddle/static/quantization/post_training_quantization.py +++ b/python/paddle/static/quantization/post_training_quantization.py @@ -112,7 +112,7 @@ def _apply_pass( class PostTrainingQuantization: """ - Utilizing post training quantization methon to quantize the FP32 model, + Utilizing post training quantization method to quantize the FP32 model, and it uses calibrate data to get the quantization information for all quantized variables. """ @@ -168,14 +168,14 @@ def __init__( When all parameters were saved in a single binary file, set it as the real filename. If parameters were saved in separate files, set it as 'None'. Default is 'None'. - batch_generator(Python Generator, depreceated): The batch generator provides + batch_generator(Python Generator, deprecated): The batch generator provides calibrate data for DataLoader, and it returns a batch every time. Note that, sample_generator and batch_generator, only one - should be set. Beisdes, batch_generator supports lod tensor. - sample_generator(Python Generator, depreceated): The sample generator provides + should be set. Besides, batch_generator supports lod tensor. + sample_generator(Python Generator, deprecated): The sample generator provides calibrate data for DataLoader, and it only returns a sample every time. Note that, sample_generator and batch_generator, only one - should be set. Beisdes, sample_generator dose not support lod tensor. + should be set. Besides, sample_generator dose not support lod tensor. data_loader(Paddle.io.DataLoader): The Dataloader provides calibrate data, and it could return a batch every time. @@ -183,7 +183,7 @@ def __init__( batch_nums(int, optional): If batch_nums is not None, the number of calibrate data is batch_size*batch_nums. If batch_nums is None, use all data provided by sample_generator as calibrate data. - algo(str, optional): If algo='KL', use KL-divergenc method to + algo(str, optional): If algo='KL', use KL-divergence method to get the KL threshold for quantized activations and get the abs_max value for quantized weights. If algo='abs_max', get the abs max value for activations and weights. If algo= 'min_max', get the min @@ -327,7 +327,7 @@ def __init__( ) assert ( weight_quantize_type in self._support_weight_quantize_type - ), "The weight_quantize_type ({}) shoud in ({}).".format( + ), "The weight_quantize_type ({}) should in ({}).".format( weight_quantize_type, self._support_weight_quantize_type ) @@ -500,7 +500,7 @@ def quantize(self): self._reset_activation_persistable() if self._algo == 'min_max': - self._save_input_threhold() + self._save_input_threshold() else: self._update_program() @@ -1055,7 +1055,7 @@ def _sample_ptf(self): threshold = q_max * scale self._quantized_threshold[var_name] = threshold - def _save_input_threhold(self): + def _save_input_threshold(self): ''' Save input threshold to the quantized op. ''' @@ -1570,7 +1570,7 @@ class WeightQuantization: def __init__(self, model_dir, model_filename=None, params_filename=None): ''' This class quantizes the weight of some ops to reduce the size of model - or improve the perforemace. + or improve the performance. Args: model_dir(str): The path of the fp32 model that will be quantized, @@ -1625,7 +1625,7 @@ def quantize_weight_to_int( as True, it saves a fake quantized model, in which the weights are quantized and dequantized. We can use PaddlePaddle to load the fake quantized model and test the accuracy on GPU or CPU. - threshold_rate(float, optional): This api uses abs_max methd to + threshold_rate(float, optional): This api uses abs_max method to quantize the weight from float32 to int8/16, and the abs max value is important for quantization diff. When the abs_max value is far away from the center of the numerical distribution, diff --git a/python/paddle/static/quantization/quanter.py b/python/paddle/static/quantization/quanter.py index 7a71b05c6c189..86696fe82247f 100644 --- a/python/paddle/static/quantization/quanter.py +++ b/python/paddle/static/quantization/quanter.py @@ -97,13 +97,13 @@ 'quantize_op_types': ['conv2d', 'depthwise_conv2d', 'mul'], # data type after quantization, such as 'uint8', 'int8', etc. default is 'int8' 'dtype': 'int8', - # window size for 'range_abs_max' quantization. defaulf is 10000 + # window size for 'range_abs_max' quantization. default is 10000 'window_size': 10000, # The decay coefficient of moving average, default is 0.9 'moving_rate': 0.9, # if True, 'quantize_op_types' will be TENSORRT_OP_TYPES 'for_tensorrt': False, - # if True, 'quantoze_op_types' will be TRANSFORM_PASS_OP_TYPES + QUANT_DEQUANT_PASS_OP_TYPES + # if True, 'quantize_op_types' will be TRANSFORM_PASS_OP_TYPES + QUANT_DEQUANT_PASS_OP_TYPES 'is_full_quantize': False, # if True, use onnx format to quant. 'onnx_format': True, @@ -276,7 +276,7 @@ def quant_aware( is non-quantized activation and function returns processed activation to be quantized. If None, the activation will be quantized directly. Default is None. - optimizer_func(function): Fuction return a optimizer. When 'is_test' is False and user want to use self-defined + optimizer_func(function): Function return a optimizer. When 'is_test' is False and user want to use self-defined quantization function and preprocess function, this function must be set. Default is None. exe(paddle.static.Executor): If user want to use self-defined quantization function and preprocess function, exe must be set for initialization. Default is None. diff --git a/python/paddle/static/quantization/quantization_pass.py b/python/paddle/static/quantization/quantization_pass.py index 453637b36aeb2..efd158d92f3cc 100644 --- a/python/paddle/static/quantization/quantization_pass.py +++ b/python/paddle/static/quantization/quantization_pass.py @@ -300,10 +300,10 @@ def _transform_forward(graph, op): # if var node is weight and weight_preprocess_func is not None, # will insert weight preprocess func - # to preorocess weight before quantization + # to preprocess weight before quantization # if var node is activation and act_preprocess_func is not None, # will insert activation preprocess func - # to preorocess activation before quantization + # to preprocess activation before quantization if is_weight and self._weight_preprocess_func is not None: var_node = self._insert_func( graph, self._weight_preprocess_func, var_node, op @@ -2550,10 +2550,10 @@ def _transform_forward(self, graph, op): # if var node is weight and weight_preprocess_func is not None, # will insert weight preprocess func - # to preorocess weight before quantization + # to preprocess weight before quantization # if var node is activation and act_preprocess_func is not None, # will insert activation preprocess func - # to preorocess activation before quantization + # to preprocess activation before quantization if is_weight and self._weight_preprocess_func is not None: var_node = self._insert_func( graph, self._weight_preprocess_func, var_node, op @@ -2762,7 +2762,7 @@ def apply(self, graph): ): self.persistable_cast_output_vars.append(op.outputs[0].name()) - # Do the preproccess of quantization, such as skipping some ops + # Do the preprocess of quantization, such as skipping some ops # for not being quantized. for op in ops: if ( @@ -3364,7 +3364,7 @@ def apply(self, graph): dequantized_vars_map[var_name] = dequant_var_node dequant_node_map[var_name] = dequant_var_node - # remove unuse node and link act quant/dequant linear to op node + # remove unused node and link act quant/dequant linear to op node for op_node in graph.all_op_nodes(): if op_node.name() == 'moving_average_abs_max_scale': graph.safe_remove_nodes(op_node) diff --git a/python/paddle/tensor/array.py b/python/paddle/tensor/array.py index b5cc0912650bc..f5c9851074968 100644 --- a/python/paddle/tensor/array.py +++ b/python/paddle/tensor/array.py @@ -60,7 +60,7 @@ def array_length(array): or not array.is_dense_tensor_array_type() ): raise TypeError( - "array should be tensor array vairable in array_length Op" + "array should be tensor array variable in array_length Op" ) return paddle._pir_ops.array_length(array) else: @@ -69,7 +69,7 @@ def array_length(array): or array.type != core.VarDesc.VarType.LOD_TENSOR_ARRAY ): raise TypeError( - "array should be tensor array vairable in array_length Op" + "array should be tensor array variable in array_length Op" ) helper = LayerHelper('array_length', **locals()) @@ -141,7 +141,7 @@ def array_read(array, i): or not array.is_dense_tensor_array_type() ): raise TypeError( - "array should be tensor array vairable in array_length Op" + "array should be tensor array variable in array_length Op" ) return paddle._pir_ops.array_read(array, i) else: @@ -151,7 +151,7 @@ def array_read(array, i): not isinstance(array, Variable) or array.type != core.VarDesc.VarType.LOD_TENSOR_ARRAY ): - raise TypeError("array should be tensor array vairable") + raise TypeError("array should be tensor array variable") out = helper.create_variable_for_type_inference(dtype=array.dtype) helper.append_op( type='read_from_array', @@ -220,13 +220,13 @@ def array_write(x, i, array=None): elif in_pir_mode(): check_variable_and_dtype(i, 'i', ['int64'], 'array_write') if not isinstance(x, paddle.pir.Value): - raise TypeError(f"x should be pir.Value, but recevied {type(x)}.") + raise TypeError(f"x should be pir.Value, but received {type(x)}.") if array is not None: if ( not isinstance(array, paddle.pir.Value) or not array.is_dense_tensor_array_type() ): - raise TypeError("array should be tensor array vairable") + raise TypeError("array should be tensor array variable") if array is None: array = paddle._pir_ops.create_array(x.dtype) @@ -242,7 +242,7 @@ def array_write(x, i, array=None): or array.type != core.VarDesc.VarType.LOD_TENSOR_ARRAY ): raise TypeError( - "array should be tensor array vairable in array_write Op" + "array should be tensor array variable in array_write Op" ) if array is None: array = helper.create_variable( @@ -302,7 +302,7 @@ def create_array(dtype, initialized_list=None): for val in array: if not isinstance(val, (Variable, paddle.pir.Value)): raise TypeError( - "All values in `initialized_list` should be Variable or pir.Value, but recevied {}.".format( + "All values in `initialized_list` should be Variable or pir.Value, but received {}.".format( type(val) ) )