Repository: tensorflow
Issue: NotImplementedError from tf.constant in trivial case
Labels: type:bug,TF 2.16

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

binary

### TensorFlow version

2.16.1

### Custom code

Yes

### OS platform and distribution

Linux Ubuntu 20.04

### Mobile device

_No response_

### Python version

3.10.12

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Trying to make a tensor that has the same value for all items in the batch, see the following bare minimum code. 
I get `NotImplementedError: cannot convert a symbolic tf.Tensor (custom_model_5_1/strided_slice:0) to a numpy array.`
I am not trying to use numpy, this is an internal error.

### Standalone code to reproduce the issue

```shell
import tensorflow as tf
import keras
import numpy as np

class CustomModel(keras.models.Model):
    def call(self, inputs):
        inputs_shape = tf.shape(inputs)
        return tf.constant(3.0, shape=(inputs_shape[0], 1), dtype=inputs.dtype)  # NotImplementedError
        #return 3.0 * tf.ones(shape=(inputs_shape[0], 1), dtype=inputs.dtype)  # OK

model = CustomModel()
model.compile(run_eagerly=False, loss="mse")  # OK if run_eagerly=True
model.fit(np.array([[0.0]]), np.array([[0.0]]))
```
```


### Relevant log output

```shell
{
	"name": "NotImplementedError",
	"message": "Exception encountered when calling CustomModel.call().

Cannot convert a symbolic tf.Tensor (custom_model_5_1/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported.

Arguments received by CustomModel.call():
  • inputs=tf.Tensor(shape=(None, 1), dtype=float32)",
	"stack": "---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[6], line 13
     11 model = CustomModel()
     12 model.compile(run_eagerly=False, loss=\"mse\")  # OK if run_eagerly=True
---> 13 model.fit(np.array([[0.0]]), np.array([[0.0]]))

File /usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    119     filtered_tb = _process_traceback_frames(e.__traceback__)
    120     # To get the full stack trace, call:
    121     # `keras.config.disable_traceback_filtering()`
--> 122     raise e.with_traceback(filtered_tb) from None
    123 finally:
    124     del filtered_tb

Cell In[6], line 8, in CustomModel.call(self, inputs)
      6 def call(self, inputs):
      7     inputs_shape = tf.shape(inputs)
----> 8     return tf.constant(3.0, shape=(inputs_shape[0], 1), dtype=inputs.dtype)

File /usr/local/lib/python3.10/dist-packages/numpy/core/fromnumeric.py:3100, in prod(a, axis, dtype, out, keepdims, initial, where)
   2979 @array_function_dispatch(_prod_dispatcher)
   2980 def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
   2981          initial=np._NoValue, where=np._NoValue):
   2982     \"\"\"
   2983     Return the product of array elements over a given axis.
   2984 
   (...)
   3098     10
   3099     \"\"\"
-> 3100     return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
   3101                           keepdims=keepdims, initial=initial, where=where)

File /usr/local/lib/python3.10/dist-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     85         else:
     86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

NotImplementedError: Exception encountered when calling CustomModel.call().

Cannot convert a symbolic tf.Tensor (custom_model_5_1/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported.

Arguments received by CustomModel.call():
  • inputs=tf.Tensor(shape=(None, 1), dtype=float32)"
}
```