keras-team/keras · error · ValueError

input with shape does not have enough dimensions for all…

Error message

input with shape {shape} does not have enough dimensions for all core dimensions {core_dims}

What it means

Guard in _vectorize_update_dim_sizes (input branch): an argument passed to the vectorized function has fewer trailing dimensions than its declared core dimensions in the gufunc signature, so the core dims cannot be aligned with the argument's shape.

Solutions

  1. Reduce the number of core dimensions declared for that argument in the signature (e.g. '(n,m)' -> '(n)').
  2. Pass an argument whose rank is at least len(core_dims), adding leading batch dimensions as needed.
  3. Move dimensions that vary per-call into the excluded set via vectorize(func, excluded=[...]).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/common/backend_utils.py:490 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/d31c1899aa4375ad. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/common/backend_utils.py:490

    signature,
):
    if not re.match(_SIGNATURE, signature):
        raise ValueError(f"not a valid gufunc signature: {signature}")
    args, retvals = (
        [
            tuple(re.findall(_DIMENSION_NAME, arg))
            for arg in re.findall(_ARGUMENT, arg_list)
        ]
        for arg_list in signature.split("->")
    )
    return args, retvals


def _vectorize_update_dim_sizes(dim_sizes, shape, core_dims, is_input=True):
    num_core_dims = len(core_dims)
    if is_input:
        if len(shape) < num_core_dims:
            raise ValueError(
                f"input with shape {shape} does not "
                "have enough dimensions for all core "
                f"dimensions {core_dims}"
            )
    else:
        if len(shape) != num_core_dims:
            raise ValueError(
                f"output shape {shape} does not "
                f"match core dimensions {core_dims}"
            )

    core_shape = shape[-num_core_dims:] if core_dims else ()
    for dim, size in zip(core_dims, core_shape):
        if dim not in dim_sizes:
            dim_sizes[dim] = size
        elif size != dim_sizes[dim]:
            raise ValueError(
                f"inconsistent size for core dimension {dim}: "

View on GitHub (pinned to 7a34a03db6)