keras-team/keras · error · ValueError

`swapaxes` does not support tensors with dynamic rank for…

Error message

`swapaxes` does not support tensors with dynamic rank for the OpenVINO backend.

What it means

Raised by keras.ops.numpy.swapaxes in the OpenVINO backend when the input's rank is dynamic. Building the transpose permutation for swapped axes requires a static rank at graph-construction time.

Solutions

  1. Pass a tensor with statically known rank
  2. Rebuild the graph so shapes are concrete
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/openvino/numpy.py:4450 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/71ecc4c94cf1c657. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/openvino/numpy.py:4450

        ref, elems[i] = _align_operand_types(ref, elems[i], "stack()")
    elems[0] = ref
    const_axis = ov_opset.constant(axis, Type.i32).output(0)
    elems = [ov_opset.unsqueeze(e, const_axis).output(0) for e in elems]
    res = ov_opset.concat(elems, axis).output(0)
    return OpenVINOKerasTensor(res)


def std(x, axis=None, keepdims=False):
    var_x = var(x, axis, keepdims)
    std_dev = ov_opset.sqrt(var_x.output).output(0)
    return OpenVINOKerasTensor(std_dev)


def swapaxes(x, axis1, axis2):
    x = get_ov_output(x)
    x_shape = x.get_partial_shape()
    if x_shape.rank.is_dynamic:
        raise ValueError(
            "`swapaxes` does not support tensors with dynamic rank for the "
            "OpenVINO backend."
        )
    rank = x_shape.rank.get_length()
    axis1 = canonicalize_axis(axis1, rank)
    axis2 = canonicalize_axis(axis2, rank)
    axes = list(range(rank))
    axes[axis1], axes[axis2] = axes[axis2], axes[axis1]
    result = ov_opset.transpose(x, ov_opset.constant(axes, Type.i32))
    return OpenVINOKerasTensor(result.output(0))


def take(x, indices, axis=None):
    x = get_ov_output(x)
    indices = get_ov_output(indices)
    if axis is None:
        target_shape = ov_opset.constant([-1], dtype=Type.i32).output(0)
        x = ov_opset.reshape(x, target_shape, False).output(0)

View on GitHub (pinned to 7a34a03db6)