{"record":{"id":"ea3cdcefb92bd5d4","repo":"huggingface/transformers","slug":"the-model-must-have-caching-enabled-to-be-performa","errorCode":null,"errorMessage":"The model must have caching enabled to be performant.","messagePattern":"The model must have caching enabled to be performant\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/executorch.py","lineNumber":214,"sourceCode":"        batch_size: int | None = None,\n        max_cache_len: int | None = None,\n        device: torch.device | None = None,\n    ) -> None:\n        \"\"\"\n        Initializes the exportable module.\n\n        Args:\n            model (`PreTrainedModel`): The pretrained model to wrap.\n\n        Raises:\n            ValueError: If the model is configured with a unsupported cache implementation.\n        \"\"\"\n        super().__init__()\n\n        config = model.config.get_text_config()\n\n        if not hasattr(config, \"use_cache\") or config.use_cache is False:\n            raise ValueError(\"The model must have caching enabled to be performant.\")\n\n        if hasattr(config, \"layer_types\") and getattr(config, \"sliding_window\", None) is not None:\n            self.model = TorchExportableModuleWithHybridCache(model, batch_size, max_cache_len, device)\n        else:\n            # If `layer_types` is not specified explicitly in the config or `sliding_window` is null,\n            # there is only 1 type of layers, so export will use `StaticCache` by default.\n            logging.info(\n                \"Using `StaticCache` for export as `layer_types` is not specified or `sliding_window` is `null` in the config.\"\n            )\n            self.model = TorchExportableModuleWithStaticCache(model, batch_size, max_cache_len, device)\n\n    def forward(\n        self,\n        input_ids: torch.Tensor | None = None,\n        inputs_embeds: torch.Tensor | None = None,\n        cache_position: torch.Tensor | None = None,\n    ) -> torch.Tensor:\n        \"\"\"","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/executorch.py#L196-L232","documentation":"Error \"The model must have caching enabled to be performant.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in ExecuTorch integration when the model runs with caching disabled.","commonSituations":"Exporting or running a model for ExecuTorch with use_cache=False, which the runtime requires for performance.","solutions":["Enable caching: set `generation_config.use_cache=True`."],"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"}