执行时遇到‘context.set_context’报错怎么办

2025-05-12 17:39:31

1、1. 系统环境:Hardware Environment(Ascend/GPU/CPU): ALLSoftware Environment:MindSpore v髫潋啜缅ersion (source or binary): 1.7.0 & Earlier versionsPython version (e.g., Python 3.7.5): 3.7.6OS platform and distribution (e.g., Linux Ubuntu 16.04): UbuntuGCC/Compiler version (if compiled from source):

2、2. python代码样例from mindspore import contextcontext.set_context(device_target="Ascend")

3、3. 报错信息:ValueError: For 'context.set_context', package type xxx support 'device_target' type xxx, but got xxx.")

4、4. 原因分析context.set_context方法为设置脚本运行的后端,有Ascend、GPU、CPU。Ascend、GPU环境可以运行潮贾篡绐CPU后端,CPU环境不能运行Ascend、GPU后端,Ascend和GPU互相不能切换。如果脚本设置的运行后端与脚本运行的硬件不匹配,则会报这个错误。

5、5. 解决方法查看当前运行的硬件,在context.set_context中设置对应的即可。

6、6. 参考文档具体可参考可以参考:配置运行信息

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