Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
971716f4
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
971716f4
编写于
4年前
作者:
M
mindspore-ci-bot
提交者:
Gitee
4年前
浏览文件
操作
浏览文件
下载
差异文件
!5136 fix large for loop runtime error due to lacking of backend operators
Merge pull request !5136 from fary86/fix_large_for_runtime_error
上级
346b97ac
8d245497
master
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
3 deletion
+46
-3
mindspore/ccsrc/pipeline/jit/parse/parse.h
mindspore/ccsrc/pipeline/jit/parse/parse.h
+6
-1
tests/ut/python/ops/test_control_ops.py
tests/ut/python/ops/test_control_ops.py
+40
-2
未找到文件。
mindspore/ccsrc/pipeline/jit/parse/parse.h
浏览文件 @
971716f4
...
...
@@ -19,6 +19,7 @@
#ifndef MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_PARSE_H_
#define MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_PARSE_H_
#include <limits>
#include <vector>
#include <string>
#include <map>
...
...
@@ -50,7 +51,11 @@ enum ParseStatusCode : int {
// max loop count of for statement, when loop count is less then this value, the for loop will be unrolled, otherwise it
// will be sunk(i.e. not unrolled)
const
int
MAX_FOR_LOOP_COUNT
=
600
;
// NOTE: Since when the for loop was unrolled, it depends backend operators `tuple_getitem` and `scalar_add` which were
// not implemented, so here set MAX_FOR_LOOP_COUNT to int max limit to override default value `600`. This will make
// the for loop will always be unrolled, but don't worry about the memory were exhausted, an exception will be raised
// when function call depth execeeds the limit `context.get_context('max_call_depth')`.
const
int
MAX_FOR_LOOP_COUNT
=
std
::
numeric_limits
<
int
>::
max
();
class
AstNodeType
;
class
ParseAst
;
...
...
This diff is collapsed.
Click to expand it.
tests/ut/python/ops/test_control_ops.py
浏览文件 @
971716f4
...
...
@@ -773,13 +773,18 @@ def test_large_for_loop():
self
.
flatten
=
P
.
ReLU
()
#nn.Flatten()
def
construct
(
self
,
x
):
for
elem
in
range
(
1
,
1900
0
):
for
elem
in
range
(
1
,
1900
):
x
=
self
.
flatten
(
x
+
elem
)
return
x
t
=
Tensor
(
np
.
ones
([
2
,
3
],
dtype
=
np
.
float32
))
net
=
Net
()
net
(
t
)
old_max_call_depth
=
context
.
get_context
(
'max_call_depth'
)
context
.
set_context
(
max_call_depth
=
60
)
with
pytest
.
raises
(
RuntimeError
)
as
err
:
net
(
t
)
context
.
set_context
(
max_call_depth
=
old_max_call_depth
)
assert
'Exceed function call depth limit 60'
in
str
(
err
.
value
)
def
test_large_for_loop_with_continue_break
():
...
...
@@ -986,3 +991,36 @@ def test_switch_layer_dtype_join_failed():
with
pytest
.
raises
(
TypeError
)
as
err
:
net
(
i
,
inp
)
def
test_large_for_loop_case2
():
class
Menet
(
nn
.
Cell
):
def
__init__
(
self
,
axis
,
flag_boottom
,
flag_top
):
super
(
Menet
,
self
).
__init__
()
self
.
squeeze
=
P
.
Squeeze
(
axis
)
self
.
expanddims
=
P
.
ExpandDims
()
self
.
flatten
=
nn
.
Flatten
()
self
.
neg
=
P
.
Neg
()
self
.
axis
=
axis
self
.
flag_boottom
=
flag_boottom
self
.
flag_top
=
flag_top
def
construct
(
self
,
x
):
if
self
.
flag_boottom
:
x
=
self
.
neg
(
x
)
for
i
in
range
(
0
,
1500
):
x
=
self
.
expanddims
(
x
,
self
.
axis
)
x
=
self
.
squeeze
(
x
)
x
=
self
.
flatten
(
x
)
if
self
.
flag_top
:
x
=
self
.
neg
(
x
)
return
x
x
=
Tensor
(
np
.
ones
([
2
,
3
],
dtype
=
np
.
float32
))
net
=
Menet
(
axis
=
0
,
flag_boottom
=
True
,
flag_top
=
True
)
old_max_call_depth
=
context
.
get_context
(
'max_call_depth'
)
context
.
set_context
(
max_call_depth
=
80
)
with
pytest
.
raises
(
RuntimeError
)
as
err
:
net
(
x
)
context
.
set_context
(
max_call_depth
=
old_max_call_depth
)
assert
'Exceed function call depth limit 80'
in
str
(
err
.
value
)
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
反馈
建议
客服
返回
顶部