MindSpore算子制作ST测试报错:TypeError: infer_dtype() takes 2 positional

举报
塞恩斯 发表于 2025/02/15 21:57:35 2025/02/15
1.2w+ 0 0
【摘要】 MindSpore算子制作ST测试报错:TypeError: infer_dtype() takes 2 positional arguments but 3 were given

一、版本信息

软件版本

CANN: 8.0.0 beta 1
Mindspore: 2.5.0
MindStudio: 7.0.0

硬件版本

香橙派AI Pro 8T 16GB版

二、BUG与解决方法

AddCustom ST case start running...
[INFO] ===========================================================================Generate acl_op.json===========================================================================
2025-02-15 15:38:37  (227880) - [INFO] [STEP1] [case_design.py] Start to parser testcase json.
2025-02-15 15:38:37  (227880) - [INFO] Start to create sub test cases for /root/MindstudioProjects/AddCustom/testcases/st/add_custom/AddCustom_case_20250215151949.json.
2025-02-15 15:38:37  (227880) - [WARNING] There is no expect output function in the case json, if no need to compare output data, ignore.
2025-02-15 15:38:37  (227880) - [INFO] Create 1 sub test cases for Test_AddCustom_001.
2025-02-15 15:38:37  (227880) - [INFO] Process finished!
2025-02-15 15:38:37  (227880) - [INFO] The st report saved in: /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/st_report.json.
2025-02-15 15:38:37  
[INFO] ===========================================================================Generate TestCase===========================================================================
2025-02-15 15:38:54  (227894) - [INFO] Content appended to /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/src/test_add_custom.py successfully.
2025-02-15 15:38:54  (227894) - [INFO] Content appended to /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/src/pytest.ini successfully.
2025-02-15 15:38:54  (227894) - [INFO] Operator test code files for specified test cases generated successfully.
2025-02-15 15:38:54  (227894) - [INFO] [STEP1] [data_generator.py] Generate data for testcase.
2025-02-15 15:38:54  (227894) - [INFO] Start to generate the input data for Test_AddCustom_001_case_1_float16.
2025-02-15 15:38:54  (227894) - [INFO] Generate data for testcase in /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/run/out/test_data/data.
2025-02-15 15:38:54  (227894) - [INFO] Process finished!
2025-02-15 15:38:54  (227894) - [INFO] The st report saved in: /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/st_report.json.
2025-02-15 15:38:56  
ST run command is cd /root/MindstudioProjects/AddCustom/testcases/st/out && export PYTHONPATH=$PYTHONPATH:/root/MindstudioProjects/AddCustom/mindspore/impl && export PYTHONPATH=$PYTHONPATH:/root/MindstudioProjects/AddCustom/op_proto && export PYTHONPATH=$PYTHONPATH:/usr/local/Ascend/ascend-toolkit/8.0.0/atc/python/site-packages && /usr/local/miniconda3/envs/mindspore/bin/python3 -m pytest -s --color=no add_custom/src/test_add_custom.py::test_AddCustom_001_case_1_float16
[WARNING] ME(227906:255086367526944,MainProcess):2025-02-15-15:39:11.255.772 [mindspore/context.py:1335] For 'context.set_context', the parameter 'device_target' will be deprecated and removed in a future version. Please use the api mindspore.set_device() instead.
[WARNING] ME(227906:255086367526944,MainProcess):2025-02-15-15:39:11.257.551 [mindspore/context.py:1335] For 'context.set_context', the parameter 'device_id' will be deprecated and removed in a future version. Please use the api mindspore.set_device() instead.
============================= test session starts ==============================
platform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0
rootdir: /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/src
configfile: pytest.ini
collected 1 item

add_custom/src/test_add_custom.py::test_AddCustom_001_case_1_float16 FAILED
[WARNING] DEVICE(227906,e7ffec52d020,python3):2025-02-15-15:39:11.485.706 [mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_memory_adapter.cc:118] Initialize] Free memory size is less than half of total memory size.Device 0 Device MOC total size:16367894528 Device MOC free size:5650636800 may be other processes occupying this card, check as: ps -ef|grep python

[ERROR] ANALYZER(227906,e7ffec52d020,python3):2025-02-15-15:39:53.238.568 [mindspore/ccsrc/pipeline/jit/ps/static_analysis/evaluator.cc:726] Run] Primitive: <PythonPrimEvaluator_AddCustom> infer failed, failed info: TypeError: infer_dtype() takes 2 positional arguments but 3 were given
=================================== FAILURES ===================================

