From b1ba325779df783384cfb1b98bd166ad61b3b3d1 Mon Sep 17 00:00:00 2001 From: wilfChen Date: Tue, 17 Aug 2021 10:33:42 +0800 Subject: [PATCH] pyfunc primitive docs --- mindspore/ops/operations/other_ops.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mindspore/ops/operations/other_ops.py b/mindspore/ops/operations/other_ops.py index 2618b1cc44b..2a5098e7518 100644 --- a/mindspore/ops/operations/other_ops.py +++ b/mindspore/ops/operations/other_ops.py @@ -852,17 +852,24 @@ class PyFunc(PrimitiveWithInfer): r""" Execute Python function. + `PyFunc` encapsulates Python functions as an operator which could be compiled into computation graph. + Unlike normal operators, it cannot be exported to MindIR as it is executed in current Python context. + As only the weights of the network is stored in the checkpoint, network include `PyFunc` could save + checkpoint and load to the network again, but will lose any Python function state. + .. warning:: This is an experimental prototype that is subject to change and/or deletion. Args: fn (function): Python function which inputs and outputs should be Python built-in scalar or numpy ndarray. in_types (list[:class:`mindspore.dtype`]): The type of the inputs. - in_shapes (list[tuple[int]]): The dimensionality of the inputs. + in_shapes (list[tuple[int]]): The dimensionality of the inputs. An empty list represents a scalar, otherwise it + represent a numpy array. out_types (list[:class:`mindspore.dtype`]): The type of the outputs. - out_shapes (list[tuple[int]]): The dimensionality of the outputs. + out_shapes (list[tuple[int]]): The dimensionality of the outputs. An empty list represents a scalar, otherwise + it represent a numpy array. stateful (bool): Whether the function is stateful or not. - If True, the execution order are same with model definition. + If True, the execution order is same with model definition. Inputs: - **input_x** (Union(tuple[Tensor], list[Tensor])) - The input tuple or list @@ -872,7 +879,9 @@ class PyFunc(PrimitiveWithInfer): tuple[Tensor], execution results Python functions. Raises: - TypeError: If the Python function execution failed. + TypeError: The Python function execution failed. + TypeError: The attributes(in_types/in_shapes/out_types/out_shapes) are inconsistent with Python function + specifications. Supported Platforms: ``CPU``