{"record":{"id":"ee5b3bfadd6bfe9f","repo":"pytorch/pytorch","slug":"at-least-dims-indexed-indices-were-supplied-but","errorCode":null,"errorMessage":"at least {dims_indexed} indices were supplied but the tensor only has {total_dims} dimensions","messagePattern":"at least (.+?) indices were supplied but the tensor only has (.+?) dimensions","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"functorch/dim/_getsetitem.py","lineNumber":321,"sourceCode":"                dims_indexed += len(s._dims)\n            dimlists.append(i)\n        elif s is None:\n            has_dimpacks_or_none = True\n        elif is_dimpack(s):\n            can_call_original_getitem = False\n            has_dimpacks_or_none = True\n            dims_indexed += 1\n        else:\n            dims_indexed += 1\n\n    # Early return if we can use original getitem\n    if can_call_original_getitem:\n        return IndexingInfo(can_call_original=True)\n\n    self_info = TensorInfo.create(self, False, True)\n    total_dims = len(self_info.levels)  # Total dimensions (positional + named)\n    if dims_indexed > total_dims:\n        raise ValueError(\n            f\"at least {dims_indexed} indices were supplied but the tensor only has {total_dims} dimensions\"\n        )\n\n    # Expand any unbound dimension list, or expand ... into individual : slices.\n    expanding_dims = total_dims - dims_indexed\n    if expanding_object != -1:\n        if unbound_dim_list is not None:\n            # Bind unbound dimension list to the expanding dimensions\n            unbound_dim_list.bind_len(expanding_dims)\n        else:\n            # Expand ... into slice(None) objects\n            no_slices = [slice(None)] * expanding_dims\n            input_list = (\n                input_list[:expanding_object]\n                + no_slices\n                + input_list[expanding_object + 1 :]\n            )\n","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/pytorch/pytorch/blob/dcd2ecae775af66439b7ede4e7a82540b058c59c/functorch/dim/_getsetitem.py#L303-L339","documentation":"The indexing pre-pass counts how many axes the index list consumes (each int, slice, Dim, pack, or ... counts at least one). If that minimum count exceeds the tensor's total levels (positional + named), indexing cannot proceed and ValueError reports both numbers. It fires only when the original torch getitem cannot be used, i.e. named dims are involved.","triggerScenarios":"t[d1, d2, d3] on a 2-d tensor; supplying an index list longer than the rank, e.g. t[:, :, :, d] on a 3-level tensor with named dims present (which disables the fast path).","commonSituations":"Code written for a higher-rank input reused on a squeezed/reduced tensor; hardcoded index arity after a preprocessing step dropped a channel dim.","solutions":["Match the number of indices to the tensor's levels (check len(t.order()) or t.ndim) and drop surplus indices.","Fix upstream so rank is preserved (keepdim=True, no unconditional squeeze).","Build indices from the tensor's actual dims rather than a fixed-length literal."],"exampleFix":"out = x[a_d, b_d, c_d]  # x has only 2 levels after a squeeze\n\n# after\nx = raw.sum(-1, keepdim=True)  # or remove the squeeze\nout = x[a_d, b_d, c_d]","handlingStrategy":"validation","validationCode":"total = len(t._levels)\nn_idx = sum(1 for x in index if x is not Ellipsis) + (1 if any(x is Ellipsis for x in index) else 0)\nif n_idx > total:\n    raise ValueError(f'{n_idx} indices for {total}-level tensor')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive index arity from the tensor (t.ndim / len(t._levels)), not literals.","Avoid unconditional squeeze before named-dim indexing.","Add rank asserts after shape-changing preprocessing."],"tags":["torchdim","getitem","indexing","rank-mismatch"],"backgroundTag":null,"analyzedSha":"dcd2ecae775af66439b7ede4e7a82540b058c59c","analyzedAt":"2026-08-14T19:21:26.615Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}