Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
d4ada69d
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
d4ada69d
编写于
1月 08, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(mge): trace exception in compiled info
GitOrigin-RevId: 508f5463b9d7b0aaf601bcf8fc88a5673d6cb0e7
上级
c9c3429a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
30 addition
and
6 deletion
+30
-6
imperative/python/megengine/jit/tracing.py
imperative/python/megengine/jit/tracing.py
+7
-4
imperative/python/src/tensor.cpp
imperative/python/src/tensor.cpp
+13
-1
imperative/python/src/trace.h
imperative/python/src/trace.h
+10
-0
imperative/python/test/unit/test_tracing.py
imperative/python/test/unit/test_tracing.py
+0
-1
未找到文件。
imperative/python/megengine/jit/tracing.py
浏览文件 @
d4ada69d
...
...
@@ -414,7 +414,7 @@ class trace:
for
x
in
escaped_tensors
:
try
:
assign_raw_tensor
(
x
(),
RawTensor
(
x
().
_dev_tensor
()))
except
TraceMismatch
Error
:
except
Runtime
Error
:
# TraceMismatchError thrown in do_exit
pass
self
.
_graph
.
wait
()
...
...
@@ -954,7 +954,8 @@ class CompiledTensorProxy:
elif
self
.
__info
.
data_read
:
self
.
__shape
=
self
.
_dev_tensor
().
shape
else
:
raise
TraceMismatchError
(
"shape of this tensor is not read in trace"
)
# c++ will throw TraceReadError
return
None
return
self
.
__shape
def
numpy
(
self
):
...
...
@@ -964,7 +965,8 @@ class CompiledTensorProxy:
elif
self
.
__info
.
data_read
:
self
.
__value
=
self
.
_dev_tensor
().
numpy
()
else
:
raise
TraceMismatchError
(
"value of this tensor is not read in trace"
)
# c++ will throw TraceReadError
return
None
if
self
.
_isscalar
:
self
.
__value
=
self
.
__value
.
squeeze
()
return
self
.
__value
...
...
@@ -972,7 +974,8 @@ class CompiledTensorProxy:
def
_dev_tensor
(
self
):
if
self
.
__data
is
None
:
if
not
self
.
__info
.
data_read
:
raise
TraceMismatchError
(
"raw data of this tensor is not read in trace"
)
# c++ will throw TraceReadError
return
None
self
.
__data
=
self
.
__info
.
data_reader
.
get_value
()
return
self
.
__data
...
...
imperative/python/src/tensor.cpp
浏览文件 @
d4ada69d
...
...
@@ -316,7 +316,11 @@ PyObject* TensorWrapper::shape() {
if
(
m_tensor
->
m_flags
&
Tensor
::
Flags
::
SCALAR
)
{
return
PyTuple_New
(
0
);
}
return
PyObject_GetAttrString
(
m_tensor
->
m_trace_info
.
compiled_info
,
"shape"
);
PyObject
*
shp
=
PyObject_GetAttrString
(
m_tensor
->
m_trace_info
.
compiled_info
,
"shape"
);
if
(
shp
==
Py_None
)
{
throw
TraceReadError
(
"shape of this tensor is not read in trace"
);
}
return
shp
;
}
if
(
m_tensor
->
m_trace_info
.
recording
&&
!
skip_tracing
)
{
PyObject_SetAttrString
(
m_tensor
->
m_trace_info
.
trace_mixin_info
,
"shape_read"
,
py
::
cast
(
true
).
release
().
ptr
());
...
...
@@ -367,6 +371,9 @@ PyObject* TensorWrapper::device() {
PyObject
*
TensorWrapper
::
numpy
()
{
if
(
m_tensor
->
m_trace_info
.
compiled_info
!=
nullptr
)
{
PyObject
*
np_val
=
PyObject_CallMethod
(
m_tensor
->
m_trace_info
.
compiled_info
,
"numpy"
,
nullptr
);
if
(
np_val
==
Py_None
)
{
throw
TraceReadError
(
"value of this tensor is not read in trace"
);
}
if
(
m_tensor
->
m_flags
&
Tensor
::
Flags
::
SCALAR
)
{
np_val
=
PyArray_Squeeze
(
reinterpret_cast
<
PyArrayObject
*>
(
np_val
));
}
...
...
@@ -445,9 +452,14 @@ PyObject* TensorWrapper::detach() {
PyObject
*
TensorWrapper
::
_dev_tensor
(){
if
(
m_tensor
->
m_trace_info
.
compiled_info
!=
nullptr
)
{
auto
*
dev_tensor
=
PyObject_CallMethod
(
m_tensor
->
m_trace_info
.
compiled_info
,
"_dev_tensor"
,
nullptr
);
if
(
dev_tensor
==
Py_None
)
{
throw
TraceReadError
(
"raw data of this tensor is not read in trace"
);
}
auto
py_dev_tensor
=
py
::
reinterpret_borrow
<
py
::
object
>
(
dev_tensor
);
auto
sh
=
interpreter_for_py
->
put
(
py_dev_tensor
.
cast
<
DeviceTensorND
>
());
m_tensor
->
m_handle
=
std
::
move
(
SharedHandle
(
sh
));
return
dev_tensor
;
}
if
(
m_tensor
->
m_trace_info
.
recording
&&
!
skip_tracing
)
{
PyObject_SetAttrString
(
m_tensor
->
m_trace_info
.
trace_mixin_info
,
"data_read"
,
py
::
cast
(
true
).
release
().
ptr
());
...
...
imperative/python/src/trace.h
浏览文件 @
d4ada69d
...
...
@@ -10,9 +10,19 @@
*/
#include "./tensor.h"
#include <stdexcept>
namespace
mgb
::
imperative
::
python
{
class
TraceReadError
:
public
std
::
exception
{
public:
explicit
TraceReadError
(
const
char
*
m
)
:
message
{
m
}
{}
const
char
*
what
()
const
noexcept
override
{
return
message
.
c_str
();}
private:
std
::
string
message
=
""
;
};
apply_result_t
apply_trace
(
ApplyContext
&
ctx
);
}
// namespace mgb::imperative::python
imperative/python/test/unit/test_tracing.py
浏览文件 @
d4ada69d
...
...
@@ -311,7 +311,6 @@ def test_trace_warp_perspective():
f
(
x
,
M
)
@
pytest
.
mark
.
skip
(
reason
=
"skip"
)
def
test_raise_on_trace
():
step_count
=
0
catch_count
=
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录