{"record":{"id":"56ebb130c8ccaf43","repo":"huggingface/transformers","slug":"the-output-attentions-attribute-is-not-supported","errorCode":null,"errorMessage":"The `output_attentions` attribute is not supported when using the `attn_implementation` set to {self._attn_implementation}. Please set it to 'eager' instead.","messagePattern":"The `output_attentions` attribute is not supported when using the `attn_implementation` set to (.+?)\\. Please set it to 'eager' instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":409,"sourceCode":"        # compute it based on the length of the `id2label` map\n        if self.id2label is None or self.num_labels != num_labels:\n            self.id2label = {i: f\"LABEL_{i}\" for i in range(num_labels)}\n            self.label2id = dict(zip(self.id2label.values(), self.id2label.keys()))\n\n    @property\n    def output_attentions(self):\n        \"\"\"\n        `bool`: Whether or not the model should returns all attentions.\n        \"\"\"\n        return self._output_attentions\n\n    @output_attentions.setter\n    def output_attentions(self, value: bool):\n        # If we set `output_attentions` explicitly before the attn implementation, dispatch eager\n        if value and self._attn_implementation is None:\n            self._attn_implementation = \"eager\"\n        if value and self._attn_implementation != \"eager\":\n            raise ValueError(\n                \"The `output_attentions` attribute is not supported when using the `attn_implementation` set to \"\n                f\"{self._attn_implementation}. Please set it to 'eager' instead.\"\n            )\n        self._output_attentions = value\n\n    @property\n    def _attn_implementation(self):\n        return self._attn_implementation_internal\n\n    @_attn_implementation.setter\n    def _attn_implementation(self, value: str | dict | None):\n        \"\"\"We set it recursively on the sub-configs as well\"\"\"\n        # Set if for current config\n        current_attn = getattr(self, \"_attn_implementation\", None)\n        attn_implementation = value if not isinstance(value, dict) else value.get(\"\", current_attn)\n        self._attn_implementation_internal = attn_implementation\n\n        # Set it recursively on the subconfigs","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L391-L427","documentation":"ValueError raised by the output_attentions setter. Attention weights are only returned by the eager attention implementation, so setting output_attentions=True while a non-eager implementation (sdpa, flash_attention_2, flex) is selected is rejected. Convenience: setting output_attentions=True before any implementation is chosen auto-dispatches eager.","triggerScenarios":"config.attn_implementation = 'sdpa' followed by config.output_attentions = True; or from_pretrained(..., attn_implementation='flash_attention_2', output_attentions=True). The setter order matters: attentions first (with _attn_implementation None) silently selects eager.","commonSituations":"Attention-map visualization or interpretability tooling on models loaded with SDPA/FA2 for speed; config dicts from_pretrained that set both keys; fine-tuning scripts enabling attentions globally.","solutions":["Set attn_implementation='eager' (before or after enabling output_attentions) when you need attention weights","Or set output_attentions first while _attn_implementation is None so eager is auto-selected","Only enable attentions for the inspection run; keep sdpa/FA2 for training and inference"],"exampleFix":"# before\ncfg.attn_implementation = 'sdpa'\ncfg.output_attentions = True  # ValueError\n# after\ncfg.attn_implementation = 'eager'\ncfg.output_attentions = True","handlingStrategy":"validation","validationCode":"if output_attentions:\n    assert cfg._attn_implementation in (None, 'eager'), 'output_attentions requires eager attention'\n    cfg.attn_implementation = 'eager'\ncfg.output_attentions = output_attentions","typeGuard":"def attentions_supported(cfg) -> bool:\n    return cfg._attn_implementation in (None, 'eager')","tryCatchPattern":"try:\n    cfg.output_attentions = True\nexcept ValueError as e:\n    if 'not supported' in str(e):\n        cfg.attn_implementation = 'eager'\n        cfg.output_attentions = True\n    else:\n        raise","preventionTips":["Decide up front: eager for inspection runs, sdpa/FA2 for throughput — never both flags","Set output_attentions before any attn_implementation to get eager auto-dispatch"],"tags":["config","attention","attn-implementation","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}