Grappler & Optimizer
tensorflow/tensorflow · C++, Graph Rewrites
Excluded tf.Reciprocal from unsound involution simplification where 1/(1/x) -> x violated IEEE 754 float rules on subnormals and overflows, and corrected unsound ArgMax/ArgMin graph rewrites on saturated float32 boundaries.
Verify with Bazel
Run the upstream regression suite in tensorflow/tensorflow for this subsystem.
$bazel test //tensorflow/core/grappler/optimizers:arithmetic_optimizer_testChanged Files (1)
1. Introduction & Motivation
Grappler's ArithmeticOptimizer simplifies computation graphs by querying IsInvolution(node) and eliminating consecutive self-inverse operators [1]. While exact for bitwise or sign-flipping operations like Neg or LogicalNot, treating floating-point Reciprocal as an involution is mathematically unsound under IEEE 754 arithmetic [2].
2. ULP & Subnormal Collapse Proof
For normal float32 values, two rounded divisions can deviate by up to ULP from . More severely, for subnormal , because , so:
| Operator | Exact Involution in binary32? | In kInvolutionOps? |
|---|---|---|
Neg, Conj, LogicalNot, Invert | Yes (exact bit/sign flip) | Yes |
Reciprocal | No (rounding & subnormal overflow) | Excluded (Fixed) |
3. Implementation & Verification
Updated arithmetic_optimizer_test.cc (RemoveInvolutionAdjacentNodes) to verify that Neg pairs still fold while Reciprocal pairs remain intact.
4. References
- TensorFlow Grappler Graph Optimization Framework,
tensorflow/core/grappler/optimizers/arithmetic_optimizer.cc. - D. Goldberg, What Every Computer Scientist Should Know About Floating-Point Arithmetic, ACM Computing Surveys, 1991.
- Anandhu P Shaji, Hunting Compiler Bugs and Numerical Traps in TensorFlow,
anandhupshaji.me/posts/tensorflow-stories.html#unsound-algebraic-rewrites.