- 
                Notifications
    You must be signed in to change notification settings 
- Fork 19.6k
Description
OS: Ubuntu 24.04.2 LTS
Python Version: 3.12.12
Keras Version: 3.11.3
TF Version: 2.20.0
Description
When calling keras.ops.quantile with arguments that results in output dimension > 1, the call results in a ValueError instead of completing successfully.
Reproduction
import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import numpy as np
import tensorflow as tf
from keras import ops
@tf.function
def run_quantile():
    x = np.array([[1, 2, 3], [4, 5, 6]])
    q = [0.5]
    return ops.quantile(x, q, axis=1)
result = run_quantile()
expected_output = np.array([[2, 5]])
assert(np.allclose(expected_output, result))Expected Result
Assert passes, program terminates without exceptions.
Actual Result
Exception is raised in the call to ops.quantile:
ValueError: Tried to convert 'perm' to a tensor and failed. Error: Expected values deque([1, 0]) to be a dense tensor with shape [], but got shape [2].
Root Cause
When in graph mode, python arguments are automatically converted to Tensorflow tensors. The final transpose call in the internal _quantile function in keras.ops passes a deque to the perm argument. This fails to be converted to a tensor causing the crash.
Metadata
Metadata
Assignees
Labels
No labels