{"record":{"id":"c5163f00a2c79a69","repo":"keras-team/keras","slug":"to-use-nnx-with-the-jax-backend-you-must-install","errorCode":null,"errorMessage":"To use NNX with the JAX backend, you must install `flax`.","messagePattern":"To use NNX with the JAX backend, you must install `flax`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/config.py","lineNumber":260,"sourceCode":"    \"\"\"Checks whether NNX specific features are enabled for the JAX backend.\n\n    Returns:\n        bool: `True` if NNX backend features are enabled, `False` otherwise.\n        Defaults to `False`.\n    \"\"\"\n    return _NNX_ENABLED\n\n\ndef set_nnx_enabled(value):\n    global _NNX_ENABLED\n    from keras.src.backend.common import global_state\n\n    _NNX_ENABLED = bool(value)\n    if _NNX_ENABLED:\n        try:\n            from flax import nnx  # noqa F401\n        except ImportError:\n            raise ImportError(\n                \"To use NNX with the JAX backend, you must install `flax`.\"\n            )\n    global_state.set_global_attribute(\"nnx_enabled\", bool(value))\n\n\ndef standardize_data_format(data_format):\n    if data_format is None:\n        return image_data_format()\n    data_format = str(data_format).lower()\n    if data_format not in {\"channels_first\", \"channels_last\"}:\n        raise ValueError(\n            \"The `data_format` argument must be one of \"\n            \"{'channels_first', 'channels_last'}. \"\n            f\"Received: data_format={data_format}\"\n        )\n    return data_format\n\n","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/config.py#L242-L278","documentation":"Raised by keras.config.set_nnx_enabled(True) when the flax package cannot be imported. NNX features for the JAX backend are built on flax.nnx, so the import guard in this setter fails with an ImportError when flax is missing.","triggerScenarios":"Thrown at keras/src/backend/config.py:260 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Install flax: pip install flax (an optional dependency for JAX-backend NNX features).","If NNX is not intended, do not enable it (set_nnx_enabled(False) or leave it off).","Verify with: python -c \"from flax import nnx\"."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}