{"record":{"id":"17d3770d8c134530","repo":"huggingface/transformers","slug":"out-features-must-not-contain-any-duplicates-got","errorCode":null,"errorMessage":"out_features must not contain any duplicates, got {self._out_features}","messagePattern":"out_features must not contain any duplicates, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/backbone_utils.py","lineNumber":89,"sourceCode":"        self._out_features, self._out_indices = out_features, out_indices\n        self.verify_out_features_out_indices()\n\n    def verify_out_features_out_indices(self):\n        \"\"\"\n        Verify that out_indices and out_features are valid for the given stage_names.\n        \"\"\"\n        if self.stage_names is None:\n            raise ValueError(\"Stage_names must be set for transformers backbones\")\n\n        if self._out_features is not None:\n            if not isinstance(self._out_features, (list,)):\n                raise ValueError(f\"out_features must be a list got {type(self._out_features)}\")\n            if any(feat not in self.stage_names for feat in self._out_features):\n                raise ValueError(\n                    f\"out_features must be a subset of stage_names: {self.stage_names} got {self._out_features}\"\n                )\n            if len(self._out_features) != len(set(self._out_features)):\n                raise ValueError(f\"out_features must not contain any duplicates, got {self._out_features}\")\n            if self._out_features != (\n                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}\"","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/backbone_utils.py#L71-L107","documentation":"Raised by BackboneConfigMixin.verify_out_features_out_indices when len(self._out_features) != len(set(self._out_features)), i.e. the same stage name appears more than once. Duplicate entries would create duplicate output hooks/channels in the feature-map output, which is meaningless for a backbone, so it is rejected. (Duplicates in out_indices are similarly rejected by the mirrored check.)","triggerScenarios":"Passing out_features=[\"stage2\", \"stage2\"] or out_indices=[1, 1, 2]; config-building code that concatenates user-requested features without deduplicating (e.g. default_features + extra_features).","commonSituations":"Programmatic config assembly merging feature lists; YAML anchors or JSON defaults that repeat a stage; copy-paste edits duplicating a line.","solutions":["Deduplicate while preserving order: out_features = list(dict.fromkeys(out_features))","Fix the merge logic that produced duplicates instead of concatenating blindly","Inspect the error message: it prints the exact list including the duplicated names"],"exampleFix":"// before\nout_features = defaults + extras  # ['stage1', 'stage2', 'stage2']\ncfg = BackboneConfig(out_features=out_features)\n// after\nout_features = list(dict.fromkeys(defaults + extras))  # ['stage1', 'stage2']\ncfg = BackboneConfig(out_features=out_features)","handlingStrategy":"validation","validationCode":"out_features = list(dict.fromkeys(out_features))  # dedupe, keep order\ncfg = SomeBackboneConfig(out_features=out_features)","typeGuard":"def has_no_duplicates(out_features) -> bool:\n    return out_features is None or len(out_features) == len(set(out_features))","tryCatchPattern":"try:\n    cfg = SomeBackboneConfig(out_features=out_features)\nexcept ValueError as e:\n    if \"must not contain any duplicates\" in str(e):\n        cfg = SomeBackboneConfig(out_features=list(dict.fromkeys(out_features)))\n    else:\n        raise","preventionTips":["Deduplicate merged feature lists with dict.fromkeys (order-preserving)","Don't concatenate default + user feature lists blindly","Read the error message — it shows the exact duplicated entries"],"tags":["backbone","configuration","validation","duplicates"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}