keras-team/keras · error · ValueError
diagonal requires input tensor with rank >= 2.Given rank: {r
Error message
diagonal requires input tensor with rank >= 2.Given rank: {rank} What it means
Error "diagonal requires input tensor with rank >= 2.Given rank: {rank}" thrown in keras-team/keras.
Source
Thrown at keras/src/backend/openvino/numpy.py:1675
neg_k_const = ov_opset.constant(-k_val, dtype=Type.i32).output(0)
rows = ov_opset.add(rng, neg_k_const).output(0)
cols = rng
rows_expanded = ov_opset.reshape(rows, [-1, 1], False).output(0)
cols_expanded = ov_opset.reshape(cols, [-1, 1], False).output(0)
indices = ov_opset.concat([rows_expanded, cols_expanded], 1).output(0)
result = ov_opset.scatter_nd_update(zeros_mat, indices, v_flat).output(0)
return OpenVINOKerasTensor(result)
def diagonal(x, offset=0, axis1=0, axis2=1):
x = get_ov_output(x)
rank = x.get_partial_shape().rank.get_length()
if rank is None:
raise ValueError("`diagonal` requires input tensor with static rank.")
if rank < 2:
raise ValueError(
f"diagonal requires input tensor with rank >= 2.Given rank: {rank}"
)
axis1 = canonicalize_axis(axis1, rank)
axis2 = canonicalize_axis(axis2, rank)
if axis1 == axis2:
raise ValueError("`axis1` and `axis2` cannot be the same.")
perm_order = [axis1, axis2] + [
i for i in range(rank) if i != axis1 and i != axis2
]
perm_const = ov_opset.constant(perm_order, dtype=Type.i32).output(0)
x_transposed = ov_opset.transpose(x, perm_const)
# Build the (row, col) index pairs in the graph so the diagonalized axes
# may be dynamic.
zero = ov_opset.constant(0, Type.i32).output(0)
one = ov_opset.constant(1, Type.i32).output(0)
offset_const = ov_opset.constant(View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/openvino/numpy.py:1675 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/820456b1162f1752.
Report an issue: GitHub.