mindspore-ai / mindspore

MindSpore is a new open source deep learning training/inference framework that could be used for mobile, edge and cloud scenarios.
https://gitee.com/mindspore/mindspore
Apache License 2.0
4.26k stars 705 forks source link

lack of output shape checking in mindspore.nn.Conv2d #288

Open PhyllisJi opened 4 months ago

PhyllisJi commented 4 months ago

Software Environment:

Describe the current behavior

Traceback (most recent call last):
  File "/mnt/AA_MoCoDiff/BR_MoCoDiff/bugs/ms/BUG1_conv_dilation_output_size.py", line 15, in <module>
    print(p(x).shape)
  File "/root/miniconda3/envs/mocodiff/lib/python3.9/site-packages/mindspore/nn/cell.py", line 705, in __call__
    raise err
  File "/root/miniconda3/envs/mocodiff/lib/python3.9/site-packages/mindspore/nn/cell.py", line 702, in __call__
    _pynative_executor.end_graph(self, output, *args, **kwargs)
  File "/root/miniconda3/envs/mocodiff/lib/python3.9/site-packages/mindspore/common/api.py", line 1215, in end_graph
    self._executor.end_graph(obj, output, *args, *(kwargs.values()))
RuntimeError: The pointer[primitive_] is null.

----------------------------------------------------
- Framework Unexpected Exception Raised:
----------------------------------------------------
This exception is caused by framework's unexpected error. Please create an issue at https://gitee.com/mindspore/mindspore/issues to get help.

----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/cpu/kernel/mkldnn/mkl_cpu_kernel.cc:391 ExecutePrimitive

Describe the expected behavior

Mindspore.nn.Conv2d checks the output shape in advance to avoid 0-dimensional output and the underlying crash

Steps to reproduce the issue

import numpy as np
import mindspore

mindspore.context.set_context(device_target='CPU')

# 關於Conv2d中dilation對輸出形狀的影響問題,torch中會報出Output size too small等信息,而ms對此不做控制,會直接計算出零或者負輸出,其中負輸出會導致底層報錯
p = mindspore.nn.Conv2d(in_channels=8, out_channels=8, kernel_size=(3, 3), stride=(1, 1), pad_mode="pad", padding=(1, 1, 1, 1), dilation=(1, 8), group=8, has_bias=True, data_format="NCHW")
# 1. 空輸出
x = mindspore.Tensor(np.random.randn(1, 8, 14, 14).astype(np.float32))
print(p(x).shape)

# # 2. 負輸出,底層報錯
x = mindspore.Tensor(np.random.randn(1, 8, 13, 13).astype(np.float32))
print(p(x).shape)
VectorSL commented 3 weeks ago

请问是哪个版本的ms ? 当前2.4 的版本我尝试运行会校验shape。 [mindspore/ccsrc/kernel/kernel.cc:625] Resize] Invalid shape:[const vector]{1, 8, 13, -1}, kernel name:Conv2D image

PhyllisJi commented 3 weeks ago

请问是哪个版本的ms ? 当前2.4 的版本我尝试运行会校验shape。 [mindspore/ccsrc/kernel/kernel.cc:625] Resize] Invalid shape:[const vector]{1, 8, 13, -1}, kernel name:Conv2D image

MindSpore 2.2.14