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

如何 把VarBase 转换为LodTensor #32765

Closed
zzz2010 opened this issue May 7, 2021 · 8 comments
Closed

如何 把VarBase 转换为LodTensor #32765

zzz2010 opened this issue May 7, 2021 · 8 comments
Assignees

Comments

@zzz2010
Copy link

zzz2010 commented May 7, 2021

你好, 我想直接在GPU上把VarBase转换为LodTensor,而不是先转cpu numpy 再create_lod_tensor. 请问有方法吗? 谢谢

@paddle-bot-old
Copy link

paddle-bot-old bot commented May 7, 2021

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@danleifeng
Copy link
Contributor

您好,可以试试这种方法,得到的是一个lodtensor
a.value().get_tensor()

@zzz2010
Copy link
Author

zzz2010 commented May 7, 2021

@danleifeng 谢谢。 想追加一个问题, 如何 把 paddle.fluid.core_avx.Tensor 转回Varbase?
我用fluid.core.from_dlpack(dlpack) 得到 paddle.fluid.core_avx.Tensor ,希望变回Varbase

@danleifeng
Copy link
Contributor

可以使用paddle.to_variable(a)接口

@zzz2010
Copy link
Author

zzz2010 commented May 8, 2021

可以使用paddle.to_variable(a)接口

@danleifeng 我尝试了 fluid.dygraph.to_variable() , 和paddle.to_tensor() 都不支持paddle.fluid.core_avx.Tensor

测试代码

import paddle
tensor=paddle.randn((3,4))
dlpack=tensor.value().get_tensor()._to_dlpack()
tensor_from_dlpack = paddle.fluid.core.from_dlpack(dlpack)
paddle.fluid.dygraph.to_variable(tensor_from_dlpack)

错误:


TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
   1. paddle.fluid.core_avx.VarBase()
   2. paddle.fluid.core_avx.VarBase(arg0: paddle::framework::proto::VarType_Type, arg1: List[int], arg2: handle, arg3: paddle::framework::proto::VarType_Type, arg4: bool)
   3. paddle.fluid.core_avx.VarBase(value: array, place: paddle::platform::CPUPlace, persistable: bool = False, zero_copy: bool = False, name: str = '', stop_gradient: int = -1)
   4. paddle.fluid.core_avx.VarBase(value: array, place: paddle::platform::XPUPlace, persistable: bool = False, zero_copy: bool = False, name: str = '', stop_gradient: int = -1)
   5. paddle.fluid.core_avx.VarBase(value: array, place: paddle::platform::CUDAPlace, persistable: bool = False, zero_copy: bool = False, name: str = '', stop_gradient: int = -1)
   6. paddle.fluid.core_avx.VarBase(value: array, place: paddle::platform::CUDAPinnedPlace, persistable: bool = False, zero_copy: bool = False, name: str = '', stop_gradient: int = -1)
   7. paddle.fluid.core_avx.VarBase(value: array)
   8. paddle.fluid.core_avx.VarBase(tensor: paddle::framework::LoDTensor)
   9. paddle.fluid.core_avx.VarBase(**kwargs)
Invoked with: <paddle.fluid.core_avx.Tensor object at 0x000001FA6AD11CB0>

@zhwesky2010
Copy link
Contributor

zhwesky2010 commented May 10, 2021

@zzz2010 构造这里有个问题,不支持core.Tensor,只支持core.LoDTensor,后面我们修复一下

@zhwesky2010
Copy link
Contributor

@zzz2010 构造这里有个问题,不支持core.Tensor,只支持core.LoDTensor,后面我们修复一下

#33430 修复了这个问题

@paddle-bot-old
Copy link

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

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

No branches or pull requests

3 participants