______________________ test_AddCustom_001_case_1_float16 _______________________
At:

  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/ops/primitive.py(746): __infer__
    def test_AddCustom_001_case_1_float16():
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/common/api.py(1897): compile
    
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/nn/cell.py(1133): compile
        input0 = np.fromfile('add_custom/run/out/test_data/data/Test_AddCustom_001_case_1_float16_input_0.bin', np.float16)
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/nn/cell.py(1150): compile_and_run
        input0.shape = [3]
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/nn/cell.py(732): __call__
    
  /root/MindstudioProjects/AddCustom/testcases/st/out/add_custom/src/test_add_custom.py(38): test_AddCustom_001_case_1_float16
        input1 = np.fromfile('add_custom/run/out/test_data/data/Test_AddCustom_001_case_1_float16_input_1.bin', np.float16)
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/python.py(159): pytest_pyfunc_call
        input1.shape = [3]
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_callers.py(103): _multicall
    
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_manager.py(120): _hookexec
        add_custom_test = Net()
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_hooks.py(513): __call__
    
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/python.py(1627): runtest
        start = time.time()
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/runner.py(174): pytest_runtest_call
    
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_callers.py(103): _multicall
>       output0 = add_custom_test(Tensor(input0),Tensor(input1))
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_manager.py(120): _hookexec

  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_hooks.py(513): __call__
add_custom/src/test_add_custom.py:38: 
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/runner.py(242): <lambda>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/runner.py(341): from_call
/usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/nn/cell.py:732: in __call__
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/runner.py(241): call_and_report
    out = self.compile_and_run(*args, **kwargs)
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/runner.py(132): runtestprotocol
/usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/nn/cell.py:1150: in compile_and_run
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/runner.py(113): pytest_runtest_protocol
    self.compile(*args, **kwargs)
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_callers.py(103): _multicall
/usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/nn/cell.py:1133: in compile
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_manager.py(120): _hookexec
    _cell_graph_executor.compile(self, *self._compile_args, phase=self.phase,
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_hooks.py(513): __call__
/usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/mindspore/common/api.py:1897: in compile
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/main.py(362): pytest_runtestloop
    result = self._graph_executor.compile(obj, args, kwargs, phase, self._use_vm_mode())
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_callers.py(103): _multicall
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_manager.py(120): _hookexec

  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_hooks.py(513): __call__
self = Prim[AddCustom]
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/main.py(337): _main
args = ({'dtype': mindspore.tensor[float16], 'shape': [3], 'value': None}, {'dtype': mindspore.tensor[float16], 'shape': [3], 'value': None})
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/main.py(283): wrap_session
tracks = ['dtype', 'shape', 'value'], out = {}
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/main.py(330): pytest_cmdline_main
fn = <bound method AddCustom.infer_dtype of Prim[AddCustom]>
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_callers.py(103): _multicall

  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_manager.py(120): _hookexec
    def __infer__(self, *args):
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pluggy/_hooks.py(513): __call__
        """Infer shape, type, and value at the same time by using dictionary as arguments."""
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/config/__init__.py(175): main
        tracks = ['dtype', 'shape', 'value']
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/_pytest/config/__init__.py(201): console_main
        out = {}
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/site-packages/pytest/__main__.py(9): <module>
        for track in tracks:
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/runpy.py(87): _run_code
            fn = getattr(self, 'infer_' + track)
  /usr/local/miniconda3/envs/mindspore/lib/python3.9/runpy.py(197): _run_module_as_main
            # fn may return None

>           out[track] = fn(*(x[track] for x in args))
[ERROR] ANALYZER(227906,e7ffec52d020,python3):2025-02-15-15:39:53.287.755 [mindspore/ccsrc/pipeline/jit/ps/static_analysis/async_eval_result.cc:71] HandleException] Exception happened, check the information as below.
E           TypeError: infer_dtype() takes 2 positional arguments but 3 were given
TypeError: infer_dtype() takes 2 positional arguments but 3 were given

解决方法
这里报错是因为在自定义算子类的时候变量函数申明有问题,如下图所示:
image.png

这里需要修改对应的infer_shape和infer_dtype函数,增加输入变量个数,起占位变量。
image.png

def infer_shape(self, x_shape, y_shape):
	return x_shape
def infer_dtype(self, x_dtype, y_dtype):
	return x_dtype
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。