{"record":{"id":"41854f6fb3b68a24","repo":"huggingface/transformers","slug":"you-have-modified-the-pretrained-model-configurati","errorCode":null,"errorMessage":"You have modified the pretrained model configuration to control generation We detected the following values set - {self.config._get_generation_parameters()}. This strategy to control generation is not supported anymore. Please use and modify `model.generation_config` (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )","messagePattern":"You have modified the pretrained model configuration to control generation We detected the following values set - (.+?)\\. This strategy to control generation is not supported anymore\\. Please use and modify `model\\.generation_config` \\(see https://huggingface\\.co/docs/transformers/generation_strategies#default-text-generation-configuration \\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/utils.py","lineNumber":1788,"sourceCode":"\n    def _prepare_generation_config(\n        self: \"GenerativePreTrainedModel\",\n        generation_config: GenerationConfig | None,\n        **kwargs: Any,\n    ) -> tuple[GenerationConfig, dict]:\n        \"\"\"\n        Prepares the base generation config, then applies any generation configuration options from kwargs. This\n        function handles retrocompatibility with respect to configuration files.\n        \"\"\"\n        # parameterization priority:\n        # user-defined kwargs or `generation_config` > `self.generation_config` > global default values\n        # TODO (joao): per-model generation config classes.\n\n        generation_config_provided = generation_config is not None\n        if generation_config is None:\n            # Users may modify `model.config` to control generation. This is a legacy behavior and is not supported anymore\n            if len(self.config._get_generation_parameters()) > 0:\n                raise ValueError(\n                    \"You have modified the pretrained model configuration to control generation \"\n                    f\"We detected the following values set - {self.config._get_generation_parameters()}. \"\n                    \"This strategy to control generation is not supported anymore. Please use and modify `model.generation_config` \"\n                    \"(see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )\",\n                )\n            generation_config = GenerationConfig()\n\n        # `torch.export.export` usually raises an exception if it is called\n        # with ``strict=True``. deepcopy can only be processed if ``strict=False``.\n        generation_config = copy.deepcopy(generation_config)\n\n        # First set values from the loaded `self.generation_config`, then set default values (BC)\n        #\n        # Only update values that are `None`, i.e. these values were not explicitly set by users to `generate()`,\n        # or values that are not present in the current config, i.e. custom entries that were set via `**kwargs`.\n        # Thus we use the specific kwargs `defaults_only=True` (`None` values only) and `allow_custom_entries=True`\n        # (custom entries are carried over).\n        global_defaults = self.generation_config._get_default_generation_params()","sourceCodeStart":1770,"sourceCodeEnd":1806,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/utils.py#L1770-L1806","documentation":"Historically users set generation knobs (`max_length`, `do_sample`, ...) on `model.config`. That pathway was removed: generation is controlled only by `model.generation_config`. Before building a fresh default `GenerationConfig`, `generate` checks `config._get_generation_parameters()` and raises if any legacy generation attribute is set on the model config.","triggerScenarios":"`model.config.max_length = 100` (or `do_sample`, `num_beams`, `temperature`, etc. on `model.config`) then `model.generate(**inputs)` without an explicit `generation_config` argument.","commonSituations":"Old tutorials/StackOverflow answers that mutate `model.config`; codebases written for transformers < 4.x behavior; loading checkpoints from before the split that stored generation parameters inside `config.json`; silent breakage after upgrading transformers.","solutions":["Move the settings: `model.generation_config.max_length = 100` (and unset them from `model.config`).","Or pass a `GenerationConfig` directly: `model.generate(**inputs, generation_config=GenerationConfig(max_length=100))`.","Strip legacy attributes from a loaded config: iterate `model.config._get_generation_parameters()` and delete/pop those keys from `model.config`.","If a Hub checkpoint's `config.json` contains generation params, set them in its `generation_config.json` instead."],"exampleFix":"# before\nmodel.config.max_length = 100\nmodel.config.do_sample = True\nout = model.generate(**inputs)  # ValueError: legacy config-controlled generation\n\n# after\nmodel.generation_config.max_length = 100\nmodel.generation_config.do_sample = True\nout = model.generate(**inputs)","handlingStrategy":"validation","validationCode":"legacy = model.config._get_generation_parameters()\nif legacy:\n    for k in legacy:\n        setattr(model.generation_config, k, getattr(model.config, k))\n        setattr(model.config, k, None)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set generation attributes on model.config; use model.generation_config exclusively.","After upgrading transformers, run a smoke generate() on each model to surface legacy-config errors.","Migrate old checkpoints: move generation params from config.json into generation_config.json."],"tags":["generation","generation-config","legacy-migration","breaking-change"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}