Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
7affca7e
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7affca7e
编写于
4月 14, 2023
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(imperative): fix try_cast usage of TensorWrapper
GitOrigin-RevId: 5510bef70dafb54ed1dde49e32b87d5be834f07f
上级
986fc998
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
5 deletion
+21
-5
imperative/python/megengine/jit/tracing.py
imperative/python/megengine/jit/tracing.py
+7
-0
imperative/python/src/grad.cpp
imperative/python/src/grad.cpp
+9
-3
imperative/python/src/module_trace.h
imperative/python/src/module_trace.h
+3
-1
imperative/python/src/tensor_utils.cpp
imperative/python/src/tensor_utils.cpp
+2
-1
未找到文件。
imperative/python/megengine/jit/tracing.py
浏览文件 @
7affca7e
...
...
@@ -239,6 +239,13 @@ class trace:
}
def
_process_outputs
(
self
,
outputs
):
assert
(
isinstance
(
outputs
,
RawTensor
)
or
(
isinstance
(
outputs
,
Sequence
)
and
not
(
isinstance
(
outputs
[
0
],
Sequence
))
)
or
isinstance
(
outputs
,
collections
.
abc
.
Mapping
)
),
"Unsupport outputs type, should be Tensor, List[Tensor] or Dict[tensor_name, Tensor]"
if
isinstance
(
outputs
,
RawTensor
):
outputs
=
[
outputs
]
if
not
isinstance
(
outputs
,
Sequence
):
...
...
imperative/python/src/grad.cpp
浏览文件 @
7affca7e
...
...
@@ -51,10 +51,14 @@ void GradKeyWrapper::backward(GradKeyWrapper* self, py::list tensors, py::list g
std
::
vector
<
ValueRef
>
args
;
mgb_assert
(
tensors
.
size
()
==
grads
.
size
());
for
(
auto
&&
tensor
:
tensors
)
{
args
.
push_back
(
TensorWrapper
::
try_cast
(
tensor
.
ptr
())
->
m_tensor
->
data
());
auto
*
tw
=
TensorWrapper
::
try_cast
(
tensor
.
ptr
());
mgb_assert
(
tw
,
"expect Tensor"
);
args
.
push_back
(
tw
->
m_tensor
->
data
());
}
for
(
auto
&&
grad
:
grads
)
{
args
.
push_back
(
TensorWrapper
::
try_cast
(
grad
.
ptr
())
->
m_tensor
->
data
());
auto
*
tw
=
TensorWrapper
::
try_cast
(
grad
.
ptr
());
mgb_assert
(
tw
,
"expect Tensor"
);
args
.
push_back
(
tw
->
m_tensor
->
data
());
}
imperative
::
apply
(
GradBackward
(
self
->
m_key
),
{
args
.
data
(),
args
.
size
()});
}
...
...
@@ -63,7 +67,9 @@ pybind11::function GradKeyWrapper::get_backward_closure(
GradKeyWrapper
*
self
,
py
::
list
tensors
)
{
std
::
vector
<
ValueRef
>
args
;
for
(
auto
&&
tensor
:
tensors
)
{
args
.
push_back
(
TensorWrapper
::
try_cast
(
tensor
.
ptr
())
->
m_tensor
->
data
());
auto
*
tw
=
TensorWrapper
::
try_cast
(
tensor
.
ptr
());
mgb_assert
(
tw
,
"expect Tensor"
);
args
.
push_back
(
tw
->
m_tensor
->
data
());
}
auto
closure_value
=
imperative
::
apply
(
GetBackwardColsure
(
self
->
m_key
),
args
)[
0
];
auto
closure
=
closure_value
.
as_ref
<
FunctionValue
>
();
...
...
imperative/python/src/module_trace.h
浏览文件 @
7affca7e
...
...
@@ -24,7 +24,9 @@ private:
ValueRefList
outputs
(
output_tws
.
size
());
auto
it
=
outputs
.
begin
();
for
(
auto
&&
output_tw
:
output_tws
)
{
*
(
it
++
)
=
TensorWrapper
::
try_cast
(
output_tw
.
ptr
())
->
m_tensor
->
data
();
auto
*
tw
=
TensorWrapper
::
try_cast
(
output_tw
.
ptr
());
mgb_assert
(
tw
,
"expect Tensor"
);
*
(
it
++
)
=
tw
->
m_tensor
->
data
();
}
return
outputs
;
}
...
...
imperative/python/src/tensor_utils.cpp
浏览文件 @
7affca7e
...
...
@@ -418,7 +418,8 @@ py::object get_res_by_refhdl(
}
mgb
::
DType
_get_dtype
(
py
::
handle
tensor
)
{
auto
tw
=
TensorWrapper
::
try_cast
(
tensor
.
ptr
());
auto
*
tw
=
TensorWrapper
::
try_cast
(
tensor
.
ptr
());
mgb_assert
(
tw
,
"expect Tensor"
);
return
tw
->
m_tensor
->
dtype
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录