{"record":{"id":"f9be0ee20c430cbc","repo":"huggingface/transformers","slug":"you-provided-compile-config-as-an-instance-of","errorCode":null,"errorMessage":"You provided `compile_config` as an instance of {}, but it must be an instance of `CompileConfig`.","messagePattern":"You provided `compile_config` as an instance of (.+?), but it must be an instance of `CompileConfig`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/configuration_utils.py","lineNumber":698,"sourceCode":"                \"`model.generation_config.pad_token_id=PAD_TOKEN_ID` to avoid errors in generation\"\n            )\n        # 1.2. Cache attributes\n        # \"paged\" re-routes to continuous batching and so it is a valid cache implementation. But we do not want to test\n        # it with the `generate` as the other would be, so we we cannot add it to ALL_CACHE_IMPLEMENTATIONS\n        valid_cache_implementations = ALL_CACHE_IMPLEMENTATIONS + (\"paged\",)\n        if self.cache_implementation is not None and self.cache_implementation not in valid_cache_implementations:\n            raise ValueError(\n                f\"Invalid `cache_implementation` ({self.cache_implementation}). Choose one of: \"\n                f\"{valid_cache_implementations}\"\n            )\n        if self.max_cache_len is not None and self.cache_implementation not in ALL_STATIC_CACHE_IMPLEMENTATIONS:\n            logger.warning_once(\n                f\"`max_cache_len` is only used with static caches ({STATIC_CACHE_IMPLEMENTATIONS}); it will be \"\n                f\"ignored with `cache_implementation={self.cache_implementation!r}`.\"\n            )\n        # 1.3. Performance attributes\n        if self.compile_config is not None and not isinstance(self.compile_config, CompileConfig):\n            raise ValueError(\n                f\"You provided `compile_config` as an instance of {type(self.compile_config)}, but it must be an \"\n                \"instance of `CompileConfig`.\"\n            )\n        # 1.4. Watermarking attributes\n        if self.watermarking_config is not None:\n            self.watermarking_config.validate()\n\n        # 2. Validation of attribute combinations\n        # 2.1. detect sampling-only parameterization when not in sampling mode\n\n        # Note that we check `is not True` in purpose. Boolean fields can also be `None` so we\n        # have to be explicit. Value of `None` is same as having `False`, i.e. the default value\n\n        if self.do_sample is not True:\n            greedy_wrong_parameter_msg = (\n                \"`do_sample` is not set to `True`. However, `{flag_name}` is set to `{flag_value}` -- this flag is \"\n                \"only used in sample-based generation modes. You should set `do_sample=True` or unset `{flag_name}`.\"\n            )","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/configuration_utils.py#L680-L716","documentation":"compile_config must be an instance of CompileConfig (the structured config for torch.compile of generation); passing a plain dict, string, or other object means generate() could not read its fields, so validate() rejects it.","triggerScenarios":"GenerationConfig(compile_config={'mode': 'reduce-overhead'}) or cache_implementation='compiled' with compile_config=True; or deserializing a generation_config.json whose compile_config arrives as a dict.","commonSituations":"Users writing compile options as dicts (natural from JSON), older configs with compile_config=True to toggle compilation, or merging configs from external tools.","solutions":["Wrap the options: GenerationConfig(compile_config=CompileConfig(mode='reduce-overhead'))","For a dict from JSON, convert: CompileConfig(**d)","Set compile_config=None if you do not want compiled generation"],"exampleFix":"# before\ncfg = GenerationConfig(compile_config={\"mode\": \"reduce-overhead\", \"fullgraph\": True})\n# after\nfrom transformers import CompileConfig\ncfg = GenerationConfig(compile_config=CompileConfig(mode=\"reduce-overhead\", fullgraph=True))","handlingStrategy":"type-guard","validationCode":"from transformers import CompileConfig\n\ndef coerce_compile_config(v):\n    if v is None or isinstance(v, CompileConfig):\n        return v\n    if isinstance(v, dict):\n        return CompileConfig(**v)\n    raise TypeError(f\"compile_config must be CompileConfig or dict, got {type(v)!r}\")","typeGuard":"from transformers import CompileConfig\n\ndef is_compile_config(v) -> bool:\n    return v is None or isinstance(v, CompileConfig)","tryCatchPattern":null,"preventionTips":["Construct CompileConfig explicitly instead of passing dicts","After loading generation_config.json, convert dict compile_config via CompileConfig(**d)"],"tags":["python","transformers","generation","torch-compile","generation-config","type-error"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}