{"record":{"id":"c6869fc055f8870e","repo":"huggingface/transformers","slug":"model-must-have-caching-enabled","errorCode":null,"errorMessage":"Model must have caching enabled.","messagePattern":"Model must have caching enabled\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/executorch.py","lineNumber":703,"sourceCode":"            device (`Optional[torch.device]`): The device to use. If not provided, we check if a value can be found\n                in `generation_config.cache_config` and otherwise we use `model.device` (no error is raised).\n        Raises:\n            AssertionError: If the model doesn't have the expected configuration for hybrid StaticCache.\n            ValueError: If `batch_size` or `max_cache_len` is not provided, either as an argument or in `cache_config`.\n        \"\"\"\n        super().__init__()\n        self.model = model\n        config = model.config.get_text_config()\n        generation_config = model.generation_config\n\n        # Sanity checks\n        if generation_config is None:\n            raise AssertionError(\n                \"The model must have a generation config to be exported with static caching. \"\n                \"Please set `generation_config` in `model`.\"\n            )\n        if not config.use_cache:\n            raise AssertionError(\"Model must have caching enabled.\")\n\n        cache_config = {} if generation_config.cache_config is None else generation_config.cache_config\n        # Ensure batch_size and max_cache_len are set\n        if batch_size is None:\n            batch_size = cache_config.get(\"batch_size\", None)\n            if batch_size is None:\n                raise ValueError(\"batch_size must be provided, either as an argument or in cache_config.\")\n        if max_cache_len is None:\n            max_cache_len = cache_config.get(\"max_cache_len\", None)\n            if max_cache_len is None:\n                raise ValueError(\"max_cache_len must be provided, either as an argument or in cache_config.\")\n        # Infer device if not provided\n        if device is None:\n            device = cache_config.get(\"device\", model.device)\n\n        # Initialize the cache\n        self.cache = StaticCache(config=config, max_cache_len=max_cache_len)\n        # Since StaticSlidingWindow have dynamic control flow that cannot be avoided, we have to replace them here by","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/executorch.py#L685-L721","documentation":"Error \"Model must have caching enabled.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in ExecuTorch integration when the model's caching is disabled.","commonSituations":"Running ExecuTorch export/inference on a model configured with use_cache=False.","solutions":["Enable caching on the model (`use_cache=True`) before export."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}