问题描述:
【功能模块】
`parameters rank` in `SGD` should be int and must > 0, but got `0` with type `int`.
mindspore版本linux-cpu-1.6.1
【操作步骤&问题现象】
在网络中加入了自定义可训练参数后,报错。之前没有错误,加入之后报如下错误:`parameters rank` in `SGD` should be int and must > 0, but got `0` with type `int`.
【截图信息】
1、
2、
解答:
自定义的parameter需满足其shape的长度(rank)大于0,self.block_weight.shape=(),其shape的长度(rank)为0。 修改为如下方式是否可以满足你的需求:self.block_weight = Parameter(Tensor(np.array([0.1]), msp.float32), name="w", requires_grad=True)