Skip to content

tf.raw_ops.AvgPool: negative kernel size is not checked at shape inference step #63034

Closed

Description

@Sehun0819

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)

Activity

  1. Venkat6871 commented on Feb 26, 2024

    @Venkat6871
    Contributor

    Hi @Sehun0819 ,

    Sorry for the delay, I tried to run your code on Colab using TF v2.15 and nightly. Please find the gist here for reference.
    Thank you!

  2. added
    comp:ops
    TF 2.15
    subtype: ubuntu/linux
    on Feb 26, 2024
  3. added a commit that references this issue on Feb 29, 2024
  4. added
    awaiting review
    and removed
    subtype: ubuntu/linux
    on Mar 5, 2024
  5. removed
    awaiting review
    on Jun 3, 2026
  6. Kayyuri commented on Jun 3, 2026

    @Kayyuri

    Hi @Sehun0819,
    Thank you so much for filing this issue! We truly appreciate your support. At the moment, this request is not prioritized and mark it for community contributions. If you would like to contribute on a fix, please feel free to fork the repository and submit a pull request in accordance with the TensorFlow CONTRIBUTION GUIDELINES and link this issue in your PR to ensure the maintainers can easily review and collaborate.
    To avoid duplicate work, please leave a comment here if you decide to take it on!

    Thank you again for your interest and we look forward to seeing your contributions!

  7. added
    stat:contribution welcome
    on Jun 3, 2026
  8. Venkat6871 commented on Sep 24, 2026

    @Venkat6871
    Contributor

    Hi @Sehun0819 ,

    We are closing this issue due to inactivity. If this is still relevant and you would like to work on it, please feel free to reopen the issue or submit a pull request referencing it.

    Thank you for your understanding.

  9. google-ml-butler commented on Sep 24, 2026

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

TF 2.15comp:opsstat:contribution welcometype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions