{"record":{"id":"3c116ec150328891","repo":"huggingface/transformers","slug":"invalid-cache-implementation-choose-one-of","errorCode":null,"errorMessage":"Invalid `cache_implementation` ({}). Choose one of: {}","messagePattern":"Invalid `cache_implementation` \\((.+?)\\)\\. Choose one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/configuration_utils.py","lineNumber":687,"sourceCode":"        if self.max_new_tokens is not None and self.max_new_tokens <= 0:\n            raise ValueError(f\"`max_new_tokens` must be greater than 0, but is {self.max_new_tokens}.\")\n        if self.assistant_ensemble_weight is not None and not (0.0 < self.assistant_ensemble_weight < 1.0):\n            raise ValueError(\n                f\"`assistant_ensemble_weight` must be in the open interval `(0.0, 1.0)`, \"\n                f\"but is {self.assistant_ensemble_weight}. Use `None` for standard (lossless) speculative decoding.\"\n            )\n        if self.pad_token_id is not None and self.pad_token_id < 0:\n            minor_issues[\"pad_token_id\"] = (\n                f\"`pad_token_id` should be positive but got {self.pad_token_id}. This will cause errors when batch \"\n                \"generating, if there is padding. Please set `pad_token_id` explicitly as \"\n                \"`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","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/configuration_utils.py#L669-L705","documentation":"validate() checks cache_implementation against the known cache backends (ALL_CACHE_IMPLEMENTATIONS plus 'paged', e.g. 'static', 'sliding_window', 'mamba', 'paged'). Any other string is rejected because generate() would later fail to construct the cache.","triggerScenarios":"GenerationConfig(cache_implementation='flash') (typo), 'dynamic' on a version where it was renamed/removed, or a custom cache name not registered in the implementation list.","commonSituations":"Typos; version drift where cache names changed between transformers releases; copying cache_implementation from tutorials targeting a different version.","solutions":["Use one of the names printed in the error message (valid_cache_implementations list)","Check your transformers version's ALL_CACHE_IMPLEMENTATIONS for supported names","For typo-prone external configs, validate against the list before constructing GenerationConfig"],"exampleFix":"# before\ncfg = GenerationConfig(cache_implementation=\"dynamic\")\n# after (recent versions)\ncfg = GenerationConfig(cache_implementation=None)  # default dynamic cache, or \"static\" for static cache","handlingStrategy":"validation","validationCode":"from transformers.generation.configuration_utils import ALL_CACHE_IMPLEMENTATIONS\n\ndef valid_cache_implementation(name) -> bool:\n    return name is None or name in set(ALL_CACHE_IMPLEMENTATIONS) | {\"paged\"}","typeGuard":"def is_valid_cache_name(name: str) -> bool:\n    from transformers.generation.configuration_utils import ALL_CACHE_IMPLEMENTATIONS\n    return name in set(ALL_CACHE_IMPLEMENTATIONS) | {\"paged\"}","tryCatchPattern":null,"preventionTips":["Copy cache implementation names from the error message or the version's constants, not from memory","Re-validate cached configs after upgrading transformers"],"tags":["python","transformers","generation","kv-cache","generation-config","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}