When using keras.ops.searchsorted within a Keras model built using the Functional API or subclassed tf.keras.Model, the operation fails with symbolic tensors. This limits its use in graph mode or during model construction, where symbolic tensors are standard.

import tensorflow as tf from keras import layers, Model from keras import ops

class TestModel(tf.keras.Model): def init(self): super().init()

def call(self, inputs):
    bins = ops.convert_to_tensor([0.0, 0.5, 1.0])
    return ops.searchsorted(bins, inputs)

model = TestModel()

Symbolic input

inputs = tf.keras.Input(shape=(1,)) outputs = model(inputs)

import tensorflow as tf from keras import layers, Model from keras import ops

class TestModel(tf.keras.Model): def init(self): super().init()

def call(self, inputs):
    bins = ops.convert_to_tensor([0.0, 0.5, 1.0])
    return ops.searchsorted(bins, inputs)

model = TestModel()

Symbolic input

inputs = tf.keras.Input(shape=(1,)) outputs = model(inputs)

ValueError: searchsorted only supports eager tensors. Received symbolic tensor:

Environment:

TensorFlow: 2.15+ (or Keras 3.x)

Backend: TensorFlow

Keras Version: 3.x (standalone or via TensorFlow)

Execution mode: Graph (Symbolic)