Add a control dependency optimizer to Grappler.
The first two rewrites implemented are: 1. Turn nodes with only control outputs into NoOps, if we know that they are safe to remove. Such nodes can be produced, e.g., by rewrite rules in the arithmetic optimizer. 2. Completely disconnect NoOp nodes with at most 1 input or at most 1 output by rerouting their inputs to their outputs. The restriction on fan-in/fan-out guarantees that we reduce the number of control dependencies in the graph. The two (slightly) non-trivial cases are: // Case a) // x --^> +------+ x --^> +---+ // y --^> | NoOp | --^> a ==> y --^> | a | // ... | | ... | | // z --^> +------+ z --^> +---+ // // Case b) // +------+ --^> a +---+ --^> a // x --^> | NoOp | --^> b ==> | x | --^> b // | | ... | | ... // +------+ --^> c +---+ --^> c PiperOrigin-RevId: 175780178
Loading
Please sign in to comment