keras-team/keras · error · TypeError

wrong number of positional arguments: expected

Error message

wrong number of positional arguments: expected {len(input_core_dims)}, got {len(args)}

What it means

Guard in _vectorize_parse_input_dimensions: the number of positional arguments supplied at call time does not equal the number of argument groups declared in the gufunc signature, so arguments cannot be paired with their core dimensions.

Solutions

  1. Call the vectorized function with exactly one positional argument per signature input group.
  2. Pass constants via keyword or the excluded parameter instead of as extra positional args.
  3. Simplify the signature, e.g. '()->()' repeated, to match the actual call pattern.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    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,
):
    from keras.src import ops

    if len(args) != len(input_core_dims):
        raise TypeError(
            "wrong number of positional arguments: "
            f"expected {len(input_core_dims)}, got {len(args)}"
        )
    shapes = []
    dim_sizes = {}
    for arg, core_dims in zip(args, input_core_dims):
        _vectorize_update_dim_sizes(
            dim_sizes, arg.shape, core_dims, is_input=True
        )
        ndim = arg.ndim - len(core_dims)
        shapes.append(arg.shape[:ndim])
    broadcast_shape = shapes[0]
    for s in shapes:
        broadcast_shape = ops.broadcast_shapes(broadcast_shape, s)
    return broadcast_shape, dim_sizes


def _vectorize_check_output_dims(

View on GitHub (pinned to 7a34a03db6)