2.3K Star 8K Fork 4.2K

GVPMindSpore / mindspore

 / 详情

nn.Cell的set_train没有改子网络的phase attribute

DONE
Bug-Report
创建于  
2023-06-06 14:42

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

当运行network.set_train()时,虽然network.training这个flag已经recursively修改了,但是network.phase没有正确修改,子网络的network.xx.phase还是最初的值。

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

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

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) : 2.0.0rc1
    -- Python version (e.g., Python 3.7.5) : 3.9.16
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):Linux

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

Related testcase / 关联用例 (Mandatory / 必填)

#test the set_train function
import mindspore.nn as nn

class Backbone(nn.Cell):
    def __init__(self):
        super().__init__()
        self.fc = nn.Dense(100, 100)
    def construct(self, x):
        x = self.fc(x)
        return x

class Head(nn.Cell):
    def __init__(self):
        super().__init__()
        self.fc = nn.Dense(100, 100)
    def construct(self, x):
        x = self.fc(x)
        return x

class Network(nn.Cell):
    def __init__(self):
        super().__init__()
        self.backbone = Backbone()
        self.head = Head()
    def construct(self, x):
        x = self.backbone(x)
        x = self.head(x)
        return x

network = Network()
network.set_train(False)
print(f"network.phase: {network.phase}\tnetwork.backbone.phase: {network.backbone.phase}\t network.head.phase: {network.head.phase}")
print(f"network.training: {network.training}\tnetwork.backbone.training: {network.backbone.training}\tnetwork.head.training: {network.head.training}")

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

运行上述代码

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

子网络的phase都改成了predict

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

network.phase: predict  network.backbone.phase: train    network.head.phase: train
network.training: False network.backbone.training: False        network.head.training: False

评论 (6)

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

wuweikang 负责人设置为qinzheng
wuweikang 关联项目设置为MindSpore Issue Assistant
wuweikang 添加了
 
mindspore-assistant
标签
wuweikang 添加了
 
mindspore-assistant
标签
wuweikang 任务状态TODO 修改为ACCEPTED
qinzheng 任务状态ACCEPTED 修改为WIP
Shawny 负责人qinzheng 修改为shaojunsong
Shawny 添加了
 
sig/frontend
标签

您好,问题我们已复现,正在分析中

您好,network.phase是一个内部参数,不会影响训练和推理的状态

是的,这不算是一个bug。只是希望training和flag这两个flag是同步变化的,以免造成用户的误解。

Shawny 任务状态WIP 修改为VALIDATION

是的,这不算是一个bug。只是希望training和flag这两个flag是同步变化的,以免造成用户的误解。

@wtomin phase是内部的一个判定参数,与相关责任人确认过这个参数的用途与框架运行时的分支有关,搭建模型的时候可以不用关注的

Shawny 任务状态VALIDATION 修改为DONE

登录 后才可以发表评论

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

搜索帮助