PR #122402
tensorflow/tensorflow · NN Ops · Merged · 3 files changed
Fixed a dynamic TypeError in tf.nn.weighted_moments when axes is passed as a constant tf.Tensor instead of a Python list, normalizing axes via tensor_util.constant_value before squeeze.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 122402 --repo tensorflow/tensorflowFixed a dynamic TypeError in tf.nn.weighted_moments when axes is passed as a constant tf.Tensor instead of a Python list, normalizing axes via tensor_util.constant_value before squeeze.
File-by-File Modification Breakdown (3)
- +1 / -0
tensorflow/python/ops/BUILD
Bazel build dependencies and test targets
- +64 / -0
tensorflow/python/ops/nn_batchnorm_test.py
Python/XLA regression test suite verifying edge-case behavior
- +16 / -2
tensorflow/python/ops/nn_impl.py
Neural network Python op implementation and axis normalization
Changed Files (3)
1. Introduction & Motivation
In TensorFlow's neural network normalization ops, tf.nn.weighted_moments reduces across user-specified axes. When keep_dims=False, the implementation calls array_ops.squeeze(x, axis=axes). In eager mode, squeeze_eager_fallback strictly requires axis to be a Python list or tuple, causing a dynamic TypeError whenever axes was passed as a tf.Tensor.
2. Mathematical & Shape Flow
weighted_moments computes the weighted mean and variance over axes:
3. Verification & References
Added testTensorAxesKeepdimsFalse in nn_batchnorm_test.py (regression test for GitHub issue #101580).
- Ioffe & Szegedy, Batch Normalization: Accelerating Deep Network Training, ICML 2015.