Repository navigation
Closed
Labels
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
source
TensorFlow version
tf2.18.0
Custom code
Yes
OS platform and distribution
linux ubuntu 24.04
Mobile device
No response
Python version
3.12
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
When using @tf.function(jit_compile=True) (XLA compilation), creating a tf.range with dtype=tf.float16 causes a ValueError indicating unsupported dtype. The same code works without XLA compilation.
Standalone code to reproduce the issue
import tensorflow as tf
class TestModel(tf.keras.Model):
def __init__(self):
super().__init__()
self.d1 = tf.keras.layers.Dense(32)
self.d2 = tf.keras.layers.Dense(16)
self.d3 = tf.keras.layers.Dense(8)
def call(self, x):
processed_outputs = []
for i in range(5):
if i < 3:
processed_outputs.append(tf.nn.relu(self.d1(x)))
else:
processed_outputs.append(tf.nn.sigmoid(self.d2(x)))
indices = tf.range(0, 10, dtype=tf.float16)
accumulated = tf.zeros_like(x)
for j in range(len(indices)):
accumulated += tf.cast(indices[j], x.dtype) * x
output = tf.nn.tanh(self.d3(x))
return output
def get_default_model():
return TestModel()
def get_sample_inputs():
x = tf.random.normal([4, 16])
return (x,)
def main():
model = get_default_model()
inputs = get_sample_inputs()
output = model(*inputs)
print(f'input shape: {inputs[0].shape}')
print(f'output shape: {output.shape}')
@tf.function(jit_compile=True)
def compiled_forward(*args):
return model(*args)
compiled_out = compiled_forward(*inputs)
print('XLA Output shape:', compiled_out.shape)
if __name__ == '__main__':
main()Relevant log output
input shape: (4, 16)
output shape: (4, 8)
Traceback (most recent call last):
...line 18, in call
indices = tf.range(0, 10, dtype=tf.float16)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: in user code:
...
ValueError: Exception encountered when calling TestModel.call().
Unsupported dtype19 for '{{node test_model_1/range}} = Range[Tidx=DT_HALF](test_model_1/range/start, test_model_1/range/limit, test_model_1/range/delta)' with input shapes: [], [], [] and with computed input tensors: input[0] = <0>, input[1] = <10>, input[2] = <1>.
Arguments received by TestModel.call():
• x=tf.Tensor(shape=(4, 16), dtype=float32)
Activity
avmohansai commentedon Mar 30, 2026
Hi @Venkat6871 ,
I Was able to reproduce the issue on Colab using
TF v2.18.0,TF v2.21.0andTF-nightly,Please find the gist here for reference.Thank you.
Venkat6871 commentedon Aug 28, 2026
Hi @Blooming-Tree ,
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!
Venkat6871 commentedon Sep 1, 2026
Hi @Blooming-Tree ,
Thank you for raising your concern here.
A fix for this issue has been proposed in this PR. Once it is merged, this issue will be resolved.
Hi @adi-IL ,
Thank you for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.
google-ml-butler commentedon Sep 2, 2026
Are you satisfied with the resolution of your issue?
Yes
No