Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Eager]patch tensor method func #38761

Merged

Conversation

wanghuancoder
Copy link
Contributor

@wanghuancoder wanghuancoder commented Jan 6, 2022

PR types

Bug fixes

PR changes

Others

Describe

monkey_patch_math_varbase函数需要调用两次才能将所有的method patch到Tensor上。修改这个bug。
目前,EagerTensor和VarBase拥有的method基本一致,仍存在少量diff:
目前,dir(core.eager.EagerTensor())的数据如下:
['T', 'add', 'and', 'array', 'array_ufunc', 'bool', 'class', 'deepcopy', 'delattr', 'dir', 'div', 'doc', 'eq', 'float', 'floordiv', 'format', 'ge', 'getattribute', 'getitem', 'gt', 'hash', 'index', 'init', 'init_subclass', 'int', 'invert', 'le', 'len', 'long', 'lt', 'matmul', 'mod', 'module', 'mul', 'ne', 'neg', 'new', 'nonzero', 'or', 'pow', 'radd', 'rdiv', 'reduce', 'reduce_ex', 'repr', 'rmul', 'rpow', 'rsub', 'rtruediv', 'setattr', 'setitem', 'sizeof', 'str', 'sub', 'subclasshook', 'truediv', 'xor', 'clear_gradient', 'copy_to', 'grad_ivar', 'is_initialized', 'place_str', 'to', 'to_static_var', 'zero_grads', 'abs', 'acos', 'acosh', 'add', 'add', 'add_n', 'addmm', 'all', 'allclose', 'amax', 'amin', 'angle', 'any', 'argmax', 'argmin', 'argsort', 'as_complex', 'as_real', 'asin', 'asinh', 'astype', 'atan', 'atanh', 'backward', 'bincount', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'block', 'bmm', 'broadcast_shape', 'broadcast_tensors', 'broadcast_to', 'cast', 'ceil', 'ceil', 'cholesky', 'cholesky_solve', 'chunk', 'clear_grad', 'clear_gradient', 'clip', 'clip', 'concat', 'cond', 'conj', 'copy', 'cos', 'cosh', 'cov', 'cross', 'cumprod', 'cumsum', 'deg2rad', 'diagonal', 'diff', 'digamma', 'dim', 'dist', 'divide', 'dot', 'dtype', 'eig', 'eigvals', 'eigvalsh', 'equal', 'equal_all', 'erf', 'erfinv', 'erfinv', 'exp', 'exp', 'expand', 'expand_as', 'exponential', 'flatten', 'flatten', 'flip', 'floor', 'floor_', 'floor_divide', 'floor_mod', 'fmax', 'fmin', 'gather', 'gather_nd', 'gcd', 'grad', 'gradient', 'greater_equal', 'greater_than', 'histogram', 'imag', 'increment', 'index_sample', 'index_select', 'inner', 'inplace_version', 'inverse', 'is_complex', 'is_empty', 'is_floating_point', 'is_integer', 'is_tensor', 'isclose', 'isfinite', 'isinf', 'isnan', 'item', 'kron', 'kthvalue', 'lcm', 'lerp', 'lerp_', 'less_equal', 'less_than', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logit', 'logsumexp', 'lstsq', 'lu', 'lu_unpack', 'masked_select', 'matmul', 'matrix_power', 'max', 'maximum', 'mean', 'median', 'min', 'minimum', 'mm', 'mod', 'mode', 'moveaxis', 'multi_dot', 'multiplex', 'multiply', 'mv', 'name', 'nansum', 'ndim', 'ndimension', 'neg', 'nonzero', 'norm', 'not_equal', 'numel', 'numpy', 'outer', 'persistable', 'place', 'pow', 'prod', 'put_along_axis', 'put_along_axis_', 'qr', 'quantile', 'rad2deg', 'rank', 'real', 'reciprocal', 'reciprocal_', 'register_hook', 'remainder', 'repeat_interleave', 'reshape', 'reshape_', 'retain_grads', 'reverse', 'roll', 'rot90', 'round', 'round_', 'rsqrt', 'rsqrt_', 'scale', 'scale_', 'scatter', 'scatter_', 'scatter_nd', 'scatter_nd_add', 'set_value', 'shape', 'shard_index', 'sign', 'sin', 'sinh', 'size', 'slice', 'solve', 'sort', 'split', 'sqrt', 'sqrt_', 'square', 'squeeze', 'squeeze_', 'stack', 'stanh', 'std', 'stop_gradient', 'strided_slice', 'subtract', 'subtract_', 'sum', 't', 'take_along_axis', 'tanh', 'tanh_', 'tensordot', 'tile', 'topk', 'trace', 'transpose', 'trunc', 'unbind', 'uniform_', 'unique', 'unique_consecutive', 'unsqueeze', 'unsqueeze_', 'unstack', 'var', 'where']

dir(core.VarBase())的数据如下:
['T', 'add', 'and', 'array', 'array_ufunc', 'bool', 'class', 'deepcopy', 'delattr', 'dir', 'div', 'doc', 'eq', 'float', 'floordiv', 'format', 'ge', 'getattribute', 'getitem', 'gt', 'hash', 'index', 'init', 'init_subclass', 'int', 'invert', 'le', 'len', 'long', 'lt', 'matmul', 'mod', 'module', 'mul', 'ne', 'neg', 'new', 'nonzero', 'or', 'pow', 'radd', 'rdiv', 'reduce', 'reduce_ex', 'repr', 'rmul', 'rpow', 'rsub', 'rtruediv', 'setattr', 'setitem', 'setitem_varbase', 'sizeof', 'str', 'sub', 'subclasshook', 'truediv', 'xor', '_alive_vars', '_allreduce', '_bump_inplace_version', '_clear', 'copy_gradient_from', 'copy_to', 'getitem_from_offset', 'getitem_index_not_tensor', 'grad_ivar', 'grad_name', 'grad_value', 'gradient_set_empty', 'inplace_version', 'is_gradient_set_empty', 'is_shared_buffer_with', 'is_sparse', 'numel', 'offset', 'place_str', 'register_backward_hook', 'register_grad_hook', 'register_void_function_post_hook', 'remove_grad_hook', 'reset_grad_inplace_version', 'set_grad_ivar', 'set_grad_type', 'share_buffer_to', 'share_memory', 'slice', 'to', 'to_static_var', 'abs', 'acos', 'acosh', 'add', 'add', 'add_n', 'addmm', 'all', 'allclose', 'amax', 'amin', 'angle', 'any', 'argmax', 'argmin', 'argsort', 'as_complex', 'as_real', 'asin', 'asinh', 'astype', 'atan', 'atanh', 'backward', 'bincount', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'block', 'bmm', 'broadcast_shape', 'broadcast_tensors', 'broadcast_to', 'cast', 'ceil', 'ceil', 'cholesky', 'cholesky_solve', 'chunk', 'clear_grad', 'clear_gradient', 'clip', 'clip', 'clone', 'concat', 'cond', 'conj', 'copy', 'cos', 'cosh', 'cov', 'cpu', 'cross', 'cuda', 'cumprod', 'cumsum', 'deg2rad', 'detach', 'diagonal', 'diff', 'digamma', 'dim', 'dist', 'divide', 'dot', 'dtype', 'eig', 'eigvals', 'eigvalsh', 'element_size', 'equal', 'equal_all', 'erf', 'erfinv', 'erfinv', 'exp', 'exp', 'expand', 'expand_as', 'exponential', 'fill', 'fill_diagonal', 'fill_diagonal_tensor', 'fill_diagonal_tensor', 'flatten', 'flatten', 'flip', 'floor', 'floor', 'floor_divide', 'floor_mod', 'fmax', 'fmin', 'gather', 'gather_nd', 'gcd', 'grad', 'gradient', 'greater_equal', 'greater_than', 'histogram', 'imag', 'increment', 'index_sample', 'index_select', 'inner', 'inplace_version', 'inverse', 'is_complex', 'is_empty', 'is_floating_point', 'is_integer', 'is_leaf', 'is_tensor', 'isclose', 'isfinite', 'isinf', 'isnan', 'item', 'kron', 'kthvalue', 'lcm', 'lerp', 'lerp', 'less_equal', 'less_than', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logit', 'logsumexp', 'lstsq', 'lu', 'lu_unpack', 'masked_select', 'matmul', 'matrix_power', 'max', 'maximum', 'mean', 'median', 'min', 'minimum', 'mm', 'mod', 'mode', 'moveaxis', 'multi_dot', 'multiplex', 'multiply', 'mv', 'name', 'nansum', 'ndim', 'ndimension', 'neg', 'nonzero', 'norm', 'not_equal', 'numel', 'numpy', 'outer', 'persistable', 'pin_memory', 'place', 'pow', 'prod', 'put_along_axis', 'put_along_axis', 'qr', 'quantile', 'rad2deg', 'rank', 'real', 'reciprocal', 'reciprocal', 'register_hook', 'remainder', 'repeat_interleave', 'reshape', 'reshape', 'reverse', 'roll', 'rot90', 'round', 'round', 'rsqrt', 'rsqrt', 'scale', 'scale', 'scatter', 'scatter', 'scatter_nd', 'scatter_nd_add', 'set_value', 'shape', 'shard_index', 'sign', 'sin', 'sinh', 'size', 'slice', 'solve', 'sort', 'split', 'sqrt', 'sqrt', 'square', 'squeeze', 'squeeze', 'stack', 'stanh', 'std', 'stop_gradient', 'strided_slice', 'subtract', 'subtract', 'sum', 't', 'take_along_axis', 'tanh', 'tanh', 'tensordot', 'tile', 'tolist', 'topk', 'trace', 'transpose', 'trunc', 'type', 'unbind', 'uniform', 'unique', 'unique_consecutive', 'unsqueeze', 'unsqueeze', 'unstack', 'value', 'var', 'where', 'zero']

Copy link
Contributor

@JiabinYang JiabinYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wanghuancoder wanghuancoder merged commit c8fbd3c into PaddlePaddle:develop Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants