mindspore.ops.composite

Composite operators.

Pre-defined combination of operators.

  • mindspore.ops.composite.core(fn=None, **flags)[source]
  • A decorator to add flag to a function.

By default, the function is marked core=True using this decorator toset flag to a graph.

  • Parameters
    • fn (Function) – Function to add flag. Default: None.

    • flags (dict) – The following flags can be set core, which indicates that this is a core function orother flag. Default: None.

  • mindspore.ops.composite.addflags(_fn, **flags)[source]
  • An interface to add flag for a function.

Note

Only supports bool value.

  • Parameters
    • fn (Function) – Function or cell to add flag.

    • flags (bool) – Flags use kwargs.

  • Returns

  • Function, the fn added flags.

Examples

  1. Copy>>> add_flags(net, predit=True)
  • class mindspore.ops.composite.MultitypeFuncGraph(name)[source]
  • Generate multiply graph.

MultitypeFuncGraph is a class used to generate graphs for function with different type as input.

  • Parameters
  • name (str) – Operator name.

  • Raises

  • ValueError – Cannot find matching fn for the given args.

Examples

  1. Copy>>> # `add` is a metagraph object which will add two objects according to
  2. >>> # input type using ".register" decorator.
  3. >>> add = MultitypeFuncGraph('add')
  • register(*type_names)[source]
  • Register a function for the given type string.
  • class mindspore.ops.composite.GradOperation(name, get_all=False, get_by_list=False, sens_param=False)[source]
  • An metafuncgraph object which is used to get the gradient of output of a network(function).

The GradOperation will convert the network(function) into a back propagation graph.

  • Parameters
    • get_all (bool) – If True, get all the gradients w.r.t inputs. Default: False.

    • get_by_list (bool) – If True, get all the gradients w.r.t Parameter variables.If get_all and get_by_list are both False, get the gradient w.r.t first input.If get_all and get_by_list are both True, get the gradients w.r.t inputs and Parameter variablesat the same time in the form of ((grads w.r.t inputs), (grads w.r.t parameters)). Default: False.

    • sens_param (bool) – Whether append sensitivity as input. If sens_param is False,a ‘ones_like(outputs)’ sensitivity will be attached automatically. Default: False.

  • class mindspore.ops.composite.HyperMap(ops=None)[source]
  • Hypermap will apply the set operation on input sequences.

Which will apply the operations of every elements of the sequence.

  • Parameters
  • ops (Union__[MultitypeFuncGraph, None]) – ops is the operation to apply. If ops is None,the operations should be putted in the first input of the instance.

  • Inputs:

    • args (Tuple[sequence]) - If ops is not None, all the inputs should be the same length sequences,and each row of the sequences. e.g. If args length is 2, and for i in length of each sequence(args[0][i], args[1][i]) will be the input of the operation.

If ops is not None, the first input is the operation, and the other is inputs.

  • Outputs:
  • sequence, the output will be same type and same length of sequence from input and the value of each elementis the result of operation apply each row of element. e.g. operation(args[0][i], args[1][i]).

  • register(*type_names)[source]

  • Register a function for the given type string.
  • mindspore.ops.composite.clipby_value(_x, clip_value_min, clip_value_max)[source]
  • Clips tensor values to a specified min and max.

Limits the value of

mindspore.ops.composite - 图1
to a range, whose lower limit is ‘clip_value_min’and upper limit is ‘clip_value_max’.

Note

‘clip_value_min’ needs to be less than or equal to ‘clip_value_max’.

  • Parameters
    • x (Tensor) – Input data.

    • clip_value_min (Tensor) – The minimum value.

    • clip_value_max (Tensor) – The maximum value.

  • Returns

  • Tensor, a clipped Tensor.