{"record":{"id":"4b05826fd8a12fb9","repo":"huggingface/transformers","slug":"self-class-name-only-supports-supported","errorCode":null,"errorMessage":"{self.__class__.__name__} only supports {supported_modes}, but got generation mode '{generation_mode}'.","messagePattern":"(.+?) only supports (.+?), but got generation mode '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/utils.py","lineNumber":1562,"sourceCode":"\n        # 7. Define which indices contributed to scores\n        cut_idx = sequences.shape[-1] - max_beam_length\n        indices = sequences[:, cut_idx:] + beam_sequence_indices\n\n        # 8. Compute scores\n        transition_scores = stacked_scores.gather(0, indices)\n\n        # 9. Mask out transition_scores of beams that stopped early\n        transition_scores[beam_indices_mask] = 0\n\n        return transition_scores\n\n    def _validate_generation_mode(\n        self: \"GenerativePreTrainedModel\", generation_mode, generation_config, generation_mode_kwargs\n    ):\n        supported_modes = getattr(self, \"_supported_generation_modes\", None)\n        if supported_modes is not None and generation_mode not in supported_modes:\n            raise ValueError(\n                f\"{self.__class__.__name__} only supports {supported_modes}, but got \"\n                f\"generation mode '{generation_mode}'.\"\n            )\n\n        if generation_mode == GenerationMode.BEAM_SEARCH and \"streamer\" in generation_mode_kwargs:\n            raise ValueError(\n                \"`streamer` cannot be used with beam search (yet!). Make sure that `num_beams` is set to 1.\"\n            )\n\n        if generation_mode == GenerationMode.ASSISTED_GENERATION:\n            if generation_config.num_return_sequences > 1:\n                raise ValueError(\n                    \"num_return_sequences has to be 1 when doing assisted generate, \"\n                    f\"but is {generation_config.num_return_sequences}.\"\n                )\n            if self._is_stateful:\n                # In assisted generation we need the ability to confirm whether the model would pick certain tokens,\n                # which is not possible with stateful models (they can't reset to a previous subset of generated text)","sourceCodeStart":1544,"sourceCodeEnd":1580,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/utils.py#L1544-L1580","documentation":"Some model classes declare `_supported_generation_modes`, a whitelist of the decoding strategies their implementation can handle (e.g. only GREEDY_SEARCH and SAMPLE). Before decoding, `generate` validates the resolved generation mode against this list and raises when the parameterization you chose resolves to an unsupported mode.","triggerScenarios":"Calling `generate` on a model that defines `_supported_generation_modes` with parameters that resolve to an excluded mode, e.g. `num_beams>1` (beam search), `assistant_model=...` (assisted generation), or contrastive-search settings, when the class only supports greedy/sample.","commonSituations":"Reusing a beam-search or speculative-decoding recipe from a mainstream LLM on a constrained architecture (some multimodal, stateful, or specialist models); upgrading transformers where the whitelist was added and previously-ignored modes now fail fast; batch pipelines assuming every model supports beam search.","solutions":["Read the error message: it lists the exact supported modes; switch parameters to one of them (e.g. keep `num_beams=1`, use `do_sample=True/False`).","Check the class attribute `type(model)._supported_generation_modes` (or inspect the model's docs) to see what is allowed.","If you need the unsupported mode, use a different model class that supports it (e.g. a standard causal LM).","If you maintain a custom model, extend `_supported_generation_modes` only after implementing/verifying that mode's requirements (cache handling, beam reordering, etc.)."],"exampleFix":"# before\nout = model.generate(**inputs, num_beams=4)  # ValueError: only supports (GREEDY_SEARCH, SAMPLE)\n\n# after\nout = model.generate(**inputs, do_sample=True, temperature=0.7, num_beams=1)","handlingStrategy":"validation","validationCode":"supported = getattr(type(model), \"_supported_generation_modes\", None)\nif supported is not None:\n    # validate after resolving mode, e.g. beam params only if BEAM_SEARCH in supported\n    if kwargs.get(\"num_beams\", 1) > 1 and not any(\"BEAM\" in m.name for m in supported):\n        kwargs[\"num_beams\"] = 1","typeGuard":null,"tryCatchPattern":"try:\n    out = model.generate(**inputs, **kwargs)\nexcept ValueError as e:\n    if \"only supports\" in str(e):\n        kwargs[\"num_beams\"] = 1\n        out = model.generate(**inputs, **kwargs)\n    else:\n        raise","preventionTips":["Query `getattr(type(model), '_supported_generation_modes', None)` before applying decoding recipes.","Keep per-model parameter presets instead of one shared generate config for heterogeneous model zoos.","Test each model class in your roster with the exact generation settings you ship."],"tags":["generation","generation-mode","beam-search","model-capabilities"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}