1 系统环境
硬件环境(Ascend/GPU/CPU): Ascend/GPU/CPU
MindSpore版本: 不限版本
执行模式(动态图/静态图): 静态图
Python版本: 3.7/3.8/3.9
操作系统平台:不限
2 报错信息
2.1 报错信息
2.2 脚本代码
3 根因分析
******此处由用户补充详细的定位过程******
根因
可能原因: 静态图模式下,网络的construct函数、@ms_function修饰的函数、@ms.jit修饰的函数中出现如下问题:
1)直接或者间接使用了try语法,此语法静态图模式不支持;
2)直接或间接的调用了MindSpore的get_context接口(get_context接口会使用try语法),此接口不能在construct等函数中调用;
处理建议:
1)将try语法在函数中移除;
2)函数中调用的get_context()接口,迁移到函数外调用;
4 解决方案
******此处由用户填写******
包含文字方案和最终脚本代码
代码格式,可上传附件
1 系统环境
硬件环境(Ascend/GPU/CPU): Ascend/GPU/CPU
MindSpore版本: 不限版本
执行模式(动态图/静态图): 静态图
Python版本: 3.7/3.8/3.9
操作系统平台:不限
2 报错信息
2.1 报错信息
2.2 脚本代码
""" This is a python code template """ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.nn import Cell from mindspore import ops from mindspore import dtype as mstype import mindspore context.set_context(mode=mindspore.GRAPH_MODE, pynative_synchronize=False) class Net1(nn.Cell): def __init__(self): super().__init__() self.add = ops.Add() self.sub = ops.Sub() self.mul = ops.Mul() self.div = ops.Div() def func(x, y): context.get_context("device_target") return self.div(x, y) def construct(self, x, y): a = self.sub(x, 1) b = self.add(a, y) c = self.mul(b, self.func(a, b)) return c def test2(): input1 = Tensor(3, mstype.float32) input2 = Tensor(2, mstype.float32) net = Net1() out = net(input1, input2) print(out) if __name__ == '__main__': test2()3 根因分析
******此处由用户补充详细的定位过程******
根因
可能原因: 静态图模式下,网络的construct函数、@ms_function修饰的函数、@ms.jit修饰的函数中出现如下问题:
1)直接或者间接使用了try语法,此语法静态图模式不支持;
2)直接或间接的调用了MindSpore的get_context接口(get_context接口会使用try语法),此接口不能在construct等函数中调用;
处理建议:
1)将try语法在函数中移除;
2)函数中调用的get_context()接口,迁移到函数外调用;
4 解决方案
******此处由用户填写******
包含文字方案和最终脚本代码
代码格式,可上传附件