2.4K Star 8.2K Fork 4.4K

GVPMindSpore / mindspore

 / 详情

修改cell中的属性后, 图中执行的时候属性的值没有变化

DONE
Bug-Report
创建于  
2023-06-16 17:12

Describe the current behavior / 问题描述 (Mandatory / 必填)

修改了cell中的一个属性的值, 在construct中需要使用这个属性控制if else, 但是值却并没有正确的被修改

Environment / 环境信息 (Mandatory / 必填)

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境: Ascend

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) : 2.0 beta
    -- Python version (e.g., Python 3.7.5) : Python 3.7.5
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04): eulor 2.8
    -- GCC/Compiler version (if compiled from source):

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph):

Please delete the mode not involved / 请删除不涉及的模式:

/mode graph

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

import numpy as np
from mindspore import nn, Tensor
from mindspore import context


class Flag(nn.Cell):

    def __init__(self):
        super().__init__(auto_prefix=False)
        self.is_first_iteration = True

    def construct(self, x):

        if self.is_first_iteration:
            print('is first iteration', self.is_first_iteration)
        else:
            print('is not first iteration', self.is_first_iteration)

        return x


context.set_context(
    mode=context.GRAPH_MODE,
    device_target="Ascend",
    device_id=7)

network = Flag()
input0 = Tensor(np.arange(10))
input1 = Tensor(np.arange(20))

network.add_flags_recursive(is_first_iteration=True)
network(input0)

network.add_flags_recursive(is_first_iteration=False)
network(input0)

network(input1)

Describe the expected behavior / 预期结果 (Mandatory / 必填)

is first iteration
Tensor(shape=[], dtype=Bool, value=True)

is not first iteration
Tensor(shape=[], dtype=Bool, value=False)

is not first iteration
Tensor(shape=[], dtype=Bool, value=False)

Related log / screenshot / 日志 / 截图 (Mandatory / 必填)

输入图片说明

评论 (7)

Titan 创建了Bug-Report

Please assign maintainer to check this issue.
请为此issue分配处理人。
@fangwenyi @chengxiaoli @wuweikang

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
恭喜你,你已经学会了使用命令来打标签,接下来就在下面的评论里打上标签吧!

Titan 修改了描述
qujianwei 负责人设置为kisnwang
qujianwei 优先级设置为主要
qujianwei 添加了
 
v2.0.0.beta
标签
qujianwei 里程碑设置为B-SIG-Parallel
qujianwei 关联分支设置为r2.0.0-beta
fangwenyi 添加了
 
v1.11.0
标签
fangwenyi 添加了
 
v1.11.0
标签

beta版本问题单统一收编到1.11版本回归,在1.11上验证没问题,就走回归测试

kisnwang 添加协作者kisnwang
kisnwang 负责人kisnwang 修改为changzherui
kisnwang 里程碑B-SIG-Parallel 修改为B-SIG-FrontEnd

问题现象:
cell编译后,修改cell属性,在construct里获取到的cell属性还是编译前的。
定位情况:
第一次编译时,cell对象会缓存,后续编译时,判断如果是同一个cell对象,会调用编译缓存。
问题原因:
属性修改后,实际前端cell对象的属性已经被修改,但是编译缓存调用的是原始对象,因此在construct里访问到的cell属性没有被修改。
场外信息:
cell的is_first_iteration 属性只会在第一次编译时被判断使用,后续不会用到,所以再次赋值没有实际使用场景。

结论:与子亮讨论后,认为是框架缓存机制导致,非框架bug。
后续考虑,在models里不要通过判断cell属性去改网络结构

changzherui 任务状态TODO 修改为VALIDATION
changzherui 添加协作者changzherui
changzherui 负责人changzherui 修改为qujianwei
changzherui 任务状态VALIDATION 修改为DONE

问题已解决,关闭

登录 后才可以发表评论

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

搜索帮助

344bd9b3 5694891 D2dac590 5694891