PR #123195
tensorflow/tensorflow · Grappler · Merged · 2 files changed
Excluded Reciprocal from Grappler's IsInvolution optimization pass so adjacent 1/(1/x) nodes are preserved, protecting IEEE 754 rounding, subnormals, and overflow semantics.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 123195 --repo tensorflow/tensorflowExcluded Reciprocal from Grappler's IsInvolution optimization pass so adjacent 1/(1/x) nodes are preserved, protecting IEEE 754 rounding, subnormals, and overflow semantics.
File-by-File Modification Breakdown (2)
- +6 / -1
tensorflow/core/grappler/op_types.cc
Grappler C++ graph optimizer pass and algebraic rewrite rules
- +45 / -14
tensorflow/core/grappler/optimizers/arithmetic_optimizer_test.cc
C++ unit and regression test suite verifying the fix
Changed Files (2)
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.