{"record":{"id":"6d0f02207d571120","repo":"xai-org/x-algorithm","slug":"unable-to-create-named-shape-with-unnamed-dimensio","errorCode":null,"errorMessage":"Unable to create named shape with unnamed dimensions (shape: {shape})","messagePattern":"Unable to create named shape with unnamed dimensions \\(shape: (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/models/sharding_context.py","lineNumber":33,"sourceCode":"rank_logger = logging.getLogger(\"rank\")\n\n\nPyTree = Any\n\n\ndef axis_group_size(axis_names: PyTree, mesh: Mesh) -> int:\n    flattened_axis_names, _ = jax.tree.flatten(axis_names)\n    if not flattened_axis_names:\n        return 0\n    return math.prod([mesh.shape[n] for n in flattened_axis_names])\n\n\nclass NamedShape:\n    names: tuple[str, ...] | None\n\n    def __init__(self, shape: Shape | None = None, names: tuple[str, ...] | None = None):\n        if names is None and len(shape) > 0:\n            raise ValueError(\n                f\"Unable to create named shape with unnamed dimensions (shape: {shape})\"\n            )\n        if names is not None and len(names) != len(shape):\n            raise ValueError(\n                f\"Number of names must match number of dimensions (shape: {shape}, names: {names})\"\n            )\n        self.shape = shape\n        self.names = names\n\n    def __repr__(self) -> str:\n        shape_str = \", \".join(\n            f\"{name or 'unnamed'}={size}\" for name, size in zip(self.names, self.shape)\n        )\n        return f\"NamedShape({shape_str})\"\n\n\nclass ShardingContext:\n    def __init__(","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/models/sharding_context.py#L15-L51","documentation":"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.","triggerScenarios":"Calling NamedShape((2, 3)) or NamedShape(some_array.shape) without passing names; passing an empty/None names tuple together with a rank>=1 shape.","commonSituations":"Wrapping raw jnp array shapes for sharding annotation; refactoring code that previously used plain tuples and now passes them to NamedShape without adding names.","solutions":["Pass a names tuple with one entry per dimension: NamedShape(shape, (\"batch\", \"features\"))","If the shape is genuinely scalar/empty, pass an empty shape so len(shape)==0 skips the check"],"exampleFix":"# before\nns = NamedShape(x.shape)\n# after\nns = NamedShape(x.shape, (\"batch\", \"model\", \"features\"))","handlingStrategy":"validation","validationCode":"assert names is not None or not shape, \"NamedShape needs names for non-empty shapes\"","typeGuard":"def has_shape_names(shape, names) -> bool:\n    return names is not None and len(names) == len(shape)","tryCatchPattern":null,"preventionTips":["Always construct NamedShape with explicit names tuple","Write a helper named_shape(x, names) that asserts arity"],"tags":["sharding","jax","validation","shape"],"backgroundTag":"shape-validation-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}