keras-team/keras · error · ValueError

Array inputs to associative_scan must have the same first di

Error message

Array inputs to associative_scan must have the same first dimension. (saw: [tf.shape(elem) for elem in elems_flat])

What it means

Error "Array inputs to associative_scan must have the same first dimension. (saw: [tf.shape(elem) for elem in elems_flat])" thrown in keras-team/keras.

Source

Thrown at keras/src/backend/tensorflow/core.py:427

    elems_flat = tree.flatten(elems)
    elems_flat = [tf.convert_to_tensor(elem) for elem in elems_flat]
    if reverse:
        elems_flat = [tf.reverse(elem, [axis]) for elem in elems_flat]

    def _combine(a_flat, b_flat):
        a = tree.pack_sequence_as(elems, a_flat)
        b = tree.pack_sequence_as(elems, b_flat)
        c = f(a, b)
        c_flat = tree.flatten(c)
        return c_flat

    def _get_dim(x):
        return shape(x)[axis]

    # TODO add constant dim check
    num_elems = _get_dim(elems_flat[0])
    if not all(_get_dim(elem) == num_elems for elem in elems_flat[1:]):
        raise ValueError(
            "Array inputs to associative_scan must have the same "
            "first dimension. (saw: {})".format(
                [tf.shape(elem) for elem in elems_flat]
            )
        )

    def _interleave(a, b, axis):
        # [a b c ...] [d e f ...] -> [a d b e c f ...]
        num_elems_a = (
            a.shape[axis] if a.shape[axis] is not None else tf.shape(a)[axis]
        )
        num_elems_b = (
            b.shape[axis] if b.shape[axis] is not None else tf.shape(b)[axis]
        )

        # Note that interleaving implies rank(a)==rank(b).
        axis = tf.where(axis >= 0, axis, tf.rank(a) + axis)
        axis = (

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/tensorflow/core.py:427 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/0bbc32b54e9f8e61. Report an issue: GitHub.