Skip to content

Conversation

@pangyoki
Copy link
Contributor

@pangyoki pangyoki commented Apr 26, 2021

PR types

New features

PR changes

APIs

Describe

Inplace Strategy has been implemented in PR #30103 .
Add 12 Inplace APIs in this PR.

NOTICE

The newly added inplace APIs in this PR will not be used publicly. They can only be called in the form of Tensor.api_, but CANNOT be called in the form of paddle.api_.

  • There is no corresponding Tensor.api method for activation op, such as relu, hard_sigmoid, leaky_relu, sigmoid and , so its inplace method will not be added temporarily.
  • The input of add_n API is a Tensor list, and it is not convenient to use Tensor.api to call, so its inplace method will not be added temporarily.

Processed API Lists in this PR

Inplace OP paddle下API
clip paddle.tensor.math.clip
scale paddle.tensor.math.scale
elementwise_sub paddle.tensor.math.subtract
elementwise_add paddle.tensor.math.add

Add 8 Inplace APIs that are auto generated.

Inplace OP paddle下API
ceil paddle.tensor.math.ceil
floor paddle.tensor.math.floor
exp paddle.tensor.math.exp
reciprocal paddle.tensor.math.reciprocal
round paddle.tensor.math.round
sqrt paddle.tensor.math.sqrt
rsqrt paddle.tensor.math.rsqrt

PS: square grad op needs to use the input var, so the corresponding Inplace API square_ hasn't been added.

Fix flatten_contiguous_range op kernel, and add flatten_ Inplace API.

Inplace OP paddle下API
flatten_contiguous_range paddle.tensor.manipulation.flatten

17 Inplace APIs in Tensor method

Tensor.reshape_
Tensor.squeeze_
Tensor.unsqueeze_
Tensor.scatter_
Tensor.tanh_
Tensor.clip_
Tensor.scale_
Tensor.add_
Tensor.subtract_
Tensor.ceil_
Tensor.floor_
Tensor.exp_
Tensor.reciprocal_
Tensor.round_
Tensor.sqrt_
Tensor.rsqrt_
Tensor.flatten_

example to use Inplace APIs

import paddle

a = paddle.rand([2,3])
# [[0.45528218, 0.92556411, 0.90491837],
#   [0.31372914, 0.01990727, 0.94381261]]

b = paddle.ones([2,3])
# [[1., 1., 1.],
# [1., 1., 1.]]

a.add_(b)
print(a)
# [[1.45528221, 1.92556405, 1.90491843],
#  [1.31372917, 1.01990724, 1.94381261]]

paddle.add_(a,b)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# AttributeError: module 'paddle' has no attribute 'add_'

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

zhiqiu
zhiqiu previously approved these changes Apr 29, 2021
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

lanxianghit
lanxianghit previously approved these changes Apr 29, 2021
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

LGTM for tools/wlist.json now, but we do have plan to gradually cleanup this white list.



@inplace_apis_in_dygraph_only
def softmax_with_cross_entropy_(logits,
Copy link
Contributor

Choose a reason for hiding this comment

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

softmax_with_cross_entropy API 已经被标记为deprecated了,所以这个inplace版本应该是也不需要了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经删除了inplace版本的softmax_with_cross_entropy_,谢谢

@pangyoki pangyoki dismissed stale reviews from lanxianghit and zhiqiu via 29737d4 April 29, 2021 09:37
@pangyoki pangyoki changed the title Add 18 inplace APIs including auto generated Add 17 inplace APIs including auto generated Apr 29, 2021
@pangyoki pangyoki changed the title Add 17 inplace APIs including auto generated Add 12 inplace APIs including auto generated Apr 29, 2021
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

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 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

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

LGTM

@pangyoki pangyoki merged commit 308073d into PaddlePaddle:develop Apr 30, 2021
pangyoki added a commit to pangyoki/Paddle that referenced this pull request Apr 30, 2021
* add relu6_ hardsigmoid_ leaky_relu_ Inplace APIs

* add softmax_with_cross_entropy_ Inplace API

* add clip_ scale_ add_ subtract_ Inplace APIs

* add wlist

* fix parameter of scale api

* add add_n_ Inplace API and remove log_ Inplace API

* fix elementwise_add_ and elementwise_sub_ broadcast problem

* elementwise inplace api give error message before run the op

* use broadcast_shape in elementwise inplace op

* add 8 inplace apis that is auto generated

* add unittest for all inplace apis

* add decorator for inplace apis in static mode

* fix windows blas fail of exp inplace api, change array_equal to allclose

* add flatten inplace api

* add flatten unittest

* fix flatten unittest

* add decorator

* fix grad.numpy in test_pylayer_op

* unsupport softmax_with_cross_entropy_

* add test_inplace_softmax_with_cross_entropy to static_mode_white_list

* delete __all__ in inplace_utils

* delete activation inplace function and add Tensor.inplace_func

* change paddle.inplace_ to Tensor.inplace_

* fix little problem

* add paddle in inplace_utils
lanxianghit pushed a commit that referenced this pull request Apr 30, 2021
* add relu6_ hardsigmoid_ leaky_relu_ Inplace APIs

* add softmax_with_cross_entropy_ Inplace API

* add clip_ scale_ add_ subtract_ Inplace APIs

* add wlist

* fix parameter of scale api

* add add_n_ Inplace API and remove log_ Inplace API

* fix elementwise_add_ and elementwise_sub_ broadcast problem

* elementwise inplace api give error message before run the op

* use broadcast_shape in elementwise inplace op

* add 8 inplace apis that is auto generated

* add unittest for all inplace apis

* add decorator for inplace apis in static mode

* fix windows blas fail of exp inplace api, change array_equal to allclose

* add flatten inplace api

* add flatten unittest

* fix flatten unittest

* add decorator

* fix grad.numpy in test_pylayer_op

* unsupport softmax_with_cross_entropy_

* add test_inplace_softmax_with_cross_entropy to static_mode_white_list

* delete __all__ in inplace_utils

* delete activation inplace function and add Tensor.inplace_func

* change paddle.inplace_ to Tensor.inplace_

* fix little problem

* add paddle in inplace_utils
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.

5 participants