tensorflow / tensorflow/tensorflow
`tf.raw_ops.AvgPool`: negative kernel size is not checked at shape inference step
Open
@Kayyuri is already working on this.
Since Apr 9, 2026.
comp:ops
stat:contribution welcome
TF 2.15
type:bug
- Dominant language
- C++
- Stars
- 200k
- Forks
- 76.9k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 433
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
source
TensorFlow version
tf 2.17
Custom code
Yes
OS platform and distribution
Linux Ubuntu 22.04 LTS
Mobile device
No response
Python version
3.11.7
Bazel version
6.5.0
GCC/compiler version
clang 16
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
Currently shape inference step of tf.raw_ops.AvgPool allows negative kernel size.
Note that debug build rejects it here:
TF_RETURN_IF_ERROR(GetWindowedOutputSizeFromDims(
c, in_rows_dim, kernel_rows, stride_rows, padding, &output_rows));
, where kernel_rows is converted to DimensionOrConstant and ends up with assertion failure here:
inline DimensionOrConstant::DimensionOrConstant(int64_t val) : val(val) {
DCHECK(val >= 0 || val == InferenceContext::kUnknownDim)
<< "Dimension must be non-negative or equal to "
"InferenceContext::kUnknownDim but got "
<< val;
}
Standalone code to reproduce the issue
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
x = tf.raw_ops.AvgPool(
value=tf.random.normal([1,1,1,1]),
ksize=[1,-2,1,1],
strides=[1,1,1,1],
padding="SAME",
data_format='NHWC',
name=None
)
print(x)
Relevant log output
Release Build:
Tensor("AvgPool:0", shape=(1, 1, 1, 1), dtype=float32)
Debug Build:
2024-02-23 22:18:43.783609: F ./tensorflow/core/framework/shape_inference.h:891] Check failed: val >= 0 || val == InferenceContext::kUnknownDim Dimension must be non-negative or equal to InferenceContext::kUnknownDim but got -2
Aborted (core dumped)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.