keras-team/keras · error · ValueError

Received `None` value for `axis`

Error message

Received `None` value for `axis`

What it means

Sentinel validation in the JAX sparse backend's axis-normalization helper (_all_axes_sum or similar in sparse.py): axis is the user-supplied reduction/insertion axis argument, and None is explicitly rejected because the helper must enumerate concrete axes to compute output shapes and broadcast dimensions.

Solutions

  1. Pass an explicit int or tuple of ints, e.g. axis=1 or axis=(1, 2), instead of None
  2. To reduce over all axes, enumerate them explicitly (e.g. axis=tuple(range(x.ndim))
  3. Check calling code for a default of None that should be a concrete axis
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/jax/sparse.py:29 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/584b4546417205b8. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/jax/sparse.py:29

    Args:
        axis: single int or a tuple of ints for the axis argument. The list of
          dimensions to reduce or insert.
        input_shape: the shape of the input as a tuple ints.
        insert_dims: `False` turns dimensions in `axis` to 1s (use case:
          reduction along `axis` with `keep_dims=True`). `True`, inserts 1s
          according to `axis` (use case: `expand_dims`).
    Returns:
        A tuple of three lists
        - The canonical value for `axis`: always a list, negative values have
          been resolved and values are sorted in ascending order.
        - The output shape: `input_shape` with 1s at the indices in `axis`, for
          use as the `shape` argument of `broadcast_in_dim`.
        - The broadcast dimensions: list of dimensions not in `axis`, for use as
          the `broadcast_dimensions` argument of `broadcast_in_dim`.
    """
    if axis is None:
        raise ValueError("Received `None` value for `axis`")
    if isinstance(axis, int):
        axis = (axis,)
    # Check uniqueness.
    if len(set(axis)) != len(axis):
        raise ValueError(f"Repeated axis in `axis`: {axis}")
    result_dims = len(input_shape)
    if insert_dims:
        result_dims += len(axis)

    # Resolve negative values.
    canonical_axis = []
    for a in axis:
        if not -result_dims <= a < result_dims:
            raise ValueError(
                f"In `axis`, axis {a} is out of bounds for array "
                f"of dimension {result_dims}"
            )
        if a < 0:

View on GitHub (pinned to 7a34a03db6)