函数变换获得梯度计算函数时报错AttributeError: module 'mindspore' has no attribute 'value_and_grad'
收藏回复举报
函数变换获得梯度计算函数时报错AttributeError: module 'mindspore' has no attribute 'value_and_grad'
发表于2023-08-21 16:12:18
0 查看

1 系统环境

硬件环境(Ascend/GPU/CPU): CPU

MindSpore版本: mindspore=1.10.0

执行模式(PyNative/ Graph):不限

Python版本: Python=3.8.8

操作系统平台: 不限

2 报错信息

2.1 问题描述

快速入门教程中的“模型训练”,通过函数变换获得梯度计算函数时,出现报错。

2.2 报错信息

AttributeError: module 'mindspore' has no attribute 'value_and_grad'

2.3 脚本代码(代码格式,可上传附件)

# Get gradient function
grad_fn = mindspore.value_and_grad(forward_fn, None, optimizer.parameters, has_aux=True)

3 根因分析

******此处由用户补充详细的定位过程******

4 解决方案

cke_8965.png

包含文字方案和最终脚本代码

请将正确的脚本打包并上传附件

我要发帖子