2.3K Star 8.1K Fork 4.3K

GVPMindSpore / mindspore

 / 详情

[CT][MS]HyperMap input multi type, grad fail in pynative

TODO
RFC 成员
创建于  
2022-03-10 19:51
name about labels
Bug Report Use this template for reporting a bug kind/bug

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

HyperMap输入序列包含多种类型,pynative模式求反向报错

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

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

Please delete the backend not involved / 请删除不涉及的后端:
/device ascend
/device gpu
/device cpu

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g.,r1.6 commit_id=xxxx) :
    -- Python version (e.g., Python 3.7.5) :
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):
    -- GCC/Compiler version (if compiled from source):

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

Please delete the mode not involved / 请删除不涉及的模式:
/mode pynative

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

from mindspore.ops.composite import MultitypeFuncGraph, HyperMap
import mindspore.ops.operations as P
import mindspore.ops.functional as F
import numpy as np
from mindspore.common import Tensor
from mindspore.nn import Cell
from mindspore import context


class AddnNet(Cell):
    def __init__(self, mtfg):
        super().__init__()
        self.hyper_map = HyperMap(mtfg)

    def construct(self, x, y):
        out = self.hyper_map(([x, x], y), (y, x))
        return out

def test():
    test = MultitypeFuncGraph("add")
    @test.register("List", "Tensor")
    def test_addn(a, x):
        s = P.AddN()(a)
        return s + x

    @test.register("Tensor", "Tensor")
    def test_add(a, b):
        return a + b

    context.set_context(mode=context.PYNATIVE_MODE)
    net = AddnNet(test)
    x = np.random.rand(3, 4).astype(np.float32)
    y = np.random.rand(3, 4).astype(np.float32)
    s1 = np.random.rand(3, 4).astype(np.float32)
    s2 = np.random.rand(3, 4).astype(np.float32)
    out = net(Tensor(x), Tensor(y))
    #gradnet = GradOfAllInputs(net, sens_param=False)
    gradnet = F.grad(net, grad_position=(0, 1), sens_param=True)
    grad = gradnet(Tensor(x), Tensor(y), (Tensor(s1), Tensor(s2)))
    print(grad)


test()

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

  1. python addn.py

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

(Tensor(shape=[3, 4], dtype=Float32, value=
[[ 5.41507423e-01, 1.81717885e+00, 1.54103398e+00, 1.30712867e+00],
[ 9.78471339e-01, 1.23454714e+00, 1.77012408e+00, 2.36107469e+00],
[ 1.52369738e+00, 1.93735743e+00, 1.77906585e+00, 1.79818678e+00]]), Tensor(shape=[3, 4], dtype=Float32, value=
[[ 4.53553289e-01, 9.11485493e-01, 1.17603493e+00, 9.09169793e-01],
[ 9.55831051e-01, 9.02100444e-01, 1.13325739e+00, 1.39627075e+00],
[ 1.25652397e+00, 1.46083164e+00, 1.32083309e+00, 9.01678324e-01]]))

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

[CRITICAL] PYNATIVE(39789,7fed08d32740,python):2022-03-10-20:01:16.149.015 [mindspore/ccsrc/pipeline/pynative/pynative_execute.cc:2858] UpdateParamAbsByArgs] The shape should be TupleShape(TupleShape((3, 4), (3, 4)), (3, 4)), but got TupleShape((3, 4), (3, 4)), grad{3}.25:sens
Traceback (most recent call last):
File "addn.py", line 41, in
test()
File "addn.py", line 39, in test
grad = gradnet(Tensor(x), Tensor(y), (Tensor(s1), Tensor(s2)))
File "/root/miniconda3/envs/ctj/lib/python3.7/site-packages/mindspore/ops/composite/base.py", line 488, in after_grad
return grad_(fn, weights, grad_position)(*args, **kwargs)
File "/root/miniconda3/envs/ctj/lib/python3.7/site-packages/mindspore/common/api.py", line 64, in wrapper
results = fn(*arg, **kwargs)
File "/root/miniconda3/envs/ctj/lib/python3.7/site-packages/mindspore/ops/composite/base.py", line 479, in after_grad
pynative_executor.grad(grad, fn, weights, grad_position, *args, **kwargs)
File "/root/miniconda3/envs/ctj/lib/python3.7/site-packages/mindspore/common/api.py", line 520, in grad
self._executor.grad_net(grad, obj, weights, grad_position, *args, *(kwargs.values()))
ValueError: mindspore/ccsrc/pipeline/pynative/pynative_execute.cc:2858 UpdateParamAbsByArgs] The shape should be TupleShape(TupleShape((3, 4), (3, 4)), (3, 4)), but got TupleShape((3, 4), (3, 4)), grad{3}.25:sens

Special notes for this issue/备注 (Optional / 选填)

评论 (2)

chentanjie 创建了Bug-Report
chentanjie 添加了
 
kind/bug
标签
展开全部操作日志

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

chentanjie 计划截止日期2022-03-27 修改为
chentanjie 里程碑设置为B-ComponentTest
chentanjie 添加了
 
ccb/bug
标签

CCB: 问题1.8解决

chentanjie 添加了
 
ccb/rfc
标签
chentanjie 里程碑B-ComponentTest 修改为B-RFC
Richard_mei 任务类型Bug-Report 修改为RFC

登录 后才可以发表评论

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

搜索帮助