keras-team/keras · error · ValueError

cycle detected in type promotion lattice for node

Error message

cycle detected in type promotion lattice for node {n}

What it means

Guard in _make_lattice_upper_bounds: while transitively closing the type-promotion lattice, a node was found among its own upper bounds, meaning the static lattice definition contains a cycle. This is an internal-configuration error in Keras's dtype machinery, not a user-input error.

Solutions

  1. This indicates a bug in Keras's dtype lattice definition or a modified Keras install — report it with the traceback to the Keras maintainers.
  2. As a workaround, reinstall/upgrade Keras to a stock release where the lattice is well-formed.
  3. Avoid monkey-patching backend dtypes or the promotion lattice.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at keras/src/backend/common/dtypes.py:102 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/c1bc73dda7d2cb86. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/common/dtypes.py:102

        f2: [f4],
        f4: [f8, c64],
        f8: [c128],
        c64: [c128],
        c128: [],
    }
    return out


def _make_lattice_upper_bounds():
    lattice = _type_promotion_lattice()
    upper_bounds = {node: {node} for node in lattice}
    for n in lattice:
        while True:
            new_upper_bounds = set().union(
                *(lattice[b] for b in upper_bounds[n])
            )
            if n in new_upper_bounds:
                raise ValueError(
                    f"cycle detected in type promotion lattice for node {n}"
                )
            if new_upper_bounds.issubset(upper_bounds[n]):
                break
            upper_bounds[n] |= new_upper_bounds
    return upper_bounds


LATTICE_UPPER_BOUNDS = _make_lattice_upper_bounds()


@functools.lru_cache(512)
def _least_upper_bound(*nodes):
    """Compute the least upper bound of a set of nodes.

    Args:
        nodes: sequence of entries from dtypes + weak_types

View on GitHub (pinned to 7a34a03db6)