-
Notifications
You must be signed in to change notification settings - Fork 5.9k
add new API: paddle.clone;Tensor.element_size;nn.utils.parameters_to_vector #38020
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
add new API: paddle.clone;Tensor.element_size;nn.utils.parameters_to_vector #38020
Conversation
|
Thanks for your contribution! |
89a8d71 to
4b3da4f
Compare
4b3da4f to
e4ce605
Compare
b7109a2 to
e813185
Compare
26dd7d9 to
0a9e5c5
Compare
0a9e5c5 to
b0d8d43
Compare
b0d8d43 to
0d99a96
Compare
0d99a96 to
572fcf6
Compare
python/paddle/tensor/creation.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两句描述不够清楚,可以在改一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
572fcf6 to
cd894ae
Compare
cd894ae to
7582067
Compare
0d28fde to
92be1b7
Compare
python/paddle/tensor/creation.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tn addition -> In addition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thx
92be1b7 to
0d56823
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| shape = param.shape | ||
| numel = reduce(lambda x, y: x * y, shape) | ||
| end = start + numel | ||
| slice_data = _C_ops.slice(vec, None, None, 'axes', [0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能否用1个split代替多个slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done,已去掉多个slice
| slice_data = _C_ops.slice(vec, None, None, 'axes', [0], | ||
| 'infer_flags', [1], 'starts', | ||
| [start], 'ends', [end]) | ||
| _C_ops.reshape2_(slice_data, None, 'shape', shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么这里需要显式使用inplace接口呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| helper.append_op( | ||
| type='assign', | ||
| inputs={'X': slice_data}, | ||
| outputs={'Out': param}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector_to_parameters可能会比较慢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已去掉assign,改成最简化的写法:
parameters_to_vector:使用1个concat OP + 完全inplace的reshape_ OP
vector_to_parameters:使用1个split OP + 完全inplace的reshape_ OP
目前全部使用inplace版的reshape_ OP,每个API实质上只有1个concat或split OP的耗时,性能可以得到保证了
d6c6d00 to
593f113
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for CMakeLists.txt

PR types
New features
PR changes
APIs
Describe
1.New API:
paddle.cloneReturns a copy of input Tensor. It will always have a Tensor copy.
Tn addition, the OP provides gradient propagation.
2.New API:
paddle.Tensor.element_sizeReturns the size in bytes of an element in the Tensor.
3.New API:
paddle.nn.utils.parameters_to_vectorFlatten parameters to a 1-D Tensor.
4.New API:
paddle.nn.utils.vector_to_parametersTransform a Tensor with 1-D shape to the parameters.