keras-team/keras · error · ImportError

To use NNX with the JAX backend, you must install `flax`.

Error message

To use NNX with the JAX backend, you must install `flax`.

What it means

Error "To use NNX with the JAX backend, you must install `flax`." thrown in keras-team/keras.

Source

Thrown at keras/src/backend/config.py:260

    """Checks whether NNX specific features are enabled for the JAX backend.

    Returns:
        bool: `True` if NNX backend features are enabled, `False` otherwise.
        Defaults to `False`.
    """
    return _NNX_ENABLED


def set_nnx_enabled(value):
    global _NNX_ENABLED
    from keras.src.backend.common import global_state

    _NNX_ENABLED = bool(value)
    if _NNX_ENABLED:
        try:
            from flax import nnx  # noqa F401
        except ImportError:
            raise ImportError(
                "To use NNX with the JAX backend, you must install `flax`."
            )
    global_state.set_global_attribute("nnx_enabled", bool(value))


def standardize_data_format(data_format):
    if data_format is None:
        return image_data_format()
    data_format = str(data_format).lower()
    if data_format not in {"channels_first", "channels_last"}:
        raise ValueError(
            "The `data_format` argument must be one of "
            "{'channels_first', 'channels_last'}. "
            f"Received: data_format={data_format}"
        )
    return data_format

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/config.py:260 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/c5163f00a2c79a69. Report an issue: GitHub.