keras-team/keras · error · ValueError

output shape does not match core dimensions

Error message

output shape {shape} does not match core dimensions {core_dims}

What it means

Guard in _vectorize_update_dim_sizes (output branch): the vectorized function returned a tensor whose rank does not exactly equal the number of core dimensions declared for that output in the gufunc signature — unlike inputs, output core dims must match exactly with no extra leading dimensions.

Solutions

  1. Make the wrapped function return tensors whose rank equals the declared output core dims (e.g. exactly 1D for '(n)').
  2. Adjust the signature's output part to the actual output rank.
  3. Strip accidental extra axes with a reshape/squeeze inside the wrapped function.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

            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}: "
                f"{size} vs {dim_sizes[dim]}"
            )


def _vectorize_parse_input_dimensions(
    args,
    input_core_dims,

View on GitHub (pinned to 7a34a03db6)