Skip to content

tf.image.resize gradients fail for half/bfloat16/float64 with antialias or lanczos/gaussian/mitchellcubic, and are silently None for bicubic half/bfloat16 #129737

Closed

Description

@bodapatisaikrishna

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

binary

TensorFlow version

tf-nightly 2.23.0-dev20261028 (git v1.12.1-148391-g87a97a3655f)

Custom code

Yes

OS platform and distribution

macOS 15.7.2 (arm64)

Mobile device

No response

Python version

3.12.0

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Backprop through tf.image.resize is broken for half and bfloat16 images in two ways, which makes mixed precision training fail for models that resize inside the graph:

  1. With antialias=True, or method = lanczos3/lanczos5/gaussian/mitchellcubic, the gradient raises InvalidArgumentError for any dtype other than float32 (float64 too). Those go through ScaleAndTranslate, which accepts half/bfloat16/double images, but ScaleAndTranslateGrad is declared T: {float} for both grads and original_image and only has a float32 kernel. The registered gradient (image_grad.py#L143-L150) passes the original image through as is, so the grad op rejects it. The kernel only reads the image's shape.

  2. With method="bicubic" (no antialias), the gradient for half/bfloat16 images is silently None. _ResizeBicubicGrad (image_grad.py#L164-L172) only computes it for float32/float64 because ResizeBicubicGrad has no 16-bit kernel. No error is raised, so the layers before the resize just stop training.

bilinear and nearest without antialias already return gradients in the input dtype for half, bfloat16 and float64, so these two look like gaps rather than intended restrictions.

Expected: gradients in the input's dtype, like ResizeBilinearGrad returns.

Standalone code to reproduce the issue

import tensorflow as tf

for dtype in [tf.float32, tf.float16, tf.bfloat16, tf.float64]:
  x = tf.random.uniform([1, 8, 8, 3], dtype=tf.float32)
  x = tf.cast(x, dtype)
  with tf.GradientTape(persistent=True) as tape:
    tape.watch(x)
    y1 = tf.image.resize(x, [4, 4], method="bilinear", antialias=True)
    y2 = tf.image.resize(x, [4, 4], method="bicubic")
  g1, g2 = None, tape.gradient(y2, x)
  try:
    g1 = tape.gradient(y1, x).dtype.name
  except tf.errors.InvalidArgumentError as e:
    g1 = "error: " + e.message.splitlines()[0]
  print(dtype.name, "| antialias:", g1, "| bicubic:", g2 if g2 is None else g2.dtype.name)

Relevant log output

float32 | antialias: float32 | bicubic: float32
float16 | antialias: error: cannot compute ScaleAndTranslateGrad as input #1(zero-based) was expected to be a float tensor but is a half tensor [Op:ScaleAndTranslateGrad] name:  | bicubic: None
bfloat16 | antialias: error: cannot compute ScaleAndTranslateGrad as input #1(zero-based) was expected to be a float tensor but is a bfloat16 tensor [Op:ScaleAndTranslateGrad] name:  | bicubic: None
float64 | antialias: error: cannot compute ScaleAndTranslateGrad as input #1(zero-based) was expected to be a float tensor but is a double tensor [Op:ScaleAndTranslateGrad] name:  | bicubic: float64

I have a small fix and will open a PR.

Activity

  1. added
    awaiting PR merge
    2.21.0
    comp:ops
    on Oct 30, 2026
  2. Venkat6871 commented on Nov 2, 2026

    @Venkat6871
    Contributor

    Hi @bodapatisaikrishna ,
    Thank you for reporting this issue and raising the PR to address it. A fix has been proposed in PR, and the issue will be resolved once it is merged.
    We truly appreciate your initiative and effort in contributing this fix.

  3. google-ml-butler commented on Nov 2, 2026

    @google-ml-butler

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

  4. added a commit that references this issue on Nov 2, 2026
    c2c992d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

2.21.0awaiting PR mergecomp:opstype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions