Category: Infrastructure
Short description: Loop operation performs recurrent execution of the network, which is described in the body
, iterating through the data. The operation has similar semantic to the ONNX* Loop operation.
Detailed description
The body of the Loop can be executed 0 or more times depending on the values passed to the Loop operation inputs called "trip count", "execution condition" and input of the Loop body called "current iteration".
These Loop operation inputs have the following meaning:
-1
can be provided as input.There are several combinations of these two inputs (trip_count, execution condition)
which are described in the following code snippet:
Loop operation description in the IR has regular sections: input
and output
. They connect Loop body to the outer graph and specify condition(s). Loop operation description in the IR also has several special sections: body
, port_map
and back_edges
similar to the ones from the TensorIterator operation but having some important features described below.
port_map
section of the Loop operation. These edges connect input ports of the Loop with the body Parameter
s.input
entry in the port_map
should have axis
attribute specifying the axis to slice. Therefore, inputs to the Loop operation corresponding to input
entries in the port_map
without axis
attribute are used "as is" (without slicing).back_edges
section of the operation. The back edge connects the respective body Parameter
and Result
operations. For such a case the Loop operation node provides input for the first iteration, while corresponding Loop operation output produces the tensor computed during the last iteration.output
entry in the port_map
should have axis
attribute specifying the axis to concatenate. Therefore, outputs from operations corresponding to output
entries in the port_map
without axis
attribute are returned "as is" (without concatenation).Parameter
operation not connected through the port_map
. This is a "current iteration" input. The Loop operation is responsible for providing the appropriate value for each iteration.Parameter
and Result
body operations. No other ways to connect graphs are allowed.Loop attributes:
Body:
body
is a network that will be recurrently executed. The network is described operation by operation as a typical IR network.
No attributes available.
Port map:
port_map is a set of rules to map input or output data tensors of Loop
operation onto body
data tensors. The port_map
entries can beinput
and output
. Each entry describes a corresponding mapping rule.
Loop
operation. The value -1
means that the body node is not connected to the Loop
operation.int
Parameter
or Result
operation ID inside the body
network to map to.Parameter
operations inside in the Loop operationint
output
entry, then it is an axis to concatenate the body Result
output across all iterations. If axis is specified for input
entry, then it is an axis to iterate through, it triggers the slicing of the input tensor.int
Back edges:
back_edges is a set of rules to transfer tensor values from body
outputs at one iteration to body
parameters at the next iteration. Back edge connects some Result
operation in the body
to Parameter
operation in the same body
.
Result
operation ID inside the body
network.Result
operations inside the Loopint
Parameter
operation ID inside the body
network to end mapping.Parameter
operations inside the Loopint
Loop Inputs
int64
or int32
type specifying maximum number of iterations. Required.boolean
type specifying whether to execute the first iteration or not. True
value means to execute the 1st iteration. Required.Loop Outputs
body
. Tensors of any type and shape.Body Inputs
purpose = "current_iteration"
and produces a scalar or 1D tensor with 1 element of int64
or int32
type. Optional.Body Outputs
body
. Tensors of any type and shape except the one corresponding to the output with execution condition. This output is marked in the port_map with attribute purpose = "execution_condition"
and is mandatory and produces a scalar or 1D tensor with 1 element of boolean
type. Other outputs are optional.Examples
Example 1: a typical Loop structure