{"record":{"id":"415f7bd66383ed94","repo":"huggingface/transformers","slug":"out-indices-must-not-contain-any-duplicates-got","errorCode":null,"errorMessage":"out_indices must not contain any duplicates, got {self._out_indices}(equivalent to {positive_indices}))","messagePattern":"out_indices must not contain any duplicates, got (.+?)\\(equivalent to (.+?)\\)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/backbone_utils.py","lineNumber":109,"sourceCode":"                sorted_feats := [feat for feat in self.stage_names if feat in self._out_features]\n            ):\n                raise ValueError(\n                    f\"out_features must be in the same order as stage_names, expected {sorted_feats} got {self._out_features}\"\n                )\n\n        if self._out_indices is not None:\n            if not isinstance(self._out_indices, list):\n                raise ValueError(f\"out_indices must be a list, got {type(self._out_indices)}\")\n            # Convert negative indices to their positive equivalent: [-1,] -> [len(stage_names) - 1,]\n            positive_indices = tuple(idx % len(self.stage_names) if idx < 0 else idx for idx in self._out_indices)\n            if any(idx for idx in positive_indices if idx not in range(len(self.stage_names))):\n                raise ValueError(\n                    f\"out_indices must be valid indices for stage_names {self.stage_names}, got {self._out_indices}\"\n                )\n            if len(positive_indices) != len(set(positive_indices)):\n                msg = f\"out_indices must not contain any duplicates, got {self._out_indices}\"\n                msg += f\"(equivalent to {positive_indices}))\" if positive_indices != self._out_indices else \"\"\n                raise ValueError(msg)\n            if positive_indices != tuple(sorted(positive_indices)):\n                sorted_negative = [\n                    idx for _, idx in sorted(zip(positive_indices, self._out_indices), key=lambda x: x[0])\n                ]\n                raise ValueError(\n                    f\"out_indices must be in the same order as stage_names, expected {sorted_negative} got {self._out_indices}\"\n                )\n\n        if self._out_features is not None and self._out_indices is not None:\n            if len(self._out_features) != len(self._out_indices):\n                raise ValueError(\"out_features and out_indices should have the same length if both are set\")\n            if self._out_features != [self.stage_names[idx] for idx in self._out_indices]:\n                raise ValueError(\"out_features and out_indices should correspond to the same stages if both are set\")\n\n    @property\n    def out_features(self):\n        return self._out_features\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/backbone_utils.py#L91-L127","documentation":"Raised when out_indices contains duplicates after negative indices are normalized to positive ones (e.g. [0, -5] both resolve to stage 0 when there are 5 stages). Duplicated stages would produce colliding feature names and ambiguous multi-feature outputs, so the config rejects them. The message appends the normalized positive indices when they differ from the input.","triggerScenarios":"out_indices like [1, 1] or [1, -4] where both normalize to the same stage (with len(stage_names)==4: 1 and -4 % 4 == 0? — concretely [0, -4] with 4 stages: -4 % 4 == 0, duplicate with 0). Fires on config verification at model init.","commonSituations":"Mixing positive and negative indices that point at the same stage; editing a config by appending a stage index that already exists; checkpoint configs saved before dedup validation existed.","solutions":["Remove the duplicate stage index from out_indices","If you mixed negative and positive forms, rewrite all indices as positive (or all negative) to make collisions obvious","Print the normalized indices: [i % len(stage_names) if i < 0 else i for i in out_indices] to spot the collision"],"exampleFix":"# before (4 stages)\nconfig.out_indices = [0, -4]  # -4 % 4 == 0 -> duplicate of 0\n\n# after\nconfig.out_indices = [0, 1]","handlingStrategy":"validation","validationCode":"n = len(config.stage_names)\nnormalized = [i % n if i < 0 else i for i in out_indices]\nassert len(normalized) == len(set(normalized)), \"duplicate stages in out_indices\"","typeGuard":"def no_duplicate_stages(out_indices: list[int], stage_names: list[str]) -> bool:\n    n = len(stage_names)\n    norm = [i % n if i < 0 else i for i in out_indices]\n    return len(norm) == len(set(norm))","tryCatchPattern":null,"preventionTips":["Use one sign convention (all positive or all negative) in out_indices","Normalize negative indices to positive before editing a config","Treat out_indices as a strictly increasing sequence by construction"],"tags":["config","backbone","validation","duplicates"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}