Skip to content

XLA fails to validate an out-of-range dynamic num_bits in QuantizeAndDequantizeV3 (num_bits ≤ 0): eager and plain graph raise InvalidArgumentError, but jit_compile=True silently produces a nonsensical result #127914

Description

@tinywisdom

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

binary

TensorFlow version

2.22.0-dev20260921(GIT_VERSION v1.12.1-145339-g0181b74d80f)

Custom code

Yes

OS platform and distribution

Linux Ubuntu 22.04(kernel 6.8, glibc 2.35)

Mobile device

N/A

Python version

3.12.13

Bazel version

N/A(binary install)

GCC/compiler version

N/A(binary install)

CUDA/cuDNN version

CUDA 12.9 / cuDNN 9.26(pip nvidia-*-cu12)

GPU model and memory

NVIDIA RTX A6000 (48 GB)

Current behavior?

tf.raw_ops.QuantizeAndDequantizeV3 takes a dynamic num_bits input. Eager execution and plain
tf.function (graph) both validate it and raise InvalidArgumentError when num_bits ≤ 0. Under
jit_compile=True (XLA), the same call silently returns a result instead of raising.

This is not merely "backends disagree on invalid input": the eager V3 kernel reads the dynamic
num_bits and explicitly requires num_bits_val > 0 (else InvalidArgumentError), whereas the XLA V3
lowering reads ctx->Input(3) and directly computes 2^num_bits with no range check — so the XLA
path is missing the input constraint the eager path enforces. TF already treats validation gaps for this
op as bugs (e.g. #99456 / #87421: hard crash / Check failed: d >= 0 instead of InvalidArgumentError).

Expected: compiled matches eager/graph — num_bits ≤ 0 raises InvalidArgumentError.
Actual: jit_compile=True silently produces a result (num_bits=0 → [-0,…]; num_bits=-1 → [-4,…]).

Standalone code to reproduce the issue

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
import tensorflow as tf

inp = tf.constant([-1., 0., 1., 2.], tf.float32)
lo, hi = tf.constant(-1., tf.float32), tf.constant(2., tf.float32)

def g(x):
    return tf.raw_ops.QuantizeAndDequantizeV3(
        input=x, input_min=lo, input_max=hi,
        num_bits=tf.constant(0, tf.int32), range_given=True)   # num_bits=0 is out of range

print("eager:", end=" ")
try: print(g(inp).numpy())
except Exception as e: print("RAISED", type(e).__name__)                 # InvalidArgumentError

print("graph:", end=" ")
try: print(tf.function(g)(inp).numpy())
except Exception as e: print("RAISED", type(e).__name__)                 # InvalidArgumentError

print("xla  :", tf.function(g, jit_compile=True)(inp).numpy())           # [-0. -0. -0. -0.]  <-- silent, WRONG

Relevant log output

eager: RAISED InvalidArgumentError
graph: RAISED InvalidArgumentError
xla  : [-0. -0. -0. -0.]          # jit_compile silently accepts an out-of-range num_bits

Activity

  1. added
    comp:ops
    on Sep 23, 2026
  2. added
    2.21.0
    on Sep 23, 2026
  3. Kayyuri commented on Sep 23, 2026

    @Kayyuri

    Hi @tinywisdom, Thank you for reporting this issue!

    You've clearly demonstrated that the XLA compilation for tf.raw_ops.QuantizeAndDequantizeV3 lacks the necessary input validation for num_bits > 0. This causes it to produce silent incorrect results when num_bits is out of range, whereas graph and eager execution correctly raises an InvalidArgumentError.

    We’ll investigate the issue on our end and provide an update.

  4. added 3 commits that reference this issue on Oct 6, 2026
    7386b9d
    5f0aa8f
    8d11fb0
  5. Kayyuri commented on Oct 14, 2026

    @Kayyuri

    Hi @tinywisdom,
    A fix for this issue has been proposed in this PR. Once it is merged, this issue will be resolved.

    Big thanks to @adi-IL for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.

  6. google-ml-butler commented on Oct 15, 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

2.21.0awaiting PR mergecomp:opscomp:xlatype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions