mindspore.ops.Primitive

class mindspore.ops.Primitive(name)[source]

Primitive is the base class of primitives in python.

Parameters

name (str) – Name for the current Primitive.

Examples

>>> add = Primitive('add')
>>>
>>> # or work with prim_attr_register:
>>> # init a Primitive class with attr1 and attr2
>>> class Add(Primitive):
...     @prim_attr_register
...     def __init__(self, attr1, attr2):
...         # check attr1 and attr2 or do some initializations
>>> # init a Primitive obj with attr1=1 and attr2=2
>>> add = Add(attr1=1, attr2=2)
add_prim_attr(name, value)[source]

Adds primitive attribute.

Parameters
  • name (str) – Attribute Name.

  • value (Any) – Attribute value.

check_elim(*args)[source]

Check if certain inputs should go to the backend. Subclass in need should override this method.

Parameters

args (Primitive args) – Same as arguments of current Primitive.

Returns

A tuple consisting of two elements. The first element indicates whether we should filter out current arguments; the seconde element is the output if we need to filter out the arguments.

del_prim_attr(name)[source]

Del primitive attribute.

Parameters

name (str) – Attribute Name.

init_prim_io_names(inputs, outputs)[source]

Initializes the name of inputs and outputs of Tensor or attributes.

Parameters
  • inputs (list[str]) – list of inputs names.

  • outputs (list[str]) – list of outputs names.

set_prim_instance_name(instance_name)[source]

Set instance name to primitive operator.

Note

It will be called by default when user defines primitive operator.

Parameters

instance_name (str) – Instance name of primitive operator set by user.

set_stage(stage)[source]

Add stage id to primitive attribute.

Note

It is valid only in semi auto parallel. In other parallel modes, please set it to be 0.

Parameters

stage (int) – The stage id for the current operation

shard(strategy)[source]

Add strategies to primitive attribute.

Note

It is valid only in semi auto parallel or auto parallel mode. In other parallel modes, strategies set here will be ignored.

Parameters

strategy (tuple) – Strategy describes the distributed parallel mode of the current primitive.

property update_parameter

Whether the primitive will update the value of parameter.