Should we have block inside operators?
Created by: typhoonzero
Inspired by https://github.com/PaddlePaddle/Paddle/issues/6517#issuecomment-351935737
Should we have blocks inside operators? For example, in programming languages, some statements controls, and evaluates several blocks:
if (condition statement) {
true condition block
} else {
false condition block
}
Or
while (condition statement) {
loop block
}
For now, we implement this by putting a BlockDescBind
inside the operator's Attr
and use Executor
to run the block inside operator. The Executor
is created for multiple times and runs unpredictable inside operators.
In that case, we can make this while_op and if_else_op bind with Executor
to run:
var1 = layers.var()
var2 = layers.var()
with if_statement(math.ops.greater(var1, var2)) as ifop:
# define subblock layers
op:
name: if_else
blocks:
block 0: condition
block 1: true block
block 2: else block
Then the Executor
will do differently control statements if the operator type is while
or if
.