-
Notifications
You must be signed in to change notification settings - Fork 762
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
【Hackathon 5th No.15】 为 Paddle 新增 Tensor.to() 以及 Layer.astype() API #6305
Conversation
docs/api/paddle/Tensor_cn.rst
Outdated
.. code-block:: python | ||
import paddle | ||
tensorx = paddle.to_tensor([1,2,3]) | ||
print(tensorx) | ||
# Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True, | ||
# [1, 2, 3]) | ||
|
||
tensorx = tensorx.to("cpu") | ||
print(tensorx.place) | ||
# Place(cpu) | ||
|
||
tensorx = tensorx.to("float32") | ||
print(tensorx.dtype) | ||
# paddle.float32 | ||
|
||
tensorx = tensorx.to("gpu", "int16") | ||
print(tensorx) | ||
# Tensor(shape=[3], dtype=int16, place=Place(gpu:0), stop_gradient=True, | ||
# [1, 2, 3]) | ||
|
||
tensor2 = paddle.to_tensor([4,5,6]) | ||
print(tensor2) | ||
# Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True, | ||
# [4, 5, 6]) | ||
tensor2 = tensor2.to(tensorx) | ||
print(tensor2) | ||
# Tensor(shape=[3], dtype=int16, place=Place(gpu:0), stop_gradient=True, | ||
# [4, 5, 6]) |
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.
代码示例请用 copy-from 的形式
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
Co-authored-by: zachary sun <70642955+sunzhongkai588@users.noreply.github.com>
Co-authored-by: zachary sun <70642955+sunzhongkai588@users.noreply.github.com>
Co-authored-by: zachary sun <70642955+sunzhongkai588@users.noreply.github.com>
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.
其他没啥问题
Co-authored-by: zachary sun <70642955+sunzhongkai588@users.noreply.github.com>
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
PaddlePaddle/Paddle#58244