keras-team/keras · error · ValueError

`pad` operation supports only scalar pad value in constant…

Error message

`pad` operation supports only scalar pad value in constant mode with the openvino backend. Received: constant_values={constant_values}

What it means

Raised by keras.ops.numpy.pad in the OpenVINO backend when constant_values is not a plain scalar number (int/float/np.integer/np.floating) in constant mode. The OpenVINO Pad op takes a single scalar fill value, so arrays or per-edge values are rejected.

Solutions

  1. Pass a single Python/NumPy scalar as constant_values (e.g. 0.0)
  2. For per-position fill values, pad manually or use a backend that supports them
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    result = ov_opset.multiply(x1_reshaped, x2_reshaped).output(0)

    return OpenVINOKerasTensor(result)


def pad(x, pad_width, mode="constant", constant_values=None):
    x = get_ov_output(x)
    pad_value = None
    if constant_values is not None:
        if mode != "constant":
            raise ValueError(
                "Argument `constant_values` can only be "
                "provided when `mode == 'constant'`. "
                f"Received: mode={mode}"
            )
        if not isinstance(
            constant_values, (int, float, np.integer, np.floating)
        ):
            raise ValueError(
                "`pad` operation supports only scalar pad value "
                "in constant mode with the openvino backend. "
                f"Received: constant_values={constant_values}"
            )
        pad_value = ov_opset.constant(
            constant_values, x.get_element_type()
        ).output(0)

    # split pad_width into two tensors pads_begin and pads_end
    pads_begin = []
    pads_end = []
    for pads_pair in pad_width:
        pads_begin.append(pads_pair[0])
        pads_end.append(pads_pair[1])
    pads_begin = ov_opset.constant(pads_begin, Type.i32).output(0)
    pads_end = ov_opset.constant(pads_end, Type.i32).output(0)
    return OpenVINOKerasTensor(
        ov_opset.pad(x, pads_begin, pads_end, mode, pad_value).output(0)

View on GitHub (pinned to 7a34a03db6)