2.4K Star 8.2K Fork 4.4K

GVPMindSpore / mindspore

 / 详情

Got "Illegal AnfNode for evaluating, node" when using "while"

DONE
Requirement
创建于  
2022-02-07 17:29
name about labels
Bug Report Use this template for reporting a bug kind/bug

Environment

  • Hardware Environment(Ascend/GPU/CPU):

Uncomment only one /device <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/device ascend
/device gpu
/device cpu

  • Software Environment:
    -- MindSpore version (source or binary):
    -- Python version (e.g., Python 3.7.5):
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):
    -- GCC/Compiler version (if compiled from source):

Related testcase

Steps to reproduce the issue

Describe the current behavior

Describe the expected behavior

Related log / screenshot

Special notes for this issue

评论 (5)

zhangzhaoju 创建了Bug-Report

Please add labels (comp or sig), also you can visit https://gitee.com/mindspore/community/blob/master/sigs/dx/docs/labels.md to find more.
为了让代码尽快被审核,请您为Pull Request打上 组件(comp)或兴趣组(sig) 标签,打上标签的PR可以直接推送给责任人进行审核。
更多的标签可以查看https://gitee.com/mindspore/community/blob/master/sigs/dx/docs/labels.md
以组件相关代码提交为例,如果你提交的是data组件代码,你可以这样评论:
//comp/data
当然你也可以邀请data SIG组来审核代码,可以这样写:
//sig/data
另外你还可以给这个PR标记类型,例如是bugfix或者是特性需求:
//kind/bug or //kind/feature
恭喜你,你已经学会了使用命令来打标签,接下来就在下面的评论里打上标签吧!

zhangzhaoju 负责人设置为chenfei_mindspore
zhangzhaoju 添加了comp/compiler(已删除)标签
zhangzhaoju 移除了comp/compiler(已删除)标签
zhangzhaoju 里程碑MindSpore Vision开发工具0.1版本 修改为未设置
zhangzhaoju 里程碑设置为B-SIG-Compiler(已删除)
zhangzhaoju 修改了描述
zhangzhaoju 修改了标题

如下代码抛异常"Illegal AnfNode for evaluating, node"

from mindspore.nn import Cell
from mindspore import Tensor, dtype, context

context.set_context(save_graphs=True, save_graphs_path='graph_path')


class Net(Cell):
    def __init__(self):
        super().__init__()
        self.ini_flg = Tensor(False, dtype.bool_)
        self.true_flg = Tensor([True], dtype.bool_)
        self.false_flg = Tensor([False], dtype.bool_)

    def construct(self, x, y):
        finish_flg = self.ini_flg
        while finish_flg:
            x = x + 1
            y = y - 1
            if x > y:
                finish_flg = self.false_flg
            else:
                finish_flg = self.true_flg
        return x, y


x = Tensor([0], dtype.int32)
y = Tensor([10], dtype.int32)
net = Net()
net(x, y)

但是为while语句添加not后可以正常运行

from mindspore.nn import Cell
from mindspore import Tensor, dtype, context

context.set_context(save_graphs=True, save_graphs_path='graph_path')


class Net(Cell):
    def __init__(self):
        super().__init__()
        self.ini_flg = Tensor(False, dtype.bool_)
        self.true_flg = Tensor([True], dtype.bool_)
        self.false_flg = Tensor([False], dtype.bool_)

    def construct(self, x, y):
        finish_flg = self.ini_flg
        while not finish_flg:
            x = x + 1
            y = y - 1
            if x > y:
                finish_flg = self.false_flg
            else:
                finish_flg = self.true_flg
        return x, y


x = Tensor([0], dtype.int32)
y = Tensor([10], dtype.int32)
net = Net()
net(x, y)

初步分析原因是:SetUndeterminedFlag只会设置到当前graph的fg_parent, 添加了not后parent就不是while的head block了

关联问题单:https://e.gitee.com/mind_spore/dashboard?issue=I4SED0

chenfei_mindspore 优先级设置为不重要
chenfei_mindspore 添加了
 
kind/bug
标签
chenfei_mindspore 计划开始日期设置为2022-03-01
chenfei_mindspore 计划截止日期设置为2022-06-30
zhangqinghua 添加了
 
v1.7.0
标签

初步分析原因:
不加not时,从header调用body进入循环时,变量finish_flag是scalar(bool)类型,在body执行过程中强制将变量finish_flag改为Tensor(bool)类型,body执行完后再次递归调用body传参finish_flag类型发生变化,导致出错。

控制流有过约束,循环体内部不能更改变量类型,如果变量是Tensor,不允许更改dtype和shape。

问题初步定位:
StaticAnalysis阶段,
第一次外部调用header图时,UndeterminedFlag=false,finish_flg初始化为Tensor(bool), 第一次infer时对parameter设置为arg的abstract,value为常量。
第二次从Body调用Header时,UndeterminedFlag=true,finish_flg被设置为Tensor([bool]), parameter设置为arg的abstract,value为kAnlyValue。

Specilize阶段,
第一次外部调用header图时,UndeterminedFlag=true,finish_flg初始化为Tensor(bool), arg的value被Broaden为kAnyValue,查询不到parameter的EvalResult,所以报错。

chenfei_mindspore 移除了
 
v1.7.0
标签
chenfei_mindspore 任务类型Bug-Report 修改为Requirement
chenfei_mindspore 里程碑B-SIG-Compiler(已删除) 修改为未设置

Appearance & Root Cause
问题现象:
Infer阶段报错。
问题根因:
while header图的第一次调用实参是Scalar常量类型,第二次由body调用header是Tensor变量类型,特化的时候一定会对实参做broaden,所以第一次调用的实参会被broaden为Scalar变量,导致查询不到infer缓存(只有Scalar常量缓存)

Fix Solution
当查询不到Scalar变量缓存时,回头查询Scalar常量。(优先使用和body一致的类型,不能统一一致时按不broaden类型查询)

chenfei_mindspore 任务状态TODO 修改为ACCEPTED
chenfei_mindspore 任务状态ACCEPTED 修改为WIP
chenfei_mindspore 任务状态WIP 修改为DONE

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(3)
6521784 chenfei52 1584972569
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore

搜索帮助

344bd9b3 5694891 D2dac590 5694891