Commit 0c19b61a authored by A. Unique TensorFlower's avatar A. Unique TensorFlower Committed by TensorFlower Gardener
Browse files

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
parent 24a6162d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment