{"record":{"id":"39558abfe2726266","repo":"xai-org/x-algorithm","slug":"number-of-names-must-match-number-of-dimensions-s","errorCode":null,"errorMessage":"Number of names must match number of dimensions (shape: {shape}, names: {names})","messagePattern":"Number of names must match number of dimensions \\(shape: (.+?), names: (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/models/sharding_context.py","lineNumber":37,"sourceCode":"\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__(\n        self,\n        name: str,\n        mesh: jax.sharding.Mesh,\n        sharding_rules: dict[str, ShardingRule] | None = None,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/models/sharding_context.py#L19-L55","documentation":"NamedShape validates that len(names) == len(shape). If you supply names for a different number of dimensions than the shape has, the constructor raises this ValueError, preventing later silent mis-assignment of dimension names to mesh axes.","triggerScenarios":"Calling NamedShape((8, 16, 1024), (\"batch\", \"features\")) — 3 dims, 2 names; or adding/removing a dimension in the shape while keeping a stale names tuple.","commonSituations":"Shapes changed by a refactor (e.g. adding head dimension) while the names list was not updated; hardcoded names copied from a different layer.","solutions":["Count the dimensions of the shape and make names exactly that length","Derive names programmatically where possible so they cannot drift from the shape"],"exampleFix":"# before\nNamedShape((8, 16, 1024), (\"batch\", \"features\"))\n# after\nNamedShape((8, 16, 1024), (\"batch\", \"model\", \"features\"))","handlingStrategy":"validation","validationCode":"assert len(names) == len(shape), f\"{len(names)} names for {len(shape)} dims\"","typeGuard":"def names_match_shape(shape, names) -> bool:\n    return names is not None and len(names) == len(shape)","tryCatchPattern":null,"preventionTips":["Derive names from a single source of truth shared with shape construction","Unit-test name/shape arity for each layer"],"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"}