PR #124588
tensorflow/tensorflow · XLA · Merged · 2 files changed
tf.experimental.numpy.cross failed XLA compilation on statically shaped 3D vectors because axis normalization emitted dynamic reshapes incompatible with XLA static bounds. Preserving static trailing dimensions resolved compilation failures.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 124588 --repo tensorflow/tensorflowtf.experimental.numpy.cross failed XLA compilation on statically shaped 3D vectors because axis normalization emitted dynamic reshapes incompatible with XLA static bounds. Preserving static trailing dimensions resolved compilation failures.
File-by-File Modification Breakdown (2)
- +13 / -2
tensorflow/python/ops/numpy_ops/np_math_ops.py
Upstream Python/C++ module implementation
- +49 / -0
tensorflow/python/ops/numpy_ops/np_math_ops_test.py
Python/XLA regression test suite verifying edge-case behavior
Changed Files (2)
1. Introduction & Motivation
NumPy-compatible APIs in tf.experimental.numpy are expected to lower seamlessly under both eager execution and xla.compile. In cross, however, internal axis-transposition helpers discarded known static dimension sizes along the contracted trailing axis, introducing dynamic shape nodes that XLA rejected during HLO lowering [1].
2. Vector Algebra & Static Shape Constraint
For vectors , the cross product contracts along an axis of exact length via the Levi-Civita tensor :
| Lowering Mode | Trailing Dimension Metadata | XLA Result |
|---|---|---|
| Before | Erased to dynamic ? | Compile failure |
| After | Preserved static 3 | Compiles to fixed HLO |
3. Implementation & Verification
Verified in XLA tests that tf.experimental.numpy.cross compiles and matches NumPy outputs for statically shaped trailing dimensions.
4. References
- NumPy Developers,
numpy.crossSpecification & Axis Semantics, NumPy Reference Manual.