PR #124586
tensorflow/tensorflow · XLA · Merged · 2 files changed
XLA's TransposeOp rejected negative permutation indices such as perm=[-1, 0] instead of wrapping them modulo tensor rank. I normalized negative indices prior to bounds validation so XLA matches eager TensorFlow behavior.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 124586 --repo tensorflow/tensorflowXLA's TransposeOp rejected negative permutation indices such as perm=[-1, 0] instead of wrapping them modulo tensor rank. I normalized negative indices prior to bounds validation so XLA matches eager TensorFlow behavior.
File-by-File Modification Breakdown (2)
- +15 / -0
tensorflow/compiler/tests/binary_ops_test.py
Python/XLA regression test suite verifying edge-case behavior
- +5 / -1
tensorflow/compiler/tf2xla/kernels/transpose_op.cc
XLA C++ kernel shape-lowering and compile-time invariant checks
Changed Files (2)
1. Introduction & Motivation
Standard TensorFlow and NumPy indexing conventions treat negative axis indices as offsets from the final dimension. Under XLA, TransposeOp performed raw non-negative bounds checks directly on the user-supplied perm tensor, causing valid expressions like tf.transpose(x, perm=[-1, 0]) to fail compilation.
2. Modular Axis Normalization
Given an input tensor of rank and a permutation vector , canonical axis normalization maps each entry via:
A valid permutation must then satisfy and pairwise distinctness ( for ).
Permutation perm () | Normalized | Before Fix | After Fix |
|---|---|---|---|
[-1, 0] | [1, 0] | Rejected by XLA | Compiles cleanly |
[-3, 0] | Out of range | Rejected by XLA | Explicit bounds error |
3. Implementation & Verification
XLA unit tests confirm negative permutation indices now compile and produce identical results to eager execution.
4. References
- TensorFlow Core API Specification,
tf.transposeNegative Permutation Axis Semantics.