xai-org/x-algorithm · error · ValueError

Unable to create named shape with unnamed dimensions (shape:

Error message

Unable to create named shape with unnamed dimensions (shape: {shape})

What it means

NamedShape.__init__ requires that any non-empty shape be accompanied by an equal-length tuple of dimension names. Constructing a NamedShape with a non-empty shape but names=None raises this ValueError immediately, because downstream sharding logic needs names to map axes to mesh axes.

Source

Thrown at phoenix/xrex/models/sharding_context.py:33

rank_logger = logging.getLogger("rank")


PyTree = Any


def axis_group_size(axis_names: PyTree, mesh: Mesh) -> int:
    flattened_axis_names, _ = jax.tree.flatten(axis_names)
    if not flattened_axis_names:
        return 0
    return math.prod([mesh.shape[n] for n in flattened_axis_names])


class NamedShape:
    names: tuple[str, ...] | None

    def __init__(self, shape: Shape | None = None, names: tuple[str, ...] | None = None):
        if names is None and len(shape) > 0:
            raise ValueError(
                f"Unable to create named shape with unnamed dimensions (shape: {shape})"
            )
        if names is not None and len(names) != len(shape):
            raise ValueError(
                f"Number of names must match number of dimensions (shape: {shape}, names: {names})"
            )
        self.shape = shape
        self.names = names

    def __repr__(self) -> str:
        shape_str = ", ".join(
            f"{name or 'unnamed'}={size}" for name, size in zip(self.names, self.shape)
        )
        return f"NamedShape({shape_str})"


class ShardingContext:
    def __init__(

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Pass a names tuple with one entry per dimension: NamedShape(shape, ("batch", "features"))
  2. If the shape is genuinely scalar/empty, pass an empty shape so len(shape)==0 skips the check

Example fix

# before
ns = NamedShape(x.shape)
# after
ns = NamedShape(x.shape, ("batch", "model", "features"))
Defensive patterns

Strategy: validation

Validate before calling

assert names is not None or not shape, "NamedShape needs names for non-empty shapes"

Type guard

def has_shape_names(shape, names) -> bool:
    return names is not None and len(names) == len(shape)

Prevention

When it happens

Trigger: Calling NamedShape((2, 3)) or NamedShape(some_array.shape) without passing names; passing an empty/None names tuple together with a rank>=1 shape.

Common situations: Wrapping raw jnp array shapes for sharding annotation; refactoring code that previously used plain tuples and now passes them to NamedShape without adding names.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/6d0f02207d571120. Report an issue: GitHub.